1 | """Trying to lump parallel stuff into simpler interface |
---|
2 | |
---|
3 | |
---|
4 | """ |
---|
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 | |
---|
27 | def distribute_mesh(domain): |
---|
28 | |
---|
29 | numprocs = pypar.size() |
---|
30 | |
---|
31 | |
---|
32 | # Subdivide the mesh |
---|
33 | print 'Subdivide mesh' |
---|
34 | nodes, triangles, boundary, triangles_per_proc, quantities = \ |
---|
35 | pmesh_divide_metis(domain, numprocs) |
---|
36 | |
---|
37 | # Build the mesh that should be assigned to each processor, |
---|
38 | # this includes ghost nodes and the communicaiton pattern |
---|
39 | print 'Build submeshes' |
---|
40 | submesh = build_submesh(nodes, triangles, boundary,\ |
---|
41 | quantities, triangles_per_proc) |
---|
42 | |
---|
43 | # Send the mesh partition to the appropriate processor |
---|
44 | print 'Distribute submeshes' |
---|
45 | for p in range(1, numprocs): |
---|
46 | send_submesh(submesh, triangles_per_proc, p) |
---|
47 | |
---|
48 | # Build the local mesh for processor 0 |
---|
49 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \ |
---|
50 | extract_hostmesh(submesh, triangles_per_proc) |
---|
51 | |
---|
52 | # Return stuff |
---|
53 | return points, vertices, boundary, quantities, \ |
---|
54 | ghost_recv_dict, full_send_dict |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | |
---|