Changeset 8543


Ignore:
Timestamp:
Aug 30, 2012, 2:48:35 PM (13 years ago)
Author:
steve
Message:

small changes to parallel code

Location:
trunk/anuga_core/source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/generic_domain.py

    r8538 r8543  
    206206        self.numproc = numproc
    207207        self.ghost_layer_width = ghost_layer_width
     208        self.communication_time = 0.0
     209        self.communication_reduce_time = 0.0
     210        self.communication_broadcast_time = 0.0
    208211
    209212        # Setup Communication Buffers
     
    12871290        self.starttime = float(time)
    12881291        self.set_time(self.starttime)
    1289        
     1292
     1293
     1294
     1295    '''
     1296    Outputs domain triangulation, full triangles are shown in green while ghost triangles are shown in blue.
     1297    The default filename is "domain.png"
     1298    '''
     1299    def dump_triangulation(self, filename="domain.png"):
     1300        # Get vertex coordinates, partition full and ghost triangles based on self.tri_full_flag
     1301
     1302        try:
     1303            import matplotlib
     1304            matplotlib.use('Agg')
     1305            import matplotlib.pyplot as plt
     1306            import matplotlib.tri as tri
     1307        except:
     1308            print "Couldn't import module from matplotlib, probably you need to update matplotlib"
     1309            raise
     1310
     1311        vertices = self.get_vertex_coordinates()
     1312        full_mask = num.repeat(self.tri_full_flag == 1, 3)
     1313        ghost_mask = num.repeat(self.tri_full_flag == 0, 3)
     1314
     1315
     1316        # Proc 0 gathers full and ghost nodes from self and other processors
     1317        fx = vertices[full_mask,0]
     1318        fy = vertices[full_mask,1]
     1319        gx = vertices[ghost_mask,0]
     1320        gy = vertices[ghost_mask,1]
     1321
     1322
     1323        # Plot full triangles
     1324        n = int(len(fx)/3)
     1325
     1326        triang = num.array(range(0,3*n))
     1327        triang.shape = (n, 3)
     1328        plt.triplot(fx, fy, triang, 'g-')
     1329
     1330        # Plot ghost triangles
     1331        n = int(len(gx)/3)
     1332        if n > 0:
     1333            triang = num.array(range(0,3*n))
     1334            triang.shape = (n, 3)
     1335            plt.triplot(gx, g, triang, 'b--')
     1336
     1337        # Save triangulation to location pointed by filename
     1338        plt.savefig(filename)
     1339
     1340
    12901341
    12911342################################################################################
  • trunk/anuga_core/source/anuga_parallel/distribute_mesh.py

    r8538 r8543  
    10761076   
    10771077    myid = pypar.rank()
     1078    nprocs = pypar.size()
    10781079   
    10791080    if verbose: print 'P%d: Sending submesh to P%d' %(myid, p)
     
    10941095             counter = counter+1
    10951096
     1097
     1098    def protocol(x):
     1099        vanilla=False
     1100        control_info, x = pypar.create_control_info(x, vanilla, return_object=True)
     1101        print 'protocol', control_info[0]
     1102
     1103    # FIXME SR: Creates cPickle dump
     1104    print 'tagmap', tagmap
     1105    protocol(tagmap)
    10961106    pypar.send(tagmap, p)
    10971107
    10981108    # send the quantities key information
    10991109
     1110    # FIXME SR: Creates cPickle dump
     1111    print 'full_quant keys', submesh["full_quan"].keys()
     1112    protocol(submesh["full_quan"].keys())
    11001113    pypar.send(submesh["full_quan"].keys(), p)
    11011114
    1102     # send the number of triangles per processor
    1103 
    1104     pypar.send(triangles_per_proc, p)
    1105 
    1106     # ghost layer width
    1107 
    1108     pypar.send(submesh["ghost_layer_width"][p], p)
    1109 
    11101115    # compress full_commun
    1111 
    11121116    flat_full_commun = []
    11131117
     
    11281132    setup_array[7] = len(flat_full_commun)
    11291133    setup_array[8] = len(submesh["full_quan"])
    1130    
    1131     pypar.send(num.array(setup_array, num.int), p)
    1132    
     1134
     1135    i=0
     1136    i +=1 ; print 'send', i
     1137    protocol(num.array(setup_array, num.int))
     1138    pypar.send(setup_array, p, bypass=True)
     1139
     1140
     1141    # ghost layer width
     1142    i +=1 ; print 'send', i
     1143    protocol(num.array(submesh["ghost_layer_width"][p], num.int))
     1144    pypar.send(num.array(submesh["ghost_layer_width"][p], num.int), p, bypass=True)
     1145
     1146
     1147    # send the number of triangles per processor
     1148    i +=1 ; print 'send', i
     1149    protocol(num.array(triangles_per_proc))
     1150    pypar.send(num.array(triangles_per_proc), p, bypass=True)
     1151
    11331152    # send the nodes
    1134 
     1153    i +=1 ; print 'send', i
     1154    protocol(num.array(submesh["full_nodes"][p], num.float))
     1155    #pypar.send(num.array(submesh["full_nodes"][p], num.float), p, bypass=False)
    11351156    pypar.send(num.array(submesh["full_nodes"][p], num.float), p)
    1136     pypar.send(num.array(submesh["ghost_nodes"][p], num.float),p)
     1157
     1158
     1159    i +=1 ; print 'send', i
     1160    protocol(num.array(submesh["ghost_nodes"][p], num.float))
     1161    pypar.send(num.array(submesh["ghost_nodes"][p], num.float),p, bypass=False)
    11371162
    11381163    # send the triangles
    11391164
    1140     pypar.send(num.array(submesh["full_triangles"][p],  num.int), p)
    1141     pypar.send(num.array(submesh["ghost_triangles"][p], num.int), p)
     1165    i +=1 ; print 'send', i
     1166    protocol(num.array(submesh["full_triangles"][p],  num.int))
     1167    pypar.send(num.array(submesh["full_triangles"][p],  num.int), p, bypass=False)
     1168    i +=1 ; print 'send', i
     1169    protocol(num.array(submesh["ghost_triangles"][p], num.int))
     1170    pypar.send(num.array(submesh["ghost_triangles"][p], num.int), p, bypass=False)
    11421171
    11431172    # send the boundary
     
    11471176        bc.append([b[0], b[1], tagmap[submesh["full_boundary"][p][b]]])
    11481177
    1149 
    1150     pypar.send(num.array(bc, num.int), p)
     1178    i +=1 ; print 'send', i
     1179    protocol(num.array(bc, num.int))
     1180    pypar.send(num.array(bc, num.int), p, bypass=False)
    11511181
    11521182    bc = []
     
    11541184        bc.append([b[0], b[1], tagmap[submesh["ghost_boundary"][p][b]]])
    11551185
    1156     pypar.send(num.array(bc, num.int), p)
     1186    i +=1 ; print 'send', i
     1187    protocol(num.array(bc, num.int))
     1188    pypar.send(num.array(bc, num.int), p, bypass=False)
    11571189
    11581190    # send the communication pattern
    11591191
    1160     pypar.send(submesh["ghost_commun"][p], p)
    1161 
    1162     pypar.send(num.array(flat_full_commun, num.int), p)
     1192    # submesh["ghost_commun"][p] is numpy array
     1193    i +=1 ; print 'send', i
     1194    protocol(submesh["ghost_commun"][p])
     1195    pypar.send(submesh["ghost_commun"][p], p, bypass=False)
     1196
     1197    i +=1 ; print 'send', i
     1198    protocol(num.array(flat_full_commun, num.int))
     1199    pypar.send(num.array(flat_full_commun, num.int), p, bypass=False)
    11631200
    11641201    # send the quantities
     1202
    11651203   
    11661204    for k in submesh["full_quan"]:
    1167         pypar.send(num.array(submesh["full_quan"][k][p], num.float), p)
     1205        print 'send full', ++i, k
     1206        protocol(num.array(submesh["full_quan"][k][p], num.float))
     1207        pypar.send(num.array(submesh["full_quan"][k][p], num.float), p, bypass=False)
    11681208       
    11691209    for k in submesh["ghost_quan"]:
    1170         pypar.send(num.array(submesh["ghost_quan"][k][p], num.float),p)
     1210        print 'send ghost', ++i, k
     1211        protocol(num.array(submesh["ghost_quan"][k][p], num.float))
     1212        pypar.send(num.array(submesh["ghost_quan"][k][p], num.float),p, bypass=False)
    11711213       
    11721214
     
    11921234    import pypar
    11931235   
    1194     numproc = pypar.size()
     1236    numprocs = pypar.size()
    11951237    myid = pypar.rank()
    11961238
     
    12111253    qkeys = pypar.receive(p)
    12121254
    1213     # receive the number of triangles per processor
    1214 
    1215     triangles_per_proc = pypar.receive(p)
    1216 
    1217     # ghost layer width
    1218 
    1219     submesh_cell["ghost_layer_width"] = pypar.receive(p)
    12201255
    12211256    # recieve information about the array sizes
    12221257
    1223     setup_array = pypar.receive(p)
     1258    x = num.zeros((9,),num.int)
     1259    pypar.receive(p, buffer=x,  bypass=True)
     1260    setup_array = x
    12241261
    12251262    no_full_nodes      = setup_array[0]
     
    12321269    no_full_commun     = setup_array[7]
    12331270    no_quantities      = setup_array[8]
    1234    
     1271
     1272
     1273    # ghost layer width
     1274    x = num.zeros((1,),num.int)
     1275    pypar.receive(p, buffer=x,  bypass=True)
     1276    submesh_cell["ghost_layer_width"] = x[0]
     1277
     1278
     1279    # receive the number of triangles per processor
     1280    x = num.zeros((numprocs,),num.int)
     1281    pypar.receive(p, buffer=x,  bypass=True)
     1282    triangles_per_proc = x
     1283
    12351284    # receive the full nodes
     1285#    x = num.zeros((no_full_nodes,),num.int)
     1286#    pypar.receive(p, buffer=x,  bypass=True)
     1287#    submesh_cell["full_nodes"] = x
     1288
    12361289
    12371290    submesh_cell["full_nodes"] = pypar.receive(p)
    1238 
    12391291    # receive the ghost nodes
    12401292
    1241     submesh_cell["ghost_nodes"] = pypar.receive(p)
     1293    submesh_cell["ghost_nodes"] = pypar.receive(p, bypass=False)
    12421294   
    12431295    # receive the full triangles
    12441296
    1245     submesh_cell["full_triangles"] = pypar.receive(p)
     1297    submesh_cell["full_triangles"] = pypar.receive(p, bypass=False)
    12461298   
    12471299    # receive the ghost triangles
    12481300
    1249     submesh_cell["ghost_triangles"] = pypar.receive(p)
     1301    submesh_cell["ghost_triangles"] = pypar.receive(p, bypass=False)
    12501302
    12511303    # receive the full boundary
    12521304
    1253     bnd_c = pypar.receive(p)
     1305    bnd_c = pypar.receive(p, bypass=False)
    12541306
    12551307    submesh_cell["full_boundary"] = {}
     
    12591311    # receive the ghost boundary
    12601312
    1261     bnd_c = pypar.receive(p)
     1313    bnd_c = pypar.receive(p, bypass=False)
    12621314
    12631315    submesh_cell["ghost_boundary"] = {}
     
    12671319    # receive the ghost communication pattern
    12681320
    1269     submesh_cell["ghost_commun"] = pypar.receive(p)
     1321    submesh_cell["ghost_commun"] = pypar.receive(p, bypass=False)
    12701322   
    12711323    # receive the full communication pattern
    12721324
    1273     full_commun = pypar.receive(p)
     1325    full_commun = pypar.receive(p, bypass=False)
    12741326
    12751327    submesh_cell["full_commun"] = {}
     
    12841336   
    12851337    for i in range(no_quantities):
    1286         tmp = pypar.receive(p)
     1338        tmp = pypar.receive(p, bypass=False)
    12871339        submesh_cell["full_quan"][qkeys[i]]=num.zeros((no_full_triangles,3), num.float)
    12881340        submesh_cell["full_quan"][qkeys[i]][:] = tmp[:]
     
    12901342    submesh_cell["ghost_quan"]={}
    12911343    for i in range(no_quantities):
    1292         tmp = pypar.receive(p)
     1344        tmp = pypar.receive(p, bypass=False)
    12931345        submesh_cell["ghost_quan"][qkeys[i]]= num.zeros((no_ghost_triangles,3), num.float)
    12941346        submesh_cell["ghost_quan"][qkeys[i]][:] = tmp[:]
  • trunk/anuga_core/source/anuga_parallel/parallel_api.py

    r8538 r8543  
    5757
    5858
    59 
    60 
    61     if not pypar_available: return domain # Bypass
     59    if not pypar_available or numprocs == 1 : return domain # Bypass
    6260
    6361    # For some obscure reason this communication must happen prior to
     
    7573
    7674        for p in range(1, numprocs):
     75            # FIXME SR: Creates cPickle dump
    7776            send((domain_name, domain_dir, domain_store, \
    7877                  domain_minimum_storable_height, georef, \
     
    130129        # Send serial to parallel (s2p) and parallel to serial (p2s) triangle mapping to proc 1 .. numprocs
    131130        for p in range(1, numprocs):
     131            # FIXME SR: Creates cPickle dump
    132132            send(s2p_map, p)
     133            # FIXME SR: Creates cPickle dump
    133134            send(p2s_map, p)
    134135
     
    250251    if verbose: print 'Distribute submeshes'       
    251252    for p in range(1, numprocs):
    252       send_submesh(submesh, triangles_per_proc, p, verbose)
     253        send_submesh(submesh, triangles_per_proc, p, verbose)
    253254
    254255    # Build the local mesh for processor 0
  • trunk/anuga_core/source/anuga_parallel/run_parallel_sw_rectangular_cross.py

    r8542 r8543  
    3333t0 = time.time()
    3434
    35 verbose = False
     35verbose = True
    3636
    3737#--------------------------------------------------------------------------
     
    4141    length = 2.0
    4242    width = 2.0
    43     dx = dy = 0.005
     43    #dx = dy = 0.005
     44    dx = dy = 0.01
    4445    domain = rectangular_cross_domain(int(length/dx), int(width/dy),
    4546                                              len1=length, len2=width)
     
    159160
    160161
    161 #domain.dump_triangulation(filename="rectangular_cross_%g.png"% numprocs)
     162if domain.number_of_global_triangles < 50000:
     163    print 'Create dump of triangulation for {0} triangles'.format(domain.number_of_global_triangles)
     164    domain.dump_triangulation(filename="rectangular_cross_%g.png"% numprocs)
    162165
    163166finalize()
Note: See TracChangeset for help on using the changeset viewer.