Changeset 3105


Ignore:
Timestamp:
Jun 6, 2006, 4:41:39 PM (18 years ago)
Author:
ole
Message:

Attempt at parallelising flagstaff

Location:
production/wollongong_2006
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • production/wollongong_2006/project.py

    r3081 r3105  
    44import sys
    55from os import sep as s, environ
     6from os.path import expanduser
    67
    78# Making assumptions about the location of scenario data
     
    1819   
    1920# Derive subdirectories and filenames
    20 home = environ['INUNDATIONHOME']     #Sandpit's parent dir
    21 #if sys.platform == 'win32':
    22 #    home = environ['INUNDATIONHOME']     #Sandpit's parent dir
    23 #else:   
    24 #    home = expanduser('~')
     21try:
     22    home = environ['INUNDATIONHOME']
     23except Exception, e:
     24    print 'Environment variable INUNDATIONHOME was not found: %s' %e
     25    home = expanduser('~')
     26
    2527
    2628meshdir = home+s+scenario_dirname+s+'meshes'+s
  • production/wollongong_2006/run_flagstaff.py

    r3101 r3105  
    2121from os import sep
    2222from os.path import dirname, basename
     23from Numeric import zeros, Float
    2324
    2425# Related major packages
     
    3132from pmesh.mesh import importUngenerateFile, Segment
    3233
     34# Parallelism
     35from pypar_dist import pypar   # The Python-MPI interface
     36from parallel.pmesh_divide import pmesh_divide_metis
     37from parallel.build_submesh import build_submesh
     38from parallel.build_local   import build_local_mesh
     39from parallel.build_commun  import send_submesh, rec_submesh, extract_hostmesh
     40from parallel.parallel_shallow_water import Parallel_Domain
     41
     42
    3343# Application specific imports
    3444import project
     45
     46
     47#------------------------------------------------------------------------------
     48# Read in processor information
     49#------------------------------------------------------------------------------
     50
     51numprocs = pypar.size()
     52myid = pypar.rank()
     53processor_name = pypar.Get_processor_name()
     54print 'I am processor %d of %d on node %s' %(myid, numprocs, processor_name)
     55
     56bounding_rectangle = zeros(4, Float) # Buffer for results
    3557
    3658
     
    4163#------------------------------------------------------------------------------
    4264
    43 # Create DEM from asc data
    44 convert_dem_from_ascii2netcdf(project.demname, use_cache=True, verbose=True)
    45 
    46 # Create pts file from DEM
    47 dem2pts(project.demname,
    48         easting_min=project.xllcorner,
    49         easting_max=project.xurcorner,
    50         northing_min=project.yllcorner,
    51         northing_max= project.yurcorner,
    52         use_cache=True,
    53         verbose=True)
    54 
    55 
    56 #------------------------------------------------------------------------------
    57 # Create the triangular mesh based on overall clipping polygon with a tagged
    58 # boundary and interior regions defined in project.py along with
    59 # resolutions (maximal area of per triangle) for each polygon
    60 #------------------------------------------------------------------------------
    61 
    62 # Generate basic mesh
    63 mesh = create_mesh_from_regions(project.bounding_polygon,
    64                                 boundary_tags=project.boundary_tags,
    65                                 maximum_triangle_area=project.base_resolution,
    66                                 interior_regions=project.interior_regions)
    67 
    68 # Add buildings
    69 # This should bind to a Reflective boundary
    70 mesh.import_ungenerate_file(project.buildings_filename,tag='wall')
    71 
    72 # Generate and write mesh to file
    73 mesh.generate_mesh(maximum_triangle_area=project.base_resolution,
    74                    verbose=True)
    75 
    76 mesh.export_mesh_file(project.mesh_filename)
    77 
    78 
    79 #------------------------------------------------------------------------------
    80 # Setup computational domain
    81 #------------------------------------------------------------------------------
    82 
    83 domain = Domain(project.mesh_filename, use_cache = False, verbose = True)
    84 print domain.statistics()
    85 
    86 domain.set_name(project.basename)
    87 domain.set_datadir(project.outputdir)
    88 domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
     65
     66max_area = project.base_resolution
     67if myid == 0:
     68    # Create DEM from asc data
     69    convert_dem_from_ascii2netcdf(project.demname,
     70                                  use_cache=True,
     71                                  verbose=True)
     72
     73    # Create pts file from DEM
     74    dem2pts(project.demname,
     75            easting_min=project.xllcorner,
     76            easting_max=project.xurcorner,
     77            northing_min=project.yllcorner,
     78            northing_max= project.yurcorner,
     79            use_cache=True,
     80            verbose=True)
     81
     82
     83    #--------------------------------------------------------------------------
     84    # Create the triangular mesh based on overall clipping polygon with a
     85    # tagged boundary and interior regions defined in project.py along with
     86    # resolutions (maximal area of per triangle) for each polygon
     87    #--------------------------------------------------------------------------
     88
     89
     90    ## Generate basic mesh
     91    mesh = create_mesh_from_regions(project.bounding_polygon,
     92                                    boundary_tags=project.boundary_tags,
     93                                    maximum_triangle_area=max_area,
     94                                    interior_regions=project.interior_regions)
     95   
     96    ## Add buildings
     97    #dict = importUngenerateFile(project.buildings_filename)
     98    #Segment.set_default_tag('wall') # This should bind to a Reflective boundary
     99    #mesh.addVertsSegs(dict)
     100
     101 
     102    # Add buildings
     103    # This should bind to a Reflective boundary
     104    mesh.import_ungenerate_file(project.buildings_filename, tag='wall')
     105
     106    # Generate and write mesh to file
     107    mesh.generate_mesh(maximum_triangle_area=max_area,
     108                       verbose=True)
     109    mesh.export_mesh_file(project.mesh_filename)
     110
     111
     112    #--------------------------------------------------------------------------
     113    # Setup computational domain
     114    #--------------------------------------------------------------------------
     115
     116    domain = Domain(project.mesh_filename, use_cache = False, verbose = True)
     117    print domain.statistics()
     118
     119    domain.set_name(project.basename)
     120    domain.set_datadir(project.outputdir)
     121    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
     122
     123    bounding_rectangle[:] = domain.get_extent(absolute=True)
     124
     125    # Subdivide the mesh
     126    print 'Subdivide mesh'
     127    nodes, triangles, boundary, triangles_per_proc, quantities = \
     128           pmesh_divide_metis(domain, numprocs)
     129
     130    # Build the mesh that should be assigned to each processor,
     131    # this includes ghost nodes and the communicaiton pattern
     132    print 'Build submeshes'   
     133    submesh = build_submesh(nodes, triangles, boundary,\
     134                            quantities, triangles_per_proc)
     135
     136    # Send the mesh partition to the appropriate processor
     137    print 'Distribute submeshes'       
     138    for p in range(1, numprocs):
     139      send_submesh(submesh, triangles_per_proc, p)
     140
     141    # Build the local mesh for processor 0
     142    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \
     143              extract_hostmesh(submesh, triangles_per_proc)
     144
     145    print 'Communication done'       
     146   
     147else:
     148    # Read in the mesh partition that belongs to this
     149    # processor (note that the information is in the
     150    # correct form for the GA data structure)
     151
     152    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict \
     153            = rec_submesh(0)
     154
     155
     156
     157
     158#------------------------------------------------------------------------------
     159# Start the computations on each subpartion
     160#------------------------------------------------------------------------------
     161
     162
     163pypar.broadcast(bounding_rectangle, 0)
     164
     165# Build the domain for this processor
     166domain = Parallel_Domain(points, vertices, boundary,
     167                         full_send_dict  = full_send_dict,
     168                         ghost_recv_dict = ghost_recv_dict)
    89169
    90170
     
    113193                     'side': D,
    114194                     'wall': R,
    115                      'ocean': W})
    116 
    117 
    118                              
     195                     'ocean': W,
     196                     'ghost': None})
     197
     198                           
    119199#------------------------------------------------------------------------------
    120200# Evolve system through time
     
    122202
    123203t0 = time.time()
    124 for t in domain.evolve(yieldstep = 1, finaltime = 1200):
    125     domain.write_time()
    126     domain.write_boundary_statistics(tags = 'ocean')     
     204for t in domain.evolve(yieldstep = 1, finaltime = 1200):
     205    if myid == 0:
     206        domain.write_time()
     207        #domain.write_boundary_statistics(tags = 'ocean')     
    127208 
    128 print 'That took %.2f seconds' %(time.time()-t0)
     209
     210if myid == 0:
     211    print 'That took %.2f seconds' %(time.time()-t0)
     212    print 'Communication time %.2f seconds'%domain.communication_time
     213    print 'Reduction Communication time %.2f seconds'\
     214          %domain.communication_reduce_time
     215    print 'Broadcast time %.2f seconds'\
     216          %domain.communication_broadcast_time
     217
     218pypar.finalize()
Note: See TracChangeset for help on using the changeset viewer.