Ignore:
Timestamp:
Aug 21, 2009, 2:02:46 PM (15 years ago)
Author:
steve
Message:

Commit a working copy of numpy version of build_commun

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga_parallel/build_commun.py

    r3926 r7400  
    1313#  Author: Linda Stals, June 2005
    1414#  Modified: Linda Stals, Nov 2005 (optimise python code)
    15 #
    16 #
    17 #########################################################
    18 
    19 from Numeric import array, Int, Float, zeros
     15#            Steve Roberts, Aug 2009 (update to numpy)
     16#
     17#
     18#########################################################
     19
     20#from Numeric import array, Int, Float, zeros
     21
     22import numpy as num
     23
    2024import logging, logging.config
    2125logger = logging.getLogger('parallel')
     
    3034
    3135import pypar
     36
    3237
    3338from build_local import build_local_mesh
     
    6570             tagmap[bkey] = counter
    6671             counter = counter+1
     72
    6773    pypar.send(tagmap, p)
    6874
    6975    # send the quantities key information
    70    
     76
    7177    pypar.send(submesh["full_quan"].keys(), p)
    7278   
    7379    # send the number of triangles per processor
    7480
    75     pypar.send(triangles_per_proc, p, use_buffer=True)
     81    pypar.send(triangles_per_proc, p)
    7682
    7783    # compress full_commun
     
    8288        for i in range(len(submesh["full_commun"][p][c])):
    8389            flat_full_commun.append([c,submesh["full_commun"][p][c][i]])
     90
     91    print 'flat_full_commun', flat_full_commun
    8492
    8593    # send the array sizes so memory can be allocated
     
    95103    setup_array[7] = len(flat_full_commun)
    96104
    97     pypar.send(setup_array, p)
     105    pypar.send(num.array(setup_array, num.int), p)
    98106   
    99107    # send the nodes
    100    
    101     pypar.send(submesh["full_nodes"][p], p, use_buffer=True)
    102     pypar.send(submesh["ghost_nodes"][p], p, use_buffer=True)
     108
     109    pypar.send(num.array(submesh["full_nodes"][p], num.float), p)
     110    pypar.send(num.array(submesh["ghost_nodes"][p], num.float),p)
    103111
    104112    # send the triangles
    105113
    106     pypar.send(array(submesh["full_triangles"][p], Int), p, use_buffer=True)
    107     pypar.send(submesh["ghost_triangles"][p], p, use_buffer=True)
     114    pypar.send(num.array(submesh["full_triangles"][p],  num.int), p)
     115    pypar.send(num.array(submesh["ghost_triangles"][p], num.int), p)
    108116
    109117    # send the boundary
     
    112120    for b in submesh["full_boundary"][p]:
    113121        bc.append([b[0], b[1], tagmap[submesh["full_boundary"][p][b]]])
    114     pypar.send(bc, p, use_buffer=True)
     122
     123
     124    pypar.send(num.array(bc, num.int), p)
     125
    115126    bc = []
    116127    for b in submesh["ghost_boundary"][p]:
    117128        bc.append([b[0], b[1], tagmap[submesh["ghost_boundary"][p][b]]])
    118     pypar.send(bc, p, use_buffer=True)
     129
     130    pypar.send(num.array(bc, num.int), p)
    119131
    120132    # send the communication pattern
    121133
    122     pypar.send(submesh["ghost_commun"][p], p, use_buffer=True)
    123     pypar.send(flat_full_commun, p, use_buffer=True)
     134    pypar.send(submesh["ghost_commun"][p], p)
     135
     136    pypar.send(num.array(flat_full_commun, num.int), p)
    124137
    125138    # send the quantities
    126139   
    127140    for k in submesh["full_quan"]:
    128         pypar.send(submesh["full_quan"][k][p], p, use_buffer=True)
     141        pypar.send(num.array(submesh["full_quan"][k][p], num.float), p)
    129142       
    130143    for k in submesh["ghost_quan"]:
    131         pypar.send(submesh["ghost_quan"][k][p], p, use_buffer=True)
     144        pypar.send(num.array(submesh["ghost_quan"][k][p], num.float),p)
    132145       
    133146
     
    150163
    151164def rec_submesh_flat(p):
    152 
     165   
    153166    numproc = pypar.size()
    154167    myid = pypar.rank()
     
    161174   
    162175    tagmap = pypar.receive(p)
     176
    163177    itagmap = {}
    164178    for t in tagmap:
     
    166180
    167181    # receive the quantities key information
    168    
     182
    169183    qkeys = pypar.receive(p)
    170184
    171185    # receive the number of triangles per processor
    172186
    173     triangles_per_proc = []
    174     for i in range(numproc):
    175         triangles_per_proc.append([0])
    176 
    177     triangles_per_proc = pypar.receive(p, triangles_per_proc)
     187    triangles_per_proc = pypar.receive(p)
    178188
    179189    # recieve information about the array sizes
    180190
    181     setup_array = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    182     setup_array = pypar.receive(p, setup_array)
    183 
     191    setup_array = pypar.receive(p)
     192
     193    no_full_nodes = setup_array[0]
     194    no_ghost_nodes = setup_array[1]
     195    no_full_triangles = setup_array[2]
     196    no_ghost_triangles = setup_array[3]
     197    no_full_boundary = setup_array[4]
     198    no_ghost_boundary = setup_array[5]
     199    no_ghost_commun = setup_array[6]
     200    no_full_commun = setup_array[7]
     201    no_quantities = len(qkeys)
     202   
    184203    # receive the full nodes
    185204
    186     no_full_nodes = setup_array[0]
    187     full_nodes = zeros((no_full_nodes, 3), Float)
    188     submesh_cell["full_nodes"] = pypar.receive(p, full_nodes)
    189    
     205    submesh_cell["full_nodes"] = pypar.receive(p)
     206
    190207    # receive the ghost nodes
    191208
    192     no_ghost_nodes = setup_array[1]
    193     ghost_nodes = zeros((no_ghost_nodes, 3), Float)
    194     submesh_cell["ghost_nodes"] = pypar.receive(p, ghost_nodes)
    195 
     209    submesh_cell["ghost_nodes"] = pypar.receive(p)
    196210   
    197211    # receive the full triangles
    198212
    199     no_full_triangles = setup_array[2]
    200     full_triangles = zeros((no_full_triangles, 3), Int)
    201     submesh_cell["full_triangles"] = pypar.receive(p, full_triangles)
     213    submesh_cell["full_triangles"] = pypar.receive(p)
    202214   
    203215    # receive the ghost triangles
    204216
    205     no_ghost_triangles = setup_array[3]
    206     ghost_triangles = zeros((no_ghost_triangles, 4), Int)
    207     submesh_cell["ghost_triangles"] = pypar.receive(p, ghost_triangles)
    208    
     217    submesh_cell["ghost_triangles"] = pypar.receive(p)
     218
    209219    # receive the full boundary
    210220
    211     no_full_boundary = setup_array[4]
    212     bc = []
    213     for i in range(no_full_boundary):
    214         bc.append([0.0, 0.0, 0.0])
    215     bnd_c = pypar.receive(p, bc)
     221    bnd_c = pypar.receive(p)
    216222
    217223    submesh_cell["full_boundary"] = {}
     
    221227    # receive the ghost boundary
    222228
    223     no_ghost_boundary = setup_array[5]
    224     bc = []
    225     for i in range(no_ghost_boundary):
    226         bc.append([0.0, 0.0, 0.0])
    227     bnd_c = pypar.receive(p, bc)
     229    bnd_c = pypar.receive(p)
    228230
    229231    submesh_cell["ghost_boundary"] = {}
     
    233235    # receive the ghost communication pattern
    234236
    235     no_ghost_commun = setup_array[6]
    236     ghost_commun = zeros((no_ghost_commun, 2), Int)
    237     submesh_cell["ghost_commun"] = pypar.receive(p, ghost_commun)
     237    submesh_cell["ghost_commun"] = pypar.receive(p)
    238238   
    239239    # receive the full communication pattern
    240240
    241     no_full_commun = setup_array[7]
    242     full_commun = []
    243     for i in range(no_full_commun):
    244         full_commun.append([0.0, 0.0])
    245 
    246     full_commun = pypar.receive(p, full_commun)
     241    full_commun = pypar.receive(p)
    247242
    248243    submesh_cell["full_commun"] = {}
     
    254249    # receive the quantities
    255250
    256     no_quantities = len(qkeys)
    257     new_quan = zeros((no_full_triangles, 3), Float)
    258251    submesh_cell["full_quan"]={}
    259252   
    260253    for i in range(no_quantities):
    261         tmp = pypar.receive(p, new_quan)
    262         submesh_cell["full_quan"][qkeys[i]]=zeros((no_full_triangles,3), Float)
     254        tmp = pypar.receive(p)
     255        submesh_cell["full_quan"][qkeys[i]]=num.zeros((no_full_triangles,3), num.float)
    263256        submesh_cell["full_quan"][qkeys[i]][:] = tmp[:]
    264257
    265     new_quan = zeros((no_ghost_triangles, 3), Float)
    266258    submesh_cell["ghost_quan"]={}
    267259    for i in range(no_quantities):
    268         tmp = pypar.receive(p, new_quan)
    269         submesh_cell["ghost_quan"][qkeys[i]]= zeros((no_ghost_triangles,3), Float)
     260        tmp = pypar.receive(p)
     261        submesh_cell["ghost_quan"][qkeys[i]]= num.zeros((no_ghost_triangles,3), num.float)
    270262        submesh_cell["ghost_quan"][qkeys[i]][:] = tmp[:]
    271263   
     
    293285
    294286def rec_submesh(p):
    295 
     287   
    296288    numproc = pypar.size()
    297289    myid = pypar.rank()
Note: See TracChangeset for help on using the changeset viewer.