def main( local_comm ): name = "test" local_rank = mpi.comm_rank( local_comm ) local_size = mpi.comm_size( local_comm ) print "%s (%s,%s): creating root communicator!"%(name,local_rank,local_size) sys.stdout.flush() if local_rank == 0: tmp_comm = mpi.comm_split( mpi.MPI_COMM_WORLD, 5, 0 ) print "%s (%s,%s): joined root communicator %s"%(name,local_rank,local_size,tmp_comm) sys.stdout.flush() ncomponents = mpi.comm_size( tmp_comm ) else: tmp_comm = mpi.comm_split( mpi.MPI_COMM_WORLD, 6, 0 ) print "%s (%s,%s): Joined non-root communicator %s"%(name,local_rank,local_size,tmp_comm) sys.stdout.flush() ncomponents = 0 print "%s (%s,%s): Distributing root communicator!"%(name,local_rank,local_size) ncomponents = mpi.bcast( ncomponents, 1, mpi.MPI_INT, 0, local_comm ) ncomponents = ncomponents[0] print "%s (%s,%s): Distributed root communicator!"%(name,local_rank,local_size) # Get total number of components and distribute to every node: # ncomponents = mpi.allreduce( ncomponents, 1, mpi.MPI_INT, mpi.MPI_SUM, root_comm ) #print "%s (%s,%s): Root Comm = %s"%(name,local_rank,local_size,root_comm) #ncomponents = mpi.comm_size( root_comm ) print "%s(%s,%s): ncomponents = %s"%(name, local_rank, local_size, ncomponents )
def __init__(self, locals=None, filename="<console>"): """Constructor. The optional locals argument will be passed to the InteractiveInterpreter base class. The optional filename argument should specify the (file)name of the input stream; it will show up in tracebacks. """ code.InteractiveConsole.__init__(self, locals,filename) self.rank = mpi.comm_rank( mpi.MPI_COMM_WORLD ) self.size = mpi.comm_size( mpi.MPI_COMM_WORLD ) return
import Numeric as nm import mpi mpi.init() rank = mpi.comm_rank(mpi.MPI_COMM_WORLD) size = mpi.comm_size(mpi.MPI_COMM_WORLD) root = 0 message = [rank] * (size + rank) print "Sending:", message recvcounts = mpi.gather(len(message), 1, mpi.MPI_INT, 1, mpi.MPI_INT, root, mpi.MPI_COMM_WORLD) displacements = [0] for i in recvcounts[:-1]: displacements.append(i) result = mpi.gatherv( message, len(message), mpi.MPI_INT, recvcounts, displacements, mpi.MPI_INT, root, mpi.MPI_COMM_WORLD ) if rank == root: print "Received:", result mpi.finalize()
dt = 0.0001 # The duration of each data sample (s) searchtype = 'ffdot' # One of 'ffdot', 'sideband', 'shortffts' maxTbyPb_ffdot = 11.0 ################################################## # You shouldn't need to edit anyting below here. # ################################################## # Figure out our environment if showplots: import Pgplot if parallel: import mpi from mpihelp import * myid = mpi.comm_rank() numprocs = mpi.comm_size() outfilenm = (outfiledir+'/'+outfilenm+`myid`+ '_'+searchtype+'_'+ctype+'.out') else: myid = 0 numprocs = 1 outfilenm = (outfiledir+'/'+outfilenm+ '_'+searchtype+'_'+ctype+'.out') def psrparams_from_list(pplist): psr = psrparams() psr.p = pplist[0] psr.orb.p = pplist[1] psr.orb.x = pplist[2] psr.orb.e = pplist[3] psr.orb.w = pplist[4]
ctype = 'NS' # The type of binary companion: 'WD', 'NS', or 'BH' # These are the minimum distances to measure from the true values Dp = 0.00002 # fraction of orbital period Dx = 0.0002 # fraction of projected orbital semi-major axis De = 0.01 # eccentricity (absolute) Dw = 0.5 # degrees (absolute) Dt = 0.00002 # fraction of orbital period if showplots: import Pgplot if parallel: import mpi from mpihelp import * myid = mpi.comm_rank() numprocs = mpi.comm_size() if ctype=='WD': if numprocs!=3: raise SystemExit, \ 'You need 3 procs for the NS-WD simulation.' else: if numprocs!=5: raise SystemExit, \ 'You need 5 procs for a NS-NS or NS-BH simulation.' else: myid = 0 # The mathematical model of the Fourier Peak. def quadratic(parameters, x): a = parameters[0] b = parameters[1]
def setUp(self): self.rank = mpi.comm_rank(mpi.MPI_COMM_WORLD) self.size = mpi.comm_size(mpi.MPI_COMM_WORLD)
def testCommSize( self ): size = mpi.comm_size( mpi.MPI_COMM_WORLD ) print size self.assert_( size >= 1 )