source: anuga_core/source/pypar-numeric/ring_example.py @ 7340

Last change on this file since 7340 was 5779, checked in by steve, 16 years ago

Added the old version of pypar which works with Numeric. Necessary for parallel code until we move anuga to numpy (and then we can use pypar as distribute via sourceforge).

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.