Changeset 2984


Ignore:
Timestamp:
May 26, 2006, 3:15:44 PM (18 years ago)
Author:
ole
Message:

Parallel version of stochastic study

Location:
development/stochastic_study
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • development/stochastic_study/project.py

    r2979 r2984  
    2727
    2828# Stats (Suresh ?)
    29 number_of_realisations = 2
     29number_of_realisations = 16000
    3030#std_dev = 0.0026  #Range is 26.035 cm
    3131#std_dev = 0.0013  #Range is 26.035 cm
  • development/stochastic_study/run_model.py

    r2979 r2984  
    3232from pyvolution.util import file_function
    3333from caching.caching import cache
     34import pypar
    3435
    3536# Application specific imports
     
    3738
    3839
     40#-----------------------------------------------------------------------------
     41# Read in processor information
     42#-----------------------------------------------------------------------------
     43
     44myid = pypar.rank()
     45numprocs = pypar.size()
     46processor_name = pypar.Get_processor_name()
     47
     48print 'I am process %d of %d running on %s' %(myid, numprocs, processor_name)
    3949
    4050
     
    4252# Setup computational domain
    4353#-----------------------------------------------------------------------------
    44 print 'Creating domain from', project.mesh_filename
     54#print 'Creating domain from', project.mesh_filename
    4555
    4656domain = Domain(project.working_dir + project.mesh_filename,
    4757                use_cache=False,
    48                 verbose=True)               
     58                verbose=False)               
    4959               
    5060
    51 print 'Number of triangles = ', len(domain)
    52 print domain.statistics()
     61#print 'Number of triangles = ', len(domain)
     62#print domain.statistics()
    5363
    5464
     
    6171#------------------------------------------------------------------------------
    6272
    63 function = file_function(project.boundary_filename, domain, verbose = True)
     73function = file_function(project.boundary_filename, domain, verbose = False)
    6474Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function) #Input wave
    6575Br = Reflective_boundary(domain) #Wall
     
    8494for filename in os.listdir(project.working_dir):
    8595    if filename.startswith(project.basename) and filename.endswith('.pck'):
    86         print 'Reading %s' %filename
     96        #print 'Reading %s' %filename
    8797        fid = open(filename)
    8898        V = cPickle.load(fid)
     
    91101        # For each column (each realisation)
    92102        for i in range(V.shape[1]):
    93             if i == 0:
    94                 name = project.basename + '_original'
    95             else:
    96                 name = project.basename               
    97             domain.set_name(name)                     #Output name
    98             domain.set_quantity('elevation', V[:,i])  #Assign bathymetry
    99             domain.set_time(0.0)                      #Reset time
    100103
    101             #---------------------------------------------------
    102             # Evolve system through time
    103             #---------------------------------------------------
    104             print 'Running realisation %d of %d in block %s'\
    105                   %(i, V.shape[1], filename)
    106             print 'Z Range:', min(V[:,i]), max(V[:,i])
     104            # Distribute work in round-robin fashion
     105            if i%numprocs == myid:
     106               
     107                name = project.basename + '_P%d' %myid   
     108                domain.set_name(name)                     #Output name
     109                domain.set_quantity('elevation', V[:,i])  #Assign bathymetry
     110                domain.set_time(0.0)                      #Reset time
    107111
    108             t0 = time.time()
    109             for t in domain.evolve(yieldstep = timestep,
    110                                    finaltime = finaltime):
    111                 domain.write_time()
    112                
     112                #---------------------------------------------------
     113                # Evolve system through time
     114                #---------------------------------------------------
     115                print 'P%d: Running realisation %d of %d in block %s'\
     116                      %(myid, realisation, V.shape[1], filename)
     117
     118                t0 = time.time()
     119                for t in domain.evolve(yieldstep = timestep,
     120                                       finaltime = finaltime):
     121                    pass
     122                    #domain.write_time()
     123                   
    113124       
    114             print 'Simulation of realisation %d took %.2f seconds'\
    115                   %(realisation, time.time()-t0)
     125                print 'P%d: Simulation of realisation %d took %.2f seconds'\
     126                      %(myid, realisation, time.time()-t0)
    116127
    117128
    118129
    119130
    120             #---------------------------------------------------
    121             # Now extract the 3 timeseries (Ch 5-7-9) and store them
    122             # in three files for this realisation
    123             f = file_function(project.working_dir + domain.filename + '.sww',
    124                               quantities='stage',
    125                               interpolation_points=project.gauges,
    126                               verbose=True)
     131                #---------------------------------------------------
     132                # Now extract the 3 timeseries (Ch 5-7-9) and store them
     133                # in three files for this realisation
     134                f = file_function(project.working_dir + domain.filename + '.sww',
     135                                  quantities='stage',
     136                                  interpolation_points=project.gauges,
     137                                  verbose=False)
    127138
    128139
    129             simulation_name = project.working_dir + \
    130                               domain.filename + '_realisation_%d' %realisation
     140                simulation_name = project.working_dir + \
     141                                  project.basename + '_realisation_%d' %realisation
    131142
    132             for k, name in enumerate(project.gauge_names):
    133                 fid = open(simulation_name + '_' + name + '.txt', 'w')
    134                 for t in f.get_time():
    135                     #For all precomputed timesteps
    136                     val = f(t, point_id = k)[0]
    137                     fid.write('%f %f\n' %(t, val))
     143                for k, name in enumerate(project.gauge_names):
     144                    fid = open(simulation_name + '_' + name + '.txt', 'w')
     145                    for t in f.get_time():
     146                        #For all precomputed timesteps
     147                        val = f(t, point_id = k)[0]
     148                        fid.write('%f %f\n' %(t, val))
    138149
    139                 fid.close()
     150                    fid.close()
    140151
    141152                   
    142153
    143154            realisation += 1           
     155
     156
     157pypar.finalize()
Note: See TracChangeset for help on using the changeset viewer.