def size(self): """ size = comm.size() Returns the size of the communicator """ return core.comm_size( self.id )
def gather( array, root, comm ): """ """ myid = core.comm_rank(comm) nprocs = core.comm_size(comm) if( myid==root ): print nm.size(array) datatype = getMpiType(array) size = nm.size(array) shape = nm.shape(array) rank = nm.rank(array) else: datatype = 0 size = 0 shape = 0 rank = 0 datatype = core.bcast( datatype, 1, core.MPI_INT, root, comm ) rank = core.bcast( rank, 1, core.MPI_INT, root, comm ) shape = core.bcast( shape, rank, core.MPI_INT, root, comm ) size = core.bcast( size, 1, core.MPI_INT, root, comm ) data = core.gather( array, size, datatype, size, datatype, root, comm ) if(myid == root): print shape shape[0] = shape[0] * nprocs print shape array = nm.asarray(data) print nm.size(array) array.shape = shape return array else: return None
def gatherv( message, root = 0,comm=core.MPI_COMM_WORLD ): rank = core.comm_rank( comm ) size = core.comm_size( comm ) #raise NotImplementedError s = pickle.dumps(message) recvlengths = core.gather(len(s),1,core.MPI_INT, 1, core.MPI_INT, root, comm) #if(rank==root): # print "recvlengths:",recvlengths displacements = [0] displ = 0 for rl in recvlengths[:-1]: displacements.append( displ+rl ) displ += rl #if(rank==root): # print "displacements:",displacements data = core.gatherv(s, len(s), core.MPI_CHAR, recvlengths, displacements, core.MPI_CHAR, root, comm) if rank==root: data = data.tostring() # print data # print "length of data:",len(data) i,n=0,0 # print recvlengths realdata = [] for length in recvlengths: n += length # print "i,n=%d,%d"%(i,n) # print data[i:n] realdata.append(pickle.loads(data[i:n])) i += length else: realdata = None return realdata
def scatterv(buffer, root=0, comm=core.MPI_COMM_WORLD): """ Input Parameters sendbuf: address of send buffer (choice, significant only at root) sendcounts: integer array (of length group size) specifying the number of elements to send to each processor displs: integer array (of length group size). Entry i specifies the displacement (relative to sendbuf from which to take the outgoing data to process i sendtype: data type of send buffer elements (handle) recvcount: number of elements in receive buffer (integer) recvtype: data type of receive buffer elements (handle) root: rank of sending process (integer) comm: communicator (handle) Output Parameter recvbuf: address of receive buffer (choice) """ size = core.comm_size( comm ) rank = core.comm_rank( comm ) length = len(buffer) sendbuffer = [] displacements = [] sendcounts = [] charbuffer = "" if( rank == root ): for b in buffer: sendbuffer.append( pickle.dumps( b ) ) if( length % size == 0 ): for x in xrange( size ): start = x * size end = start + size elements = sendbuffer[start:end] es = pickle.dumps(elements) s = 0 d = 0 s = len(es) sendcounts.append(s) displacements.append(d) d += s charbuffer += es else: remainder = length % size for x in xrange( size ): if( x == 0 ): start = 0 end = size + remainder else: start = remainder + (x * size) end = start + size elements = sendbuffer[start:end] es = pickle.dumps(elements) s = 0 d = 0 s = len(es) sendcounts.append(s) displacements.append(d) d+=s charbuffer+=es # SEND: recvbuffer = core.scatterv( charbuffer, sendcounts, displacements, core.MPI_CHAR, sendcounts[rank], core.MPI_CHAR, root, comm ) data = pickle.loads(recvbuffer) return data
def __init__(self, id): communicator.Communicator.__init__(self, int(id)) self.size = core.comm_size(self.id) self.rank = core.comm_rank(self.id)
def comm_size(self): return core.comm_size(self.id)