In this program, each node prints out it's rank and the size of the current MPI run (total number of nodes). In addition, each node prints out the same of the python program with a message "python is not about snakes".
Example 5-1. example1.py
#!/usr/bin/env python import Numeric from Numeric import * import mpi from mpi import * import sys #print "before",len(sys.argv),sys.argv sys.argv = mpi.mpi_init(len(sys.argv),sys.argv) print "after ",len(sys.argv),sys.argv myid=mpi.mpi_comm_rank(mpi.MPI_COMM_WORLD) numprocs=mpi.mpi_comm_size(mpi.MPI_COMM_WORLD) print "Hello from ",myid print "Numprocs is ",numprocs print "python is not about snakes" ###print sys.executable,sys.path mpi.mpi_finalize() |
Sample output using 2 nodes:
after 1 ('/Users/jren/mympi/mpi_tests/p_ex00.py',)
Hello from 0
Numprocs is 2
python is not about snakes
after 1 ('/Users/jren/mympi/mpi_tests/p_ex00.py',)
Hello from 1
Numprocs is 2
python is not about snakes |