source: anuga_core/source/anuga_parallel/parallel_api.py @ 3593

Last change on this file since 3593 was 3593, checked in by ole, 18 years ago

Got first version of parallel api going

Still todo: Communicate all attributes of domain such as name and also boundary conditions across to other processes automatically.

File size: 3.5 KB
Line 
1"""Trying to lump parallel stuff into simpler interface
2
3
4"""
5
6# Parallelism
7import pypar   # The Python-MPI interface
8from anuga_parallel.pmesh_divide  import pmesh_divide_metis
9from anuga_parallel.build_submesh import build_submesh
10from anuga_parallel.build_local   import build_local_mesh
11from anuga_parallel.build_commun  import send_submesh, rec_submesh, extract_hostmesh
12from anuga_parallel.parallel_shallow_water import Parallel_Domain
13
14
15#------------------------------------------------------------------------------
16# Read in processor information
17#------------------------------------------------------------------------------
18
19numprocs = pypar.size()
20myid = pypar.rank()
21processor_name = pypar.Get_processor_name()
22print 'I am processor %d of %d on node %s' %(myid, numprocs, processor_name)
23
24
25
26
27def 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
75def 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
100    # Return structures necessary for building the parallel domain
101    return points, vertices, boundary, quantities, \
102           ghost_recv_dict, full_send_dict
103   
104
105
106
Note: See TracBrowser for help on using the repository browser.