- Timestamp:
- Jun 30, 2005, 5:41:44 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/parallel/parallel_shallow_water.py
r1558 r1563 33 33 34 34 def __init__(self, coordinates, vertices, boundary = None, 35 full_send_dict = None, ghost_recv_dict = None, 36 velocity = None): 35 full_send_dict = None, ghost_recv_dict = None): 37 36 38 37 self.processor = pypar.rank() 39 38 self.numproc = pypar.size() 40 #print 'Processor %d'%self.processor 41 #velocity = [(self.processor+1),0.0] 42 43 #print 'velocity',velocity 44 45 Advection_Domain.__init__(self, coordinates, vertices, boundary, 46 velocity = velocity) 39 40 Shallow_Water_Domain.__init__(self, coordinates, vertices, boundary) 47 41 48 42 N = self.number_of_elements … … 51 45 self.numproc = pypar.size() 52 46 47 # Setup Communication Buffers 48 self.nsys = 3 49 for key in full_send_dict: 50 buffer_shape = full_send_dict[key][0].shape[0] 51 full_send_dict[key].append(zeros( (buffer_shape,self.nsys) ,Float)) 52 53 54 for key in ghost_recv_dict: 55 buffer_shape = ghost_recv_dict[key][0].shape[0] 56 ghost_recv_dict[key].append(zeros( (buffer_shape,self.nsys) ,Float)) 57 53 58 self.full_send_dict = full_send_dict 54 # for key in self.full_send_dict:55 # self.full_send_dict[key][0] = array(self.full_send_dict[key][0],Int)56 # self.full_send_dict[key][2] = array(self.full_send_dict[key][2],Float)57 58 59 59 self.ghost_recv_dict = ghost_recv_dict 60 # for key in self.ghost_recv_dict: 61 # self.ghost_recv_dict[key][0] = array(self.ghost_recv_dict[key][0],Int) 62 # self.ghost_recv_dict[key][2] = array(self.ghost_recv_dict[key][2],Float) 60 63 61 64 62 self.communication_time = 0.0 65 63 self.communication_reduce_time = 0.0 66 64 67 #print self.full_send_dict 68 #print self.ghost_recv_dict 65 69 66 70 67 def check_integrity(self): 71 Advection_Domain.check_integrity(self)68 Shallow_Water_Domain.check_integrity(self) 72 69 73 70 msg = 'Will need to check global and local numbering' 74 71 assert self.conserved_quantities[0] == 'stage', msg 72 assert self.conserved_quantities[1] == 'xmomentum', msg 73 assert self.conserved_quantities[2] == 'ymomentum', msg 75 74 76 75 … … 79 78 80 79 # Calculate local timestep 81 Advection_Domain.update_timestep(self, yieldstep, finaltime)80 Shallow_Water_Domain.update_timestep(self, yieldstep, finaltime) 82 81 83 82 import time … … 101 100 self.communication_reduce_time += time.time()-t0 102 101 102 103 103 def update_ghosts(self): 104 105 self.update_ghosts_second()106 107 108 def update_ghosts_second(self):109 104 110 105 # We must send the information from the full cells and … … 119 114 t0 = time.time() 120 115 121 stage_cv = self.quantities['stage'].centroid_values 116 stage_cv = self.quantities['stage'].centroid_values 117 xmomentum_cv = self.quantities['xmomentum'].centroid_values 118 ymomentum_cv = self.quantities['ymomentum'].centroid_values 122 119 123 120 # update of non-local ghost cells … … 127 124 for send_proc in self.full_send_dict: 128 125 if send_proc != iproc: 129 # LINDA:130 # now store full as local id, global_id, value131 126 132 127 Idf = self.full_send_dict[send_proc][0] 133 128 Xout = self.full_send_dict[send_proc][2] 134 129 135 N = len(Xout) 136 137 138 #============================== 139 # Original python Code 130 N = len(Idf) 131 140 132 for i in range(N): 141 Xout[i] = stage_cv[Idf[i]] 142 #============================== 143 144 145 #LINDA: 146 #could not get the code below to work, kept on complaining about error: no match for call to `(py::list) (int&)' 147 148 code1 = """ 149 for (int i=0; i<N ; i++){ 150 Xout(i) = stage_cv(Idf(i)); 151 } 152 """ 153 #weave.inline(code1, ['stage_cv','Idf','Xout','N'], 154 # type_converters = converters.blitz, compiler='gcc'); 133 Xout[i,0] = stage_cv[Idf[i]] 134 Xout[i,1] = xmomentum_cv[Idf[i]] 135 Xout[i,2] = ymomentum_cv[Idf[i]] 136 155 137 156 138 pypar.send(Xout,send_proc) … … 161 143 if self.ghost_recv_dict.has_key(iproc): 162 144 163 # LINDA:164 # now store ghost as local id, global id, value165 145 Idg = self.ghost_recv_dict[iproc][0] 166 146 X = self.ghost_recv_dict[iproc][2] 167 147 168 148 X = pypar.receive(iproc,X) 169 N = len(X) 170 171 #LINDA: had problems getting C code to work 172 173 174 #=========================== 175 # Origin Python Code 149 N = len(Idg) 150 176 151 for i in range(N): 177 stage_cv[Idg[i]] = X[i] 178 #=========================== 179 180 181 code2 = """ 182 for (int i=0; i<N; i++){ 183 stage_cv(Idg(i)) = X(i); 184 } 185 """ 186 # weave.inline(code2, ['stage_cv','Idg','X','N'], 187 # type_converters = converters.blitz, compiler='gcc'); 152 stage_cv[Idg[i]] = X[i,0] 153 xmomentum_cv[Idg[i]] = X[i,1] 154 ymomentum_cv[Idg[i]] = X[i,2] 155 188 156 189 157 #local update of ghost cells … … 201 169 N = len(Idg) 202 170 203 204 #======================================205 # Original python loop206 171 for i in range(N): 207 #print i,Idg[i],Idf[i] 208 stage_cv[Idg[i]] = stage_cv[Idf[i]] 209 #====================================== 210 211 212 code3 = """ 213 for (int i=0; i<N; i++){ 214 stage_cv(Idg(i)) = stage_cv(Idf(i)); 215 } 216 """ 217 #weave.inline(code3, ['stage_cv','Idg','Idf','N'], 218 # type_converters = converters.blitz, compiler='gcc'); 219 220 self.communication_time += time.time()-t0 221 222 223 # if self.ghosts is not None: 224 # stage_cv = self.quantities['stage'].centroid_values 225 # for triangle in self.ghosts: 226 # stage_cv[triangle] = stage_cv[self.ghosts[triangle]] 227 228 def update_ghosts_first(self): 229 230 # We must send the information from the full cells and 231 # receive the information for the ghost cells 232 # We have a dictionary of lists with ghosts expecting updates from 233 # the separate processors 234 235 import weave 236 from weave import converters 237 238 import time 239 t0 = time.time() 240 241 242 stage_cv = self.quantities['stage'].centroid_values 243 244 for send_proc in self.full_send_dict: 245 if send_proc != self.processor: 246 Idf = self.full_send_dict[send_proc][0] 247 Xout = self.full_send_dict[send_proc][1] 248 N = len(Xout) 249 250 251 #============================== 252 # Original python Code 253 for i in range(N): 254 Xout[i] = stage_cv[Idf[i]] 255 #============================== 256 257 258 # code1 = """ 259 # for (int i=0; i<N ; i++){ 260 # Xout(i) = stage_cv(Idf(i)); 261 # } 262 # """ 263 # weave.inline(code1, ['stage_cv','Idf','Xout','N'], 264 # type_converters = converters.blitz, compiler='gcc'); 265 266 pypar.send(Xout,send_proc) 267 268 269 #Receive data from the iproc processor 270 for recv_proc in self.ghost_recv_dict: 271 if recv_proc != self.processor: 272 Idg = self.ghost_recv_dict[recv_proc][0] 273 X = self.ghost_recv_dict[recv_proc][1] 274 275 X = pypar.receive(recv_proc,X) 276 N = len(X) 277 278 279 #=========================== 280 # Origin Python Code 281 for i in range(N): 282 stage_cv[Idg[i]] = X[i] 283 #=========================== 284 285 286 # code2 = """ 287 # for (int i=0; i<N; i++){ 288 # stage_cv(Idg(i)) = X(i); 289 # } 290 # """ 291 # weave.inline(code2, ['stage_cv','Idg','X','N'], 292 # type_converters = converters.blitz, compiler='gcc'); 293 294 295 #local update of ghost cells 296 iproc = self.processor 297 if self.full_send_dict.has_key(iproc): 298 Idf = self.full_send_dict[iproc][0] 299 #print Idf 300 Idg = self.ghost_recv_dict[iproc][0] 301 N = len(Idg) 302 #print Idg 303 304 305 #====================================== 306 # Original python loop 307 for i in range(N): 308 #print i,Idg[i],Idf[i] 309 stage_cv[Idg[i]] = stage_cv[Idf[i]] 310 #====================================== 311 312 313 # code3 = """ 314 # for (int i=0; i<N; i++){ 315 # stage_cv(Idg(i)) = stage_cv(Idf(i)); 316 # } 317 # """ 318 # weave.inline(code3, ['stage_cv','Idg','Idf','N'], 319 # type_converters = converters.blitz, compiler='gcc'); 320 172 stage_cv[Idg[i]] = stage_cv[Idf[i]] 173 xmomentum_cv[Idg[i]] = xmomentum_cv[Idf[i]] 174 ymomentum_cv[Idg[i]] = ymomentum_cv[Idf[i]] 321 175 322 176 self.communication_time += time.time()-t0 … … 339 193 340 194 341 342 195 def evolve(self, yieldstep = None, finaltime = None): 343 196 """Specialisation of basic evolve method from parent class … … 349 202 350 203 #Call basic machinery from parent class 351 for t in Advection_Domain.evolve(self, yieldstep, finaltime):204 for t in Shallow_Water_Domain.evolve(self, yieldstep, finaltime): 352 205 353 206 #Pass control on to outer loop for more specific actions … … 355 208 356 209 357
Note: See TracChangeset
for help on using the changeset viewer.