def DisableAll(): if not lparallel: return mpi.synchronizeQueuedOutput('/dev/null')
if _newpympi: def mpirecv(pe=0, ms=0): result, stat = mpi.recv(pe, ms) return result else: def mpirecv(pe=0, ms=0): return mpi.recv(pe, ms) # --------------------------------------------------------------------------- # --- By default, set so that only PE0 sends output to the terminal. if lparallel: mpi.synchronizeQueuedOutput('/dev/null') def number_of_PE(): if not lparallel: return 0 return mpi.procs def get_rank(): if not lparallel: return 0 return mpi.rank # --------------------------------------------------------------------------- # Enable output from all processors def EnableAll():
def EnableAll(): if not lparallel: return mpi.synchronizeQueuedOutput(None)
#**************************************************************************# #* FILE ************** scatters.py ************************# #**************************************************************************# #* Author: Chris Murray Martin Casado Tue Feb 19 18:15:03 PST 2002 # #**************************************************************************# #* Test interface and expected behavior of mpi.gather/mpi.allgather # #**************************************************************************# import mpi mpi.synchronizeQueuedOutput("/dev/null","/dev/null") import unittest #==================================================================== # Scatter #==================================================================== class scatters(unittest.TestCase): def testScatter(self): #decide on roots roots = [0,0,0] roots = [int(mpi.procs / 3), 0, int(mpi.procs / 2) ] nprocs = mpi.procs #values to be scattered list1 = [] list2 = [] longList = [] tuple1 = () string1 = "" for x in range(nprocs): list1 += [nprocs - x]
#**************************************************************************# #* FILE ************** reduces.py ************************# #**************************************************************************# #* Author: Patrick Miller February 14 2002 *# #**************************************************************************# #* Test interface and expected behavior of mpi.reduce and allreduce *# #**************************************************************************# import mpi mpi.synchronizeQueuedOutput("/dev/null","/dev/null") import unittest import sys ################################################################## # CLASS REDUCE # ################################################################## class reduce(unittest.TestCase): reducer = mpi.reduce ################################################################## # MEMBER COMPAREROOT # # Data comparison on root process # ################################################################## def compareRoot(self,label,v,expected): self.failUnless(type(v) == type(expected),'%s] Bad result type %s on %d, expected %s'%( label,type(v),mpi.rank,type(expected))) self.failUnless(v==expected,'%s] Bad value %r on %d (expected %r)'%( label,v,mpi.rank,expected)) return
# # Python file with some parallel operations # from numpy import * # --- Try import mpi - if not found, then run in serial mode # --- Note that: # --- mpi.COMM_WORLD is same as MPI_COMM_WORLD # --- mpi.WORLD is a duplicate of MPI_COMM_WORLD # --- comm_world is used for most communications (and defaults to mpi.WORLD) try: import mpi mpi.synchronizeQueuedOutput(None) me = mpi.rank npes = mpi.procs comm_world = mpi.WORLD except ImportError: me = 0 npes = 1 comm_world = None lparallel = (npes > 1) def setdefaultcomm_world(comm): global comm_world,me,npes if not lparallel: return comm_world = comm me = comm_world.rank npes = comm_world.procs # --------------------------------------------------------------------------- # --- send and recv using the correct comm_world
def DisableAll(): if lpyMPIactive: mpi.synchronizeQueuedOutput('/dev/null') elif lmpi4pyactive: synchronizeQueuedOutput_mpi4py(out=True, error=False)
def EnableAll(): if lpyMPIactive: mpi.synchronizeQueuedOutput(None) elif lmpi4pyactive: synchronizeQueuedOutput_mpi4py(out=False, error=False)