source: inundation/parallel/build_commun.py @ 2090

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

Removed pypar test files and commented pmesh_divide

File size: 8.5 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    for c in submesh["full_commun"][p]:
75        for i in range(len(submesh["full_commun"][p][c])):
76            flat_full_commun.append([c,submesh["full_commun"][p][c][i]])
77
78    # send the array sizes so memory can be allocated
79
80    setup_array = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
81    setup_array[0] = len(submesh["full_nodes"][p])
82    setup_array[1] = len(submesh["ghost_nodes"][p])
83    setup_array[2] = len(submesh["full_triangles"][p])
84    setup_array[3] = len(submesh["ghost_triangles"][p])
85    setup_array[4] = len(submesh["full_boundary"][p])
86    setup_array[5] = len(submesh["ghost_commun"][p])
87    setup_array[6] = len(flat_full_commun)
88
89    pypar.send(setup_array, p)
90   
91    # send the nodes
92   
93    pypar.send(submesh["full_nodes"][p], p, use_buffer=True)
94    pypar.send(submesh["ghost_nodes"][p], p, use_buffer=True)
95
96    # send the triangles
97
98    pypar.send(array(submesh["full_triangles"][p], Int), p, use_buffer=True)
99    pypar.send(submesh["ghost_triangles"][p], p, use_buffer=True)
100
101    # send the boundary (is it quicker to send as an array?)
102
103    bc = []
104    for b in submesh["full_boundary"][p]:
105        bc.append([b[0], b[1], tagmap[submesh["full_boundary"][p][b]]])
106    pypar.send(bc, p, use_buffer=True)
107
108    # send the communication pattern
109
110    pypar.send(submesh["ghost_commun"][p], p, use_buffer=True)
111    pypar.send(flat_full_commun, p, use_buffer=True)
112
113    # send the quantities
114   
115    for k in submesh["full_quan"]:
116        pypar.send(submesh["full_quan"][k][p], p, use_buffer=True)
117       
118    for k in submesh["ghost_quan"]:
119        pypar.send(submesh["ghost_quan"][k][p], p, use_buffer=True)
120       
121
122#########################################################
123#
124# Receive the submesh from processor p.
125#
126# *) The order and form is strongly coupled with
127# send_submesh.
128#
129# -------------------------------------------------------
130#
131# *) All of the information has been received by the
132# processor p and passed into build_local.
133#
134# *) The information is returned in a form needed by the
135# GA datastructure.
136#
137#########################################################
138
139def rec_submesh_flat(p):
140
141    from Numeric import zeros, Float, Int
142
143    numproc = pypar.size()
144    myid = pypar.rank()
145
146    submesh_cell = {}
147   
148    print "pypar receiving submesh from processor ",p
149
150    # receive the tagmap for the boundary conditions
151   
152    tagmap = pypar.receive(p)
153
154    # receive the quantities key information
155   
156    qkeys = pypar.receive(p)
157
158    # receive the number of triangles per processor
159
160    triangles_per_proc = []
161    for i in range(numproc):
162        triangles_per_proc.append([0])
163
164    triangles_per_proc = pypar.receive(p, triangles_per_proc)
165
166    # recieve information about the array sizes
167
168    setup_array = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
169    setup_array = pypar.receive(p, setup_array)
170
171    # receive the full nodes
172
173    no_full_nodes = setup_array[0]
174    full_nodes = zeros((no_full_nodes, 3), Float)
175    submesh_cell["full_nodes"] = pypar.receive(p, full_nodes)
176   
177    # receive the ghost nodes
178
179    no_ghost_nodes = setup_array[1]
180    ghost_nodes = zeros((no_ghost_nodes, 3), Float)
181    submesh_cell["ghost_nodes"] = pypar.receive(p, ghost_nodes)
182
183   
184    # receive the full triangles
185
186    no_full_triangles = setup_array[2]
187    full_triangles = zeros((no_full_triangles, 3), Int)
188    submesh_cell["full_triangles"] = pypar.receive(p, full_triangles)
189   
190    # receive the ghost triangles
191
192    no_ghost_triangles = setup_array[3]
193    ghost_triangles = zeros((no_ghost_triangles, 4), Int)
194    submesh_cell["ghost_triangles"] = pypar.receive(p, ghost_triangles)
195   
196    # receive the full boundary
197
198    no_full_boundary = setup_array[4]
199    bc = []
200    for i in range(no_full_boundary):
201        bc.append([0.0, 0.0, 0.0])
202    bnd_c = pypar.receive(p, bc)
203
204    itagmap = {}
205    for t in tagmap:
206        itagmap[tagmap[t]]=t
207
208    submesh_cell["full_boundary"] = {}
209    for b in bnd_c:
210        submesh_cell["full_boundary"][b[0],b[1]]=itagmap[b[2]]
211
212    # receive the ghost communication pattern
213
214    no_ghost_commun = setup_array[5]
215    ghost_commun = zeros((no_ghost_commun, 2), Int)
216    submesh_cell["ghost_commun"] = pypar.receive(p, ghost_commun)
217   
218    # receive the full communication pattern
219
220    no_full_commun = setup_array[6]
221    full_commun = []
222    for i in range(no_full_commun):
223        full_commun.append([0.0, 0.0])
224
225    full_commun = pypar.receive(p, full_commun)
226
227    submesh_cell["full_commun"] = {}
228    for c in full_commun:
229        submesh_cell["full_commun"][c[0]] = []
230    for c in full_commun:
231        submesh_cell["full_commun"][c[0]].append(c[1])
232
233    # receive the quantities
234
235    no_quantities = len(qkeys)
236    new_quan = zeros((no_full_triangles, 3), Float)
237    submesh_cell["full_quan"]={}
238   
239    for i in range(no_quantities):
240        tmp = pypar.receive(p, new_quan)
241        submesh_cell["full_quan"][qkeys[i]]=zeros((no_full_triangles,3), Float)
242        submesh_cell["full_quan"][qkeys[i]][:] = tmp[:]
243
244    new_quan = zeros((no_ghost_triangles, 3), Float)
245    submesh_cell["ghost_quan"]={}
246    for i in range(no_quantities):
247        tmp = pypar.receive(p, new_quan)
248        submesh_cell["ghost_quan"][qkeys[i]]= zeros((no_ghost_triangles,3), Float)
249        submesh_cell["ghost_quan"][qkeys[i]][:] = tmp[:]
250   
251    return submesh_cell, triangles_per_proc
252
253
254
255#########################################################
256#
257# Receive the submesh from processor p.
258#
259# *) The order and form is strongly coupled with
260# send_submesh.
261#
262# -------------------------------------------------------
263#
264# *) All of the information has been received by the
265# processor p and passed into build_local.
266#
267# *) The information is returned in a form needed by the
268# GA datastructure.
269#
270#########################################################
271
272def rec_submesh(p):
273
274    from Numeric import zeros, Float, Int
275
276    numproc = pypar.size()
277    myid = pypar.rank()
278
279    [submesh_cell, triangles_per_proc] = rec_submesh_flat(p)
280   
281    # find the full triangles assigned to this processor
282
283    lower_t = 0
284    for i in range(myid):
285        lower_t = lower_t+triangles_per_proc[i]
286    upper_t = lower_t+triangles_per_proc[myid]
287
288    # convert the information into a form needed by the GA
289    # datastructure
290
291    [GAnodes, GAtriangles, boundary, quantities, ghost_rec, full_send] = \
292              build_local_mesh(submesh_cell, lower_t, upper_t, \
293                               numproc)
294   
295    return GAnodes, GAtriangles, boundary, quantities, ghost_rec, full_send
296
297
Note: See TracBrowser for help on using the repository browser.