source: inundation/parallel/build_commun.py @ 2004

Last change on this file since 2004 was 1582, checked in by linda, 19 years ago

fixed bug in build_commun for receiving quantities

File size: 8.3 KB
Line 
1#########################################################
2#
3# Handle the communication between the host machine
4# (processor 0) and the processors. The host machine is
5# responsible for the doing the initial grid partitioning.
6#
7# The routines given below should be moved to the
8# build_submesh.py and build_local.py file to allow
9# overlapping of  communication and computation.
10# This should be done after more debugging.
11#
12#
13#  Author: Linda Stals, June 2005
14#
15#
16#########################################################
17
18from Numeric import array, Int, Float
19import logging, logging.config
20logger = logging.getLogger('parallel')
21logger.setLevel(logging.WARNING)
22
23try:
24    logging.config.fileConfig('log.ini')
25except:
26    pass
27
28
29import sys
30import pypar
31from Numeric import zeros
32from build_local import *
33
34#########################################################
35#
36# Send the submesh to processor p.
37#
38# *) The order and form is strongly coupled with
39# rec_submesh.
40#
41# -------------------------------------------------------
42#
43# *) All of the information has been sent to processor p.
44#
45#########################################################
46
47def send_submesh(submesh, triangles_per_proc, p):
48
49    print "pypar sending submesh to processor ",p
50   
51    # build and send the tagmap for the boundary conditions
52   
53    tagmap = {}
54    counter = 1
55    for b in submesh["full_boundary"][p]:
56         bkey = submesh["full_boundary"][p][b]
57         if not tagmap.has_key(bkey):
58             tagmap[bkey] = counter
59             counter = counter+1
60    pypar.send(tagmap, p)
61
62    # send the quantities key information
63   
64    pypar.send(submesh["full_quan"].keys(), p)
65   
66    # send the number of triangles per processor
67
68    pypar.send(triangles_per_proc, p, use_buffer=True)
69
70    # compress full_commun
71
72    flat_full_commun = []
73
74
75    for c in submesh["full_commun"][p]:
76        for i in range(len(submesh["full_commun"][p][c])):
77            flat_full_commun.append([c,submesh["full_commun"][p][c][i]])
78
79    # send the array sizes so memory can be allocated
80
81    setup_array = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
82    setup_array[0] = len(submesh["full_nodes"][p])
83    setup_array[1] = len(submesh["ghost_nodes"][p])
84    setup_array[2] = len(submesh["full_triangles"][p])
85    setup_array[3] = len(submesh["ghost_triangles"][p])
86    setup_array[4] = len(submesh["full_boundary"][p])
87    setup_array[5] = len(submesh["ghost_commun"][p])
88    setup_array[6] = len(flat_full_commun)
89
90    pypar.send(setup_array, p)
91   
92    # send the nodes
93
94    pypar.send(submesh["full_nodes"][p], p, use_buffer=True)
95    pypar.send(submesh["ghost_nodes"][p], p, use_buffer=True)
96
97    # send the triangles
98   
99    pypar.send(array(submesh["full_triangles"][p], Int), p, use_buffer=True)
100    pypar.send(submesh["ghost_triangles"][p], p, use_buffer=True)
101
102    # send the boundary (is it quicker to send as an array?)
103
104    bc = []
105    for b in submesh["full_boundary"][p]:
106        bc.append([b[0], b[1], tagmap[submesh["full_boundary"][p][b]]])
107    pypar.send(bc, p, use_buffer=True)
108
109    # send the communication pattern
110
111    pypar.send(submesh["ghost_commun"][p], p, use_buffer=True)
112    pypar.send(flat_full_commun, p, use_buffer=True)
113
114    # send the quantities
115   
116    for k in submesh["full_quan"]:
117        pypar.send(submesh["full_quan"][k][p], p, use_buffer=True)
118       
119    for k in submesh["ghost_quan"]:
120        pypar.send(submesh["ghost_quan"][k][p], p, use_buffer=True)
121       
122   
123#########################################################
124#
125# Receive the submesh from processor p.
126#
127# *) The order and form is strongly coupled with
128# send_submesh.
129#
130# -------------------------------------------------------
131#
132# *) All of the information has been received by the
133# processor p and passed into build_local.
134#
135# *) The information is returned in a form needed by the
136# GA datastructure.
137#
138#########################################################
139
140def rec_submesh(p):
141
142    from Numeric import zeros, Float, Int
143
144    numproc = pypar.size()
145    myid = pypar.rank()
146
147    submesh_cell = {}
148   
149    print "pypar receiving submesh from processor ",p
150
151    # receive the tagmap for the boundary conditions
152   
153    tagmap = pypar.receive(p)
154
155    # receive the quantities key information
156   
157    qkeys = pypar.receive(p)
158
159    # receive the number of triangles per processor
160
161    triangles_per_proc = []
162    for i in range(numproc):
163        triangles_per_proc.append([0])
164
165    triangles_per_proc = pypar.receive(p, triangles_per_proc)
166
167    # recieve information about the array sizes
168
169    setup_array = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
170    setup_array = pypar.receive(p, setup_array)
171
172    # receive the full nodes
173
174    no_full_nodes = setup_array[0]
175    full_nodes = []
176    for i in range(no_full_nodes):
177        full_nodes.append([0.0, 0.0, 0.0])
178    submesh_cell["full_nodes"] = pypar.receive(p, full_nodes)
179
180    # receive the ghost nodes
181
182    no_ghost_nodes = setup_array[1]
183    ghost_nodes = []
184    for i in range(no_ghost_nodes):
185        ghost_nodes.append([0, 0.0, 0.0])
186    submesh_cell["ghost_nodes"] = pypar.receive(p, ghost_nodes)
187
188    # receive the full triangles
189
190    no_full_triangles = setup_array[2]
191    submesh_cell["full_triangles"] = []
192    for i in range(no_full_triangles):
193        submesh_cell["full_triangles"].append([0, 0, 0])
194
195    full_triangles = pypar.receive(p, array(submesh_cell["full_triangles"], Int))
196   
197    for i in range(no_full_triangles):
198        submesh_cell["full_triangles"][i][0] = full_triangles[i][0]
199        submesh_cell["full_triangles"][i][1] = full_triangles[i][1]
200        submesh_cell["full_triangles"][i][2] = full_triangles[i][2]
201
202    # receive the ghost triangles
203
204    no_ghost_triangles = setup_array[3]
205    ghost_triangles = []
206    for i in range(no_ghost_triangles):
207        ghost_triangles.append([0, [0.0, 0.0, 0.0]])
208    submesh_cell["ghost_triangles"] = pypar.receive(p, ghost_triangles)
209
210    # receive the full boundary
211
212    no_full_boundary = setup_array[4]
213    bc = []
214    for i in range(no_full_boundary):
215        bc.append([0.0, 0.0, 0.0])
216    bnd_c = pypar.receive(p, bc)
217
218    itagmap = {}
219    for t in tagmap:
220        itagmap[tagmap[t]]=t
221
222    submesh_cell["full_boundary"] = {}
223    for b in bnd_c:
224        submesh_cell["full_boundary"][b[0],b[1]]=itagmap[b[2]]
225
226    # receive the ghost communication pattern
227
228    no_ghost_commun = setup_array[5]
229    ghost_commun = []
230    for i in range(no_ghost_commun):
231        ghost_commun.append([0.0, 0.0])
232
233    submesh_cell["ghost_commun"] = pypar.receive(p, ghost_commun)
234
235    # receive the full communication pattern
236
237    no_full_commun = setup_array[6]
238    full_commun = []
239    for i in range(no_full_commun):
240        full_commun.append([0.0, 0.0])
241
242    full_commun = pypar.receive(p, full_commun)
243
244    submesh_cell["full_commun"] = {}
245    for c in full_commun:
246        submesh_cell["full_commun"][c[0]] = []
247    for c in full_commun:
248        submesh_cell["full_commun"][c[0]].append(c[1])
249
250    # receive the quantities
251
252    no_quantities = len(qkeys)
253    new_quan = zeros((no_full_triangles, 3), Float)
254    submesh_cell["full_quan"]={}
255   
256    for i in range(no_quantities):
257        tmp = pypar.receive(p, new_quan)
258        submesh_cell["full_quan"][qkeys[i]]=zeros((no_full_triangles,3), Float)
259        submesh_cell["full_quan"][qkeys[i]][:] = tmp[:]
260
261    new_quan = zeros((no_ghost_triangles, 3), Float)
262    submesh_cell["ghost_quan"]={}
263    for i in range(no_quantities):
264        tmp = pypar.receive(p, new_quan)
265        submesh_cell["ghost_quan"][qkeys[i]]= zeros((no_ghost_triangles,3), Float)
266        submesh_cell["ghost_quan"][qkeys[i]][:] = tmp[:]
267   
268    # find the full triangles assigned to this processor
269
270    lower_t = 0
271    for i in range(myid):
272        lower_t = lower_t+triangles_per_proc[i]
273    upper_t = lower_t+triangles_per_proc[myid]
274
275    # convert the information into a form needed by the GA
276    # datastructure
277
278    [GAnodes, GAtriangles, boundary, quantities, ghost_rec, full_send] = \
279              build_local_mesh(submesh_cell, lower_t, upper_t, \
280                               numproc)
281
282    return GAnodes, GAtriangles, boundary, quantities, ghost_rec, full_send
283
284
Note: See TracBrowser for help on using the repository browser.