Changeset 3585


Ignore:
Timestamp:
Sep 14, 2006, 9:24:05 AM (18 years ago)
Author:
ole
Message:

Work on parallel API

Location:
anuga_work/production/wollongong_2006
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • anuga_work/production/wollongong_2006/parallel_api.py

    r3584 r3585  
    11"""Trying to lump parallel stuff into simpler interface
    22
     3
    34"""
     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_mesh(domain):
     28
     29    numprocs = pypar.size()
     30
     31   
     32    # Subdivide the mesh
     33    print 'Subdivide mesh'
     34    nodes, triangles, boundary, triangles_per_proc, quantities = \
     35           pmesh_divide_metis(domain, numprocs)
     36
     37    # Build the mesh that should be assigned to each processor,
     38    # this includes ghost nodes and the communicaiton pattern
     39    print 'Build submeshes'   
     40    submesh = build_submesh(nodes, triangles, boundary,\
     41                            quantities, triangles_per_proc)
     42
     43    # Send the mesh partition to the appropriate processor
     44    print 'Distribute submeshes'       
     45    for p in range(1, numprocs):
     46      send_submesh(submesh, triangles_per_proc, p)
     47
     48    # Build the local mesh for processor 0
     49    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \
     50              extract_hostmesh(submesh, triangles_per_proc)
     51
     52    # Return stuff
     53    return points, vertices, boundary, quantities, \
     54           ghost_recv_dict, full_send_dict
     55   
     56
     57
     58
  • anuga_work/production/wollongong_2006/run_flagstaff.py

    r3584 r3585  
    5454
    5555
    56 #------------------------------------------------------------------------------
    57 # Preparation of topographic data
    58 #
    59 # Convert ASC 2 DEM 2 PTS using source data and store result in source data
    60 #------------------------------------------------------------------------------
    61 
    62 max_area = project.base_resolution
    6356if myid == 0:
    6457   
     
    7265    print 'Generate mesh'
    7366    # Generate basic mesh
     67    max_area = project.base_resolution
    7468    mesh = create_mesh_from_regions(project.bounding_polygon,
    7569                                    boundary_tags=project.boundary_tags,
  • anuga_work/production/wollongong_2006/run_flagstaff_parallel_api.py

    r3584 r3585  
    3131from anuga.pmesh.mesh import importUngenerateFile, Segment
    3232
     33from anuga.caching import cache
     34
    3335# Parallelism
    34 import pypar   # The Python-MPI interface
    35 from anuga_parallel.pmesh_divide  import pmesh_divide_metis
    36 from anuga_parallel.build_submesh import build_submesh
    37 from anuga_parallel.build_local   import build_local_mesh
    38 from anuga_parallel.build_commun  import send_submesh, rec_submesh, extract_hostmesh
    39 from anuga_parallel.parallel_shallow_water import Parallel_Domain
    40 
     36from parallel_api import *
    4137
    4238# Application specific imports
    4339import project
    4440
    45 
    46 #------------------------------------------------------------------------------
    47 # Read in processor information
    48 #------------------------------------------------------------------------------
    49 
    50 numprocs = pypar.size()
    51 myid = pypar.rank()
    52 processor_name = pypar.Get_processor_name()
    53 print 'I am processor %d of %d on node %s' %(myid, numprocs, processor_name)
    54 
    55 
    56 #------------------------------------------------------------------------------
    57 # Preparation of topographic data
    58 #
    59 # Convert ASC 2 DEM 2 PTS using source data and store result in source data
    60 #------------------------------------------------------------------------------
    61 
    62 max_area = project.base_resolution
     41# Sequential part
    6342if myid == 0:
    6443   
     
    6948    #--------------------------------------------------------------------------
    7049
    71 
    7250    print 'Generate mesh'
    7351    # Generate basic mesh
    74     mesh = create_mesh_from_regions(project.bounding_polygon,
    75                                     boundary_tags=project.boundary_tags,
    76                                     maximum_triangle_area=max_area,
    77                                     interior_regions=project.interior_regions)
     52    max_area = project.base_resolution
     53
     54   
     55    mesh = cache(create_mesh_from_regions,
     56                 project.bounding_polygon,
     57                 {'boundary_tags': project.boundary_tags,
     58                  'maximum_triangle_area':max_area,
     59                  'interior_regions': project.interior_regions},
     60                 verbose=True)
    7861   
    7962    # Add buildings that will bind to a Reflective boundary
     
    9477    print domain.statistics()
    9578
     79    domain.set_name(project.basename)
     80    domain.set_datadir(project.outputdir)   
     81
     82
     83    #------------------------------------------------------------------------------
     84    # Setup initial conditions
     85    #------------------------------------------------------------------------------
     86    domain.set_quantity('stage', project.initial_sealevel)
     87    domain.set_quantity('friction', 0.03)   
    9688    domain.set_quantity('elevation',
    9789                        filename=project.demname + '.pts',
    9890                        use_cache=True,
    99                         verbose=True)   
     91                        verbose=True)
    10092
    10193
    102     # Subdivide the mesh
    103     print 'Subdivide mesh'
    104     nodes, triangles, boundary, triangles_per_proc, quantities = \
    105            pmesh_divide_metis(domain, numprocs)
    10694
    107     # Build the mesh that should be assigned to each processor,
    108     # this includes ghost nodes and the communicaiton pattern
    109     print 'Build submeshes'   
    110     submesh = build_submesh(nodes, triangles, boundary,\
    111                             quantities, triangles_per_proc)
    11295
    113     # Send the mesh partition to the appropriate processor
    114     print 'Distribute submeshes'       
    115     for p in range(1, numprocs):
    116       send_submesh(submesh, triangles_per_proc, p)
     96#---------------
     97# Parallel stuff
     98#---------------
    11799
    118     # Build the local mesh for processor 0
    119     points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \
    120               extract_hostmesh(submesh, triangles_per_proc)
     100if myid == 0:
     101    # Distribute the domain
     102    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict,\
     103            = distribute_mesh(domain)
    121104
     105
     106    domain_name = domain.get_name()
     107    domain_dir = domain.get_datadir()
     108
     109    for p in range(pypar.size()):
     110        pypar.send((domain_name, domain_dir), p)
     111   
    122112    print 'Communication done'       
    123113   
     
    127117    # correct form for the GA data structure)
    128118
    129     points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict \
     119    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict, \
    130120            = rec_submesh(0)
    131121
     122    print 'P %d receiving names' %myid
     123    X = pypar.receive(0)
     124    print X
     125    (domain_name, domain_dir) = X
    132126
    133127
     
    138132
    139133
     134
    140135# Build the domain for this processor
    141136domain = Parallel_Domain(points, vertices, boundary,
     
    143138                         ghost_recv_dict = ghost_recv_dict)
    144139
    145 # Name etc currently has to be set here as they are not transferred from the
     140# Name and dir, etc currently has to be set here as they are not transferred from the
    146141# original domain
    147 domain.set_name(project.basename)
    148 domain.set_datadir(project.outputdir)
     142domain.set_name(domain_name)
     143domain.set_datadir(domain_dir)
    149144
    150145
     
    152147# Setup initial conditions
    153148#------------------------------------------------------------------------------
     149for q in quantities:
     150    domain.set_quantity(q, quantities[q]) # Distribute elevation   
    154151
    155152
    156 domain.set_quantity('elevation', quantities['elevation']) # Distribute elevation
    157 domain.set_quantity('stage', project.initial_sealevel)
    158 domain.set_quantity('friction', 0.03)
    159 
    160 #
    161 # FIXME (Ole): This one segfaults which is bad, because set_quantity is
    162 # time consuming and should be done here rather than on processor 0
    163 # It did not segfault today 2 Aug 2006 !!!
    164 # But values are zero ??....
    165 #
    166 #domain.set_quantity('elevation',
    167 #                    filename=project.demname + '.pts',
    168 #                    use_cache=False,
    169 #                    verbose=True)
     153#domain.set_quantity('elevation', quantities['elevation']) # Distribute elevation
     154#domain.set_quantity('stage', project.initial_sealevel)
     155#domain.set_quantity('friction', 0.03)
    170156
    171157
  • anuga_work/production/wollongong_2006/run_flagstaff_sequential.py

    r3584 r3585  
    3939
    4040
    41 #------------------------------------------------------------------------------
    42 # Preparation of topographic data
    43 #
    44 # Convert ASC 2 DEM 2 PTS using source data and store result in source data
    45 #------------------------------------------------------------------------------
    4641
    47 max_area = project.base_resolution
    4842
    4943   
     
    5650
    5751print 'Generate mesh'
     52max_area = project.base_resolution
    5853mesh = create_mesh_from_regions(project.bounding_polygon,
    5954                                boundary_tags=project.boundary_tags,
Note: See TracChangeset for help on using the changeset viewer.