Changeset 2130
- Timestamp:
- Dec 8, 2005, 8:29:24 AM (18 years ago)
- Location:
- inundation/parallel
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/parallel/build_commun.py
r2094 r2130 17 17 ######################################################### 18 18 19 from Numeric import array, Int, Float 19 from Numeric import array, Int, Float, zeros 20 20 import logging, logging.config 21 21 logger = logging.getLogger('parallel') … … 30 30 import sys 31 31 import pypar 32 from Numeric import zeros 33 from build_local import *32 33 from build_local import build_local_mesh 34 34 35 35 ######################################################### … … 140 140 def rec_submesh_flat(p): 141 141 142 from Numeric import zeros, Float, Int143 144 142 numproc = pypar.size() 145 143 myid = pypar.rank() … … 273 271 def rec_submesh(p): 274 272 275 from Numeric import zeros, Float, Int276 277 273 numproc = pypar.size() 278 274 myid = pypar.rank() -
inundation/parallel/build_local.py
r2091 r2130 18 18 ######################################################### 19 19 20 from mesh import * 21 from Numeric import * 20 from Numeric import zeros, Float, Int, concatenate, \ 21 take, arrayrange, put, sort, compress, equal 22 22 23 23 24 ######################################################### … … 44 45 Ntriangles = len(triangles) 45 46 46 # extract the nodes (using the local ID)47 # Extract the nodes (using the local ID) 47 48 48 49 GAnodes = take(nodes, (1, 2), 1) 49 50 50 # build a global ID to local ID mapping51 # Build a global ID to local ID mapping 51 52 52 53 NGlobal = 0 … … 55 56 NGlobal = nodes[i][0] 56 57 index = zeros(int(NGlobal)+1, Int) 57 put(index, take(nodes, (0,), 1).astype(Int), arrayrange(Nnodes)) 58 put(index, take(nodes, (0,), 1).astype(Int), \ 59 arrayrange(Nnodes)) 58 60 59 # change the global IDs in the triangles to the local IDs61 # Change the global IDs in the triangles to the local IDs 60 62 61 63 GAtriangles = zeros((Ntriangles, 3), Int) … … 94 96 def build_local_commun(index, ghostc, fullc, nproc): 95 97 96 # initialise98 # Initialise 97 99 98 100 full_send = {} 99 101 ghost_recv = {} 100 102 101 # build the ghost_recv dictionary (sort the103 # Build the ghost_recv dictionary (sort the 102 104 # information by the global numbering) 103 105 … … 112 114 ghost_recv[c][0] = take(index, d) 113 115 114 # build a temporary copy of the full_send dictionary116 # Build a temporary copy of the full_send dictionary 115 117 # (this version allows the information to be stored 116 118 # by the global numbering) … … 122 124 if not tmp_send.has_key(neigh): 123 125 tmp_send[neigh] = [] 124 tmp_send[neigh].append([global_id, index[global_id]]) 125 126 # extract the full send information and put it in the form 126 tmp_send[neigh].append([global_id, \ 127 index[global_id]]) 128 129 # Extract the full send information and put it in the form 127 130 # required for the full_send dictionary 128 131 … … 158 161 def build_local_mesh(submesh, lower_t, upper_t, nproc): 159 162 160 # combine the full nodes and ghost nodes 161 162 nodes = concatenate((submesh["full_nodes"], submesh["ghost_nodes"])) 163 164 # combine the full triangles and ghost triangles 163 # Combine the full nodes and ghost nodes 164 165 nodes = concatenate((submesh["full_nodes"], \ 166 submesh["ghost_nodes"])) 167 168 # Combine the full triangles and ghost triangles 165 169 166 170 gtri = take(submesh["ghost_triangles"],(1, 2, 3),1) 167 171 triangles = concatenate((submesh["full_triangles"], gtri)) 168 172 169 # renumber the boundary edges to correspond to the new173 # Renumber the boundary edges to correspond to the new 170 174 # triangle numbering 171 175 172 176 GAboundary = {} 173 177 for b in submesh["full_boundary"]: 174 GAboundary[b[0]-lower_t,b[1]] =submesh["full_boundary"][b]175 176 # make note of the new triangle numbers, including the ghost178 GAboundary[b[0]-lower_t,b[1]] = submesh["full_boundary"][b] 179 180 # Make note of the new triangle numbers, including the ghost 177 181 # triangles 178 182 … … 187 191 index[submesh["ghost_triangles"][i][0]] = i+upper_t-lower_t 188 192 189 # change the node numbering (and update the numbering in the193 # Change the node numbering (and update the numbering in the 190 194 # triangles) 191 195 192 196 [GAnodes, GAtriangles] = build_local_GA(nodes, triangles) 193 197 194 # extract the local quantities198 # Extract the local quantities 195 199 196 200 quantities ={} … … 202 206 quantities[k][Nf:Nf+Ng] = submesh["ghost_quan"][k] 203 207 204 # change the communication pattern into a form needed by205 # the parallel_adv ection.py file208 # Change the communication pattern into a form needed by 209 # the parallel_adv 206 210 207 211 gcommun = submesh["ghost_commun"] 208 212 fcommun = submesh["full_commun"] 209 [ghost_rec, full_send] = build_local_commun(index, gcommun, fcommun, nproc) 210 211 # clean up before exiting 213 [ghost_rec, full_send] = \ 214 build_local_commun(index, gcommun, fcommun, nproc) 215 216 # Clean up before exiting 212 217 213 218 del(index) 214 219 215 return GAnodes, GAtriangles, GAboundary, quantities, ghost_rec, full_send 220 return GAnodes, GAtriangles, GAboundary, quantities, ghost_rec, \ 221 full_send -
inundation/parallel/build_submesh.py
r2105 r2130 13 13 14 14 import sys 15 from mesh import * 16 from Numeric import * 15 16 from Numeric import zeros, Float, Int, concatenate, \ 17 reshape, arrayrange, take, nonzero 18 19 from mesh import Mesh 20 17 21 18 22 ######################################################### … … 41 45 def submesh_full(nodes, triangles, boundary, triangles_per_proc): 42 46 43 # initialise47 # Initialise 44 48 45 49 tlower = 0 … … 50 54 boundary_list = [] 51 55 submesh = {} 52 tsubnodes = concatenate((reshape(arrayrange(nnodes),(nnodes,1)), nodes), 1) 53 54 # loop over processors 56 node_range = reshape(arrayrange(nnodes),(nnodes,1)) 57 tsubnodes = concatenate((node_range, nodes), 1) 58 59 # Loop over processors 55 60 56 61 for p in range(nproc): 57 62 58 # find triangles on processor p63 # Find triangles on processor p 59 64 60 65 tupper = triangles_per_proc[p]+tlower … … 62 67 triangle_list.append(subtriangles) 63 68 64 # find the boundary edges on processor p69 # Find the boundary edges on processor p 65 70 66 71 subboundary = {} … … 70 75 boundary_list.append(subboundary) 71 76 72 # find nodes in processor p77 # Find nodes in processor p 73 78 74 79 nodemap = zeros(nnodes, 'i') … … 80 85 node_list.append(take(tsubnodes,nonzero(nodemap))) 81 86 82 # move to the next processor87 # Move to the next processor 83 88 84 89 tlower = tupper 85 90 86 # put the results in a dictionary91 # Put the results in a dictionary 87 92 88 93 submesh["full_nodes"] = node_list … … 90 95 submesh["full_boundary"] = boundary_list 91 96 92 # clean up before exiting97 # Clean up before exiting 93 98 94 99 del (nodemap) … … 128 133 ntriangles = len(mesh.triangles) 129 134 130 # find the first layer of boundary triangles135 # Find the first layer of boundary triangles 131 136 132 137 trianglemap = zeros(ntriangles, 'i') … … 145 150 trianglemap[n] = 1 146 151 147 # find the second layer of boundary triangles152 # Find the second layer of boundary triangles 148 153 149 154 for t in range(len(trianglemap)): … … 162 167 trianglemap[n] = 1 163 168 164 # build the triangle list and make note of the vertices169 # Build the triangle list and make note of the vertices 165 170 166 171 nodemap = zeros(ncoord, 'i') … … 179 184 subtriangles = take(tsubtriangles, nonzero(trianglemap)) 180 185 181 # keep a record of the triangle vertices, if they are not already there186 # Keep a record of the triangle vertices, if they are not already there 182 187 183 188 subnodes = [] … … 189 194 subnodes = take(tsubnodes, nonzero(nodemap)) 190 195 191 # clean up before exiting196 # Clean up before exiting 192 197 193 198 del (nodelist) … … 197 202 del (trianglemap) 198 203 199 # return the triangles and vertices sitting on the boundary layer204 # Return the triangles and vertices sitting on the boundary layer 200 205 201 206 return subnodes, subtriangles … … 220 225 def ghost_commun_pattern(subtri, p, tri_per_proc): 221 226 222 # loop over the ghost triangles227 # Loop over the ghost triangles 223 228 224 229 ghost_commun = zeros((len(subtri), 2), Int) … … 227 232 global_no = subtri[i][0] 228 233 229 # find which processor contains the full triangle234 # Find which processor contains the full triangle 230 235 231 236 nproc = len(tri_per_proc) … … 238 243 sum = sum+tri_per_proc[q] 239 244 240 # keep a copy of the neighbour processor number245 # Keep a copy of the neighbour processor number 241 246 242 247 ghost_commun[i] = [global_no, neigh] … … 273 278 full_commun = [] 274 279 275 # loop over the processor280 # Loop over the processor 276 281 277 282 for p in range(nproc): 278 283 279 # loop over the full triangles in the current processor284 # Loop over the full triangles in the current processor 280 285 # and build an empty dictionary 281 286 … … 287 292 tlower = tupper 288 293 289 # loop over the processor again294 # Loop over the processor again 290 295 291 296 for p in range(nproc): 292 297 293 # loop over the ghost triangles in the current processor,298 # Loop over the ghost triangles in the current processor, 294 299 # find which processor contains the corresponding full copy 295 300 # and note that the processor must send updates to this … … 334 339 ghost_commun = [] 335 340 336 # loop overprocessors341 # Loop over the processors 337 342 338 343 for p in range(nproc): 339 344 340 # find the full triangles in this processor345 # Find the full triangles in this processor 341 346 342 347 tupper = triangles_per_proc[p]+tlower 343 348 344 # build the ghost boundary layer 345 346 [subnodes, subtri] = ghost_layer(submesh, mesh, p, tupper, tlower) 349 # Build the ghost boundary layer 350 351 [subnodes, subtri] = \ 352 ghost_layer(submesh, mesh, p, tupper, tlower) 347 353 ghost_triangles.append(subtri) 348 354 ghost_nodes.append(subnodes) 349 355 350 # build the communication pattern for the ghost nodes 351 352 gcommun = ghost_commun_pattern(subtri, p, triangles_per_proc) 356 # Build the communication pattern for the ghost nodes 357 358 gcommun = \ 359 ghost_commun_pattern(subtri, p, triangles_per_proc) 353 360 ghost_commun.append(gcommun) 354 361 355 # move to the next processor362 # Move to the next processor 356 363 357 364 tlower = tupper 358 365 359 # record the ghost layer and communication pattern366 # Record the ghost layer and communication pattern 360 367 361 368 submesh["ghost_nodes"] = ghost_nodes … … 363 370 submesh["ghost_commun"] = ghost_commun 364 371 365 # build the communication pattern for the full triangles372 # Build the communication pattern for the full triangles 366 373 367 374 full_commun = full_commun_pattern(submesh, triangles_per_proc) 368 375 submesh["full_commun"] = full_commun 369 376 370 # return the submesh377 # Return the submesh 371 378 372 379 return submesh … … 397 404 lower = 0 398 405 399 # build an empty dictionary to hold the quantites406 # Build an empty dictionary to hold the quantites 400 407 401 408 submesh["full_quan"] = {} … … 405 412 submesh["ghost_quan"][k] = [] 406 413 407 # loop trough the subdomains414 # Loop trough the subdomains 408 415 409 416 for p in range(nproc): 410 417 upper = lower+triangles_per_proc[p] 411 418 412 # find the global ID of the ghost triangles419 # Find the global ID of the ghost triangles 413 420 414 421 global_id = [] … … 417 424 global_id.append(submesh["ghost_triangles"][p][j][0]) 418 425 419 # use the global ID to extract the quantites information from426 # Use the global ID to extract the quantites information from 420 427 # the full domain 421 428 … … 424 431 submesh["ghost_quan"][k].append(zeros( (M,3) , Float)) 425 432 for j in range(M): 426 submesh["ghost_quan"][k][p][j] = quantities[k][global_id[j]] 433 submesh["ghost_quan"][k][p][j] = \ 434 quantities[k][global_id[j]] 427 435 428 436 lower = upper … … 448 456 triangles_per_proc): 449 457 450 # temporarily build the mesh to find the neighbouring458 # Temporarily build the mesh to find the neighbouring 451 459 # triangles 452 460 453 461 mesh = Mesh(nodes, triangles) 454 462 455 # subdivide into non-overlapping partitions 456 457 submeshf = submesh_full(nodes, triangles, edges, triangles_per_proc) 458 459 # add any extra ghost boundary layer information 463 # Subdivide into non-overlapping partitions 464 465 submeshf = submesh_full(nodes, triangles, edges, \ 466 triangles_per_proc) 467 468 # Add any extra ghost boundary layer information 460 469 461 470 submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc) 462 471 463 # order the quantities information to be the same as the triangle472 # Order the quantities information to be the same as the triangle 464 473 # information 465 474 466 submesh = submesh_quantities(submeshg, quantities, triangles_per_proc) 475 submesh = submesh_quantities(submeshg, quantities, \ 476 triangles_per_proc) 467 477 468 478 return submesh -
inundation/parallel/pmesh_divide.py
r2095 r2130 5 5 # 6 6 # 7 # Th is is only intended as a temporary file, once an8 # automatic grid partitioner has been incorporatedthis9 # file will become redundant.7 # The final routine, pmesh_divide_metis, does automatic 8 # grid partitioning. Once testing has finished on this 9 # routine the others should be removed. 10 10 # 11 11 # Authors: Linda Stals and Matthew Hardy, June 2005 … … 16 16 ######################################################### 17 17 18 18 from os import sep 19 from sys import path 19 20 from math import floor 20 from Numeric import zeros, Float, Int, reshape 21 22 from Numeric import zeros, Float, Int, reshape, argsort 23 21 24 22 25 ######################################################### … … 40 43 def reorder(quantities, tri_index, proc_sum): 41 44 42 # find the number triangles45 # Find the number triangles 43 46 44 47 N = len(tri_index) 45 48 46 # temporary storage area49 # Temporary storage area 47 50 48 51 index = zeros(N, Int) 49 52 q_reord = {} 50 53 51 # find the new ordering of the triangles54 # Find the new ordering of the triangles 52 55 53 56 for i in range(N): … … 56 59 index[i] = proc_sum[bin]+bin_off_set 57 60 58 # reorder each quantity according to the new ordering61 # Reorder each quantity according to the new ordering 59 62 60 63 for k in quantities: … … 87 90 def pmesh_divide(domain, n_x = 1, n_y = 1): 88 91 89 # find the bounding box92 # Find the bounding box 90 93 91 94 x_coord_min = domain.xy_extent[0] … … 94 97 y_coord_max = domain.xy_extent[3] 95 98 96 # find the size of each sub-box99 # Find the size of each sub-box 97 100 98 101 x_div = (x_coord_max-x_coord_min)/n_x 99 102 y_div = (y_coord_max-y_coord_min)/n_y 100 103 101 # initialise the lists104 # Initialise the lists 102 105 103 106 tri_list = [] … … 110 113 tri_list[i] = [] 111 114 112 # subdivide the triangles depending on which sub-box they sit115 # Subdivide the triangles depending on which sub-box they sit 113 116 # in (a triangle sits in the sub-box if its first vectex sits 114 117 # in that sub-box) … … 133 136 tri_index[i] = ([bin, len(tri_list[bin])-1]) 134 137 135 # find the number of triangles per processor and order the138 # Find the number of triangles per processor and order the 136 139 # triangle list so that all of the triangles belonging to 137 140 # processor i are listed before those belonging to processor … … 144 147 triangles.append(t) 145 148 146 # the boundary labels have to changed in accoradance with the149 # The boundary labels have to changed in accoradance with the 147 150 # new triangle ordering, proc_sum and tri_index help with this 148 151 … … 151 154 proc_sum[i+1]=proc_sum[i]+triangles_per_proc[i] 152 155 153 # relabel the boundary elements to fit in with the new triangle156 # Relabel the boundary elements to fit in with the new triangle 154 157 # ordering 155 158 … … 161 164 quantities = reorder(domain.quantities, tri_index, proc_sum) 162 165 163 # extract the node list166 # Extract the node list 164 167 165 168 nodes = domain.coordinates.copy() … … 191 194 def pmesh_divide_steve(domain, n_x = 1, n_y = 1): 192 195 193 # find the bounding box196 # Find the bounding box 194 197 x_coord_min = domain.xy_extent[0] 195 198 x_coord_max = domain.xy_extent[2] … … 198 201 199 202 200 # find the size of each sub-box203 # Find the size of each sub-box 201 204 202 205 x_div = (x_coord_max-x_coord_min)/n_x … … 204 207 205 208 206 # initialise the lists 209 # Initialise the lists 210 207 211 tri_list = [] 208 212 triangles_per_proc = [] … … 214 218 tri_list[i] = [] 215 219 216 # subdivide the triangles depending on which sub-box they sit220 # Subdivide the triangles depending on which sub-box they sit 217 221 # in (a triangle sits in the sub-box if its first vectex sits 218 222 # in that sub-box) … … 221 225 N = domain.number_of_elements 222 226 223 # sort by x coordinate of centroid224 from Numeric import argsort 227 # Sort by x coordinate of centroid 228 225 229 sort_order = argsort(argsort(domain.centroid_coordinates[:,0])) 226 230 … … 237 241 tri_index[i] = ([bin, len(tri_list[bin])-1]) 238 242 239 #print tri_list 240 #print tri_index 241 242 # find the number of triangles per processor and order the 243 # Find the number of triangles per processor and order the 243 244 # triangle list so that all of the triangles belonging to 244 245 # processor i are listed before those belonging to processor … … 252 253 253 254 254 # the boundary labels have to changed in accoradance with the255 # The boundary labels have to changed in accoradance with the 255 256 # new triangle ordering, proc_sum and tri_index help with this 256 257 … … 259 260 proc_sum[i+1]=proc_sum[i]+triangles_per_proc[i] 260 261 261 # relabel the boundary elements to fit in with the new triangle262 # Relabel the boundary elements to fit in with the new triangle 262 263 # ordering 263 264 … … 269 270 quantities = reorder(domain.quantities, tri_index, proc_sum) 270 271 271 # extract the node list 272 # Extract the node list 273 272 274 nodes = domain.coordinates.copy() 273 275 274 275 # convert the triangle datastructure to be an array typ 276 # Convert the triangle datastructure to be an array type, 276 277 # this helps with the communication 277 278 … … 289 290 # Divide the mesh using a call to metis, through pymetis. 290 291 291 from os import sep292 from sys import path293 292 294 293 path.append('..' + sep + 'pymetis') … … 297 296 298 297 def pmesh_divide_metis(domain, n_procs): 299 # initialise the lists 298 299 # Initialise the lists 300 300 # List, indexed by processor of # triangles. 301 301 302 triangles_per_proc = [] 303 302 304 # List of lists, indexed by processor of vertex numbers 305 303 306 tri_list = [] 307 304 308 # List indexed by processor of cumulative total of triangles allocated. 309 305 310 proc_sum = [] 306 311 for i in range(n_procs): … … 310 315 311 316 # Prepare variables for the metis call 317 312 318 n_tri = len(domain.triangles) 313 319 if n_procs != 1: #Because metis chokes on it... … … 317 323 318 324 # The 1 here is for triangular mesh elements. 325 319 326 edgecut, epart, npart = partMeshNodal(n_tri, n_vert, t_list, 1, n_procs) 320 327 del edgecut … … 327 334 # tri_index maps triangle number -> processor, new triangle number 328 335 # (local to the processor) 336 329 337 tri_index = {} 330 338 triangles = [] … … 337 345 # print triangles_per_proc 338 346 339 # order the triangle list so that all of the triangles belonging347 # Order the triangle list so that all of the triangles belonging 340 348 # to processor i are listed before those belonging to processor 341 349 # i+1 … … 345 353 triangles.append(t) 346 354 347 # the boundary labels have to changed in accoradance with the355 # The boundary labels have to changed in accoradance with the 348 356 # new triangle ordering, proc_sum and tri_index help with this 349 357 … … 352 360 proc_sum[i+1]=proc_sum[i]+triangles_per_proc[i] 353 361 354 # relabel the boundary elements to fit in with the new triangle362 # Relabel the boundary elements to fit in with the new triangle 355 363 # ordering 356 364 … … 365 373 triangles_per_proc[0] = n_tri 366 374 triangles = domain.triangles.copy() 375 367 376 # This is essentially the same as a chunk of code from reorder. 377 368 378 quantities = {} 369 379 for k in domain.quantities: … … 372 382 quantities[k][i] = domain.quantities[k].vertex_values[i] 373 383 374 # extract the node list 384 # Extract the node list 385 375 386 nodes = domain.coordinates.copy() 376 # convert the triangle datastructure to be an array type 387 388 # Convert the triangle datastructure to be an array type, 377 389 # this helps with the communication 378 390 -
inundation/parallel/run_parallel_merimbula.py
r2050 r2130 16 16 # *) The (new) files that have been added to manage the 17 17 # grid partitioning are 18 # +) mg2ga.py: read in the test files.19 18 # +) pmesh_divide.py: subdivide a pmesh 20 19 # +) build_submesh.py: build the submeshes on the host -
inundation/parallel/run_parallel_sw_merimbula.py
r2090 r2130 16 16 # *) The (new) files that have been added to manage the 17 17 # grid partitioning are 18 # +) mg2ga.py: read in the test files.19 18 # +) pmesh_divide.py: subdivide a pmesh 20 19 # +) build_submesh.py: build the submeshes on the host -
inundation/parallel/run_parallel_sw_merimbula_metis.py
r2108 r2130 19 19 # *) The (new) files that have been added to manage the 20 20 # grid partitioning are 21 # +) mg2ga.py: read in the test files.22 21 # +) pmesh_divide.py: subdivide a pmesh 23 22 # +) build_submesh.py: build the submeshes on the host -
inundation/parallel/run_parallel_sw_rectangle.py
r1697 r2130 16 16 # *) The (new) files that have been added to manage the 17 17 # grid partitioning are 18 # +) mg2ga.py: read in the test files.19 18 # +) pmesh_divide.py: subdivide a pmesh 20 19 # +) build_submesh.py: build the submeshes on the host
Note: See TracChangeset
for help on using the changeset viewer.