source: inundation/ga/storm_surge/parallel/ring_example.py @ 1472

Last change on this file since 1472 was 1363, checked in by steve, 20 years ago

Changes to visualisation. Can use visualise_color_stage to color stage, but it uses python update (slow).

File size: 1.5 KB
Line 
1import pypar                                       # Import module and initialise MPI
2
3proc = pypar.size()                                # Number of processes as specified by mpirun
4myid = pypar.rank()                                # Id of of this process (myid in [0, proc-1])
5node = pypar.get_processor_name()                  # Host name on which current process is running
6
7print 'I am proc %d of %d on node %s' %(myid, proc, node)
8
9if myid == 0:                                      # Actions for process 0:
10  msg = 'P0' 
11  pypar.send(msg, destination=1)                   # Send message to proces 1 (right hand neighbour)
12  msg = pypar.receive(source=proc-1)               # Receive message from last process
13     
14  print 'Processor 0 received message "%s" from processor %d' %(msg, proc-1)
15
16else:                                              # Actions for all other processes:
17
18  source = myid-1                                  # Source is the process to the left
19  destination = (myid+1)%proc                      # Destination is process to the right
20                                                   # wrapped so that last processor will
21                                                   # send back to proces 0 
22 
23  msg = pypar.receive(source)                      # Receive message from source
24  msg = msg + 'P' + str(myid)                      # Update message     
25  pypar.send(msg, destination)                     # Send message to destination   
26
27pypar.finalize()                                   # Stop MPI
Note: See TracBrowser for help on using the repository browser.