Example #1
0
	def exit(self, code):
	
		'''This method exits the simulation.
		
		In a parallel environment calls MPI_ABORT.
		In serial, calls sys.exit().
		
		Code is the exit code. Only used in serial processes.'''
		
		if Environment.isParallel:
			import pypar
			return pypar.abort(code)
		else:
			return sys.exit(code)
Example #2
0
#   mpirun -np 4 demo.py


import pypar    # The Python-MPI interface
import numpy
typ = 'd'  #'i', 'l', 'f', 'd'

numproc = pypar.size()
myid =    pypar.rank()
node =    pypar.Get_processor_name()

print "I am proc %d of %d on node %s" %(myid, numproc, node)

if numproc < 2:
  print "Demo must run on at least 2 processors to continue"
  pypar.abort()

if myid == 0:
  msg = numpy.array([0], typ)

  print 'Processor 0 sending message "%s" to processor %d' %(str(msg), 1)
  pypar.send(msg, 1)

  msg, status = pypar.receive(numproc-1, return_status=True)
  print 'Processor 0 received message "%s" from processor %d' %(str(msg), numproc-1)
  print 'Size of msg was %d bytes' %(status.bytes())

else:
  source = myid-1
  destination = (myid+1)%numproc
Example #3
0
msgid = 0
vanilla = 0 #Select vanilla mode (slower but general)

numprocs = pypar.size()
myid = pypar.rank()
processor_name = pypar.get_processor_name()

if myid == 0:
  # Main process - Create message, pass on, verify correctness and log timing
  #
  print "MAXM = %d, number of processors = %d" %(MAXM, numprocs)
  print "Measurements are repeated %d times for reliability" %repeats

if numprocs < 2:
  print "Program needs at least two processors - aborting\n"
  pypar.abort()
   
pypar.barrier() #Synchronize all before timing   
print "I am process %d on %s" %(myid,processor_name)


#Initialise data and timings
#

try:
  from numpy.random import uniform, seed
  seed(17)
  A = uniform(0.0,100.0,MAXM)
except:
  print 'problem with RandomArray'
  from numpy import ones, Float