[3584] | 1 | """Trying to lump parallel stuff into simpler interface |
---|
| 2 | |
---|
[3585] | 3 | |
---|
[3584] | 4 | """ |
---|
[3585] | 5 | |
---|
| 6 | # Parallelism |
---|
| 7 | import pypar # The Python-MPI interface |
---|
| 8 | from anuga_parallel.pmesh_divide import pmesh_divide_metis |
---|
| 9 | from anuga_parallel.build_submesh import build_submesh |
---|
| 10 | from anuga_parallel.build_local import build_local_mesh |
---|
| 11 | from anuga_parallel.build_commun import send_submesh, rec_submesh, extract_hostmesh |
---|
| 12 | from anuga_parallel.parallel_shallow_water import Parallel_Domain |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | #------------------------------------------------------------------------------ |
---|
| 16 | # Read in processor information |
---|
| 17 | #------------------------------------------------------------------------------ |
---|
| 18 | |
---|
| 19 | numprocs = pypar.size() |
---|
| 20 | myid = pypar.rank() |
---|
| 21 | processor_name = pypar.Get_processor_name() |
---|
| 22 | print 'I am processor %d of %d on node %s' %(myid, numprocs, processor_name) |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | |
---|
[3593] | 27 | def distribute(domain): |
---|
| 28 | |
---|
| 29 | if myid == 0: |
---|
| 30 | #------------------------------------------------------------------- |
---|
| 31 | # Distribute the domain |
---|
| 32 | #------------------------------------------------------------------- |
---|
| 33 | |
---|
| 34 | points, vertices, boundary, quantities,\ |
---|
| 35 | ghost_recv_dict, full_send_dict,\ |
---|
| 36 | = distribute_mesh(domain) |
---|
| 37 | print 'Communication done' |
---|
| 38 | |
---|
| 39 | else: |
---|
| 40 | # Read in the mesh partition that belongs to this |
---|
| 41 | # processor (note that the information is in the |
---|
| 42 | # correct form for the GA data structure) |
---|
| 43 | |
---|
| 44 | points, vertices, boundary, quantities,\ |
---|
| 45 | ghost_recv_dict, full_send_dict,\ |
---|
| 46 | = rec_submesh(0) |
---|
| 47 | |
---|
| 48 | #------------------------------------------------------------------------ |
---|
| 49 | # Start the computations on each subpartion |
---|
| 50 | #------------------------------------------------------------------------ |
---|
| 51 | |
---|
| 52 | # Build the domain for this processor |
---|
| 53 | domain = Parallel_Domain(points, vertices, boundary, |
---|
| 54 | full_send_dict = full_send_dict, |
---|
| 55 | ghost_recv_dict = ghost_recv_dict) |
---|
| 56 | |
---|
| 57 | #------------------------------------------------------------------------ |
---|
| 58 | # Setup initial conditions |
---|
| 59 | #------------------------------------------------------------------------ |
---|
| 60 | for q in quantities: |
---|
| 61 | domain.set_quantity(q, quantities[q]) # Distribute all quantities |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | #------------------------------------------------------------------------ |
---|
| 65 | # Return parallel domain to all nodes |
---|
| 66 | #------------------------------------------------------------------------ |
---|
| 67 | return domain |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
[3585] | 75 | def distribute_mesh(domain): |
---|
| 76 | |
---|
| 77 | numprocs = pypar.size() |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | # Subdivide the mesh |
---|
| 81 | print 'Subdivide mesh' |
---|
| 82 | nodes, triangles, boundary, triangles_per_proc, quantities = \ |
---|
| 83 | pmesh_divide_metis(domain, numprocs) |
---|
| 84 | |
---|
| 85 | # Build the mesh that should be assigned to each processor, |
---|
| 86 | # this includes ghost nodes and the communicaiton pattern |
---|
| 87 | print 'Build submeshes' |
---|
| 88 | submesh = build_submesh(nodes, triangles, boundary,\ |
---|
| 89 | quantities, triangles_per_proc) |
---|
| 90 | |
---|
| 91 | # Send the mesh partition to the appropriate processor |
---|
| 92 | print 'Distribute submeshes' |
---|
| 93 | for p in range(1, numprocs): |
---|
| 94 | send_submesh(submesh, triangles_per_proc, p) |
---|
| 95 | |
---|
| 96 | # Build the local mesh for processor 0 |
---|
| 97 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \ |
---|
| 98 | extract_hostmesh(submesh, triangles_per_proc) |
---|
| 99 | |
---|
[3588] | 100 | # Return structures necessary for building the parallel domain |
---|
[3585] | 101 | return points, vertices, boundary, quantities, \ |
---|
| 102 | ghost_recv_dict, full_send_dict |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|