source: inundation/parallel/run_parallel_sw_merimbula_test.py @ 2906

Last change on this file since 2906 was 2906, checked in by linda, 18 years ago

Made correction to the parallel report

File size: 7.1 KB
Line 
1#!/usr/bin/env python
2###
3#########################################################
4#
5#  Main file for parallel mesh testing.
6#
7#  This is a modification of the run_parallel_advection.py
8# file.
9#
10#
11# *) The (new) files that have been added to manage the
12# grid partitioning are
13#    +) pmesh_divide_metis.py: subdivide a pmesh
14#    +) build_submesh.py: build the submeshes on the host
15# processor.
16#    +) build_local.py: build the GA mesh datastructure
17# on each processor.
18#    +) build_commun.py: handle the communication between
19# the host and processors
20#
21# *) Things still to do:
22#    +) Overlap the communication and computation: The
23# communication routines in build_commun.py should be
24# interdispersed in the build_submesh.py and build_local.py
25# files. This will overlap the communication and
26# computation and will be far more efficient. This should
27# be done after more testing and there more confidence in
28# the subpartioning.
29#    +) Much more testing especially with large numbers of
30# processors.
31#  Authors: Linda Stals, Steve Roberts and Matthew Hardy,
32# June 2005
33#
34#
35#
36#########################################################
37import sys
38import pypar    # The Python-MPI interface
39import time
40
41
42from os import sep
43sys.path.append('..'+sep+'pyvolution')
44
45# Numeric arrays
46
47from Numeric import array, zeros, Float
48
49# Print debugging information
50
51from print_stats import print_test_stats, build_full_flag
52
53# pmesh
54
55from shallow_water import Domain
56from parallel_shallow_water import Parallel_Domain
57from pmesh2domain import pmesh_to_domain_instance
58
59# Reuse previous mesh import
60
61from caching import cache
62
63# Mesh partition routines
64
65from pmesh_divide import pmesh_divide_metis
66from build_submesh import build_submesh, extract_hostmesh
67from build_local   import build_local_mesh
68from build_commun  import send_submesh, rec_submesh
69
70###############################
71# Read in processor information
72###############################
73
74numprocs = pypar.size()
75myid = pypar.rank()
76processor_name = pypar.Get_processor_name()
77
78############################
79# Set the initial conditions
80############################
81
82rect = zeros( 4, Float) # Buffer for results
83
84class Set_Stage:
85    """Set an initial condition with constant water height, for x<x0
86    """
87
88    def __init__(self, x0=0.25, x1=0.5, h=1.0):
89        self.x0 = x0
90        self.x1 = x1
91        self.= h
92
93    def __call__(self, x, y):
94        return self.h*((x>self.x0)&(x<self.x1))
95
96#######################
97# Partition the domain
98#######################
99
100if myid == 0:
101
102    # Read in the test files
103
104    filename = 'test-100.tsh'
105#    filename = 'merimbula_10785_1.tsh'
106
107    # Build the whole domain
108   
109    domain_full = pmesh_to_domain_instance(filename, Domain)
110
111#    domain_full = cache(pmesh_to_domain_instance,
112#               (filename, Domain),
113#              dependencies = [filename])
114
115    rect = array(domain_full.xy_extent, Float)
116
117    # Initialise the wave
118
119    domain_full.set_quantity('stage', Set_Stage(200.0,300.0,1.0))
120#    domain_full.set_quantity('stage', Set_Stage(756000.0,756500.0,2.0))
121#    domain_full.set_quantity('stage', Set_Stage(756000.0,756500.0,0.0))
122
123    # Subdivide the domain
124
125    # Note the different arguments compared with pmesh_divide,
126    # pmesh_divide_steve etc.
127   
128    nodes, triangles, boundary, triangles_per_proc, quantities = \
129         pmesh_divide_metis(domain_full, numprocs)
130
131    print triangles_per_proc
132   
133    rect = array(domain_full.xy_extent, Float)
134
135    submesh = build_submesh(nodes, triangles, boundary,\
136                            quantities, triangles_per_proc)
137
138    # Send the mesh partition to the appropriate processor
139
140    for p in range(1, numprocs):
141      send_submesh(submesh, triangles_per_proc, p)
142
143    # Build the local mesh for processor 0
144
145    hostmesh = extract_hostmesh(submesh)
146    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \
147             build_local_mesh(hostmesh, 0, triangles_per_proc[0], numprocs)
148
149# Read in the mesh partition that belongs to this
150# processor (note that the information is in the
151# correct form for the GA data structure
152
153else:
154    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict \
155            = rec_submesh(0)
156
157
158###########################################
159# Start the computations on each subpartion
160###########################################
161
162#if myid == 0:
163#    print 'ghost'
164#    print ghost_recv_dict
165#processor_name
166#if myid == 0:
167#    print 'full'
168#    print full_send_dict
169
170# The visualiser needs to know the size of the whole domain
171
172pypar.broadcast(rect,0)
173
174domain = Parallel_Domain(points, vertices, boundary,
175                         full_send_dict  = full_send_dict,
176                         ghost_recv_dict = ghost_recv_dict)
177
178# Make a note of which triangles are full and which are ghost
179
180tri_full_flag = build_full_flag(domain, ghost_recv_dict)
181
182try:
183    domain.initialise_visualiser(rect=rect)
184    #domain.visualiser.coloring['stage'] = True
185    domain.visualiser.scale_z['stage'] = 0.2
186    domain.visualiser.scale_z['elevation'] = 0.05
187except:
188    print 'No visualiser'
189
190
191domain.default_order = 1
192
193#Boundaries
194from parallel_shallow_water import Transmissive_boundary, Reflective_boundary
195
196T = Transmissive_boundary(domain)
197R = Reflective_boundary(domain)
198domain.set_boundary( {'outflow': R, 'inflow': R, 'inner':R, 'exterior': R, 'open':R, 'ghost':None} )
199
200
201domain.set_quantity('stage', quantities['stage'])
202domain.set_quantity('elevation', quantities['elevation'])
203
204domain.store = False
205#domain.filename = 'merimbula-%d' %domain.processor
206
207#---------
208# Evolution
209t0 = time.time()
210
211print 'Processor %d on %s: No of elements %d'%(domain.processor,processor_name,domain.number_of_elements)
212yieldstep = 0.05
213finaltime = 5.0
214
215yieldstep = 1
216finaltime = 90
217
218#yieldstep = 1
219#finaltime = 1
220#processor_name
221#for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
222#    if myid == 0:
223#        domain.write_time()
224        #print 'Processor %d, Integral of stage %d'%\
225        #       (domain.processor,domain.quantities['stage'].get_integral())
226        #    print_test_stats(domain, tri_full_flag)
227
228
229# Profiling
230#import profile
231#profiler = profile.Profile()
232#result.dump_stats("profile." + str(numprocs) + "." + str(myid) + ".dat")
233
234#New hotshot profiling
235import hotshot
236profiler = hotshot.Profile("hotshot." + str(numprocs) + "." + str(myid) + ".prof")
237s = '''for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
238  if myid == 0:
239    domain.write_time()
240  print_test_stats(domain, tri_full_flag)
241
242'''
243result = profiler.runctx(s, globals(), locals())
244profiler.close()
245
246#print 'P%d: That took %.2f seconds' %(myid, time.time()-t0)
247#print 'P%d: Communication time %.2f seconds' %(myid, domain.communication_time)
248#print 'P%d: Reduction Communication time %.2f seconds' %(myid, domain.communication_reduce_time)
249#print 'P%d: Broadcast time %.2f seconds' %(myid, domain.communication_broadcast_time)
250
251
252
253if myid == 0:
254    print 'That took %.2f seconds' %(time.time()-t0)
255    print 'Communication time %.2f seconds'%domain.communication_time
256    print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time
257    print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time
Note: See TracBrowser for help on using the repository browser.