Line | |
---|
1 | import pypar # Import module and initialise MPI |
---|
2 | |
---|
3 | proc = pypar.size() # Number of processes as specified by mpirun |
---|
4 | myid = pypar.rank() # Id of of this process (myid in [0, proc-1]) |
---|
5 | node = pypar.get_processor_name() # Host name on which current process is running |
---|
6 | |
---|
7 | print 'I am proc %d of %d on node %s' %(myid, proc, node) |
---|
8 | |
---|
9 | if 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 | |
---|
16 | else: # 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 | |
---|
27 | pypar.finalize() # Stop MPI |
---|
Note: See
TracBrowser
for help on using the repository browser.