Example #1
0
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
Example #2
0
 def bcast(self, message, root=0):
     """
     """
     s = pickle.dumps(message)
     length = int(core.bcast(len(s), 1, core.MPI_INT, root, self.id))
     data = core.bcast(s, length, core.MPI_CHAR, root, self.id)
     newmessage = pickle.loads(data)
     return newmessage
Example #3
0
def bcast( message, root=0, comm=core.MPI_COMM_WORLD ):
    """
    value = bcast( rootvalue[, root=0, communicator=mpi.COMM_WORLD] )

    Broadcast:  A collective operation that communicates the value on processor 'root' of
    of communicator mpi.COMM_WORLD to all processors in communicator mpi.COMM_WORLD

    rootvalue's value is ignored on non-root processors.

    Example of use:

    # generate / read data:
    if (mpi.COMM_WORLD.comm_rank()==0):
        mydata = somefile.read()
    else:
        mydata = 0
    # broadcast my data from root to all processors:
    mydata = mpi.bcast( mydata )
    # Or equivalently:
    mydata = mpi.bcast( mydata, 0, mpi.COMM_WORLD )
    # Or even:
    mydata = mpi.COMM_WORLD.bcast( mydata )
    # Yet another:
    mydata = mpi.COMM_WORLD.bcast( mydata, 0 )
    # Finally: do something with mydata
    # on all processors.
    """
    rank = core.comm_rank( comm )
    if( rank == root ):
        messageType = getMessageType( message )
        core.bcast( messageType, 1, core.MPI_INT, root, comm )
    else:
        messageType = int(core.bcast( 0, 1, core.MPI_INT, root, comm ))

    if messageType == SINGLE:
        print "Single Element Case:"
        dataType = getSingleType( message )
        dataType = int(core.bcast( dataType, 1, core.MPI_INT, root, comm ))
        returnvalue = core.bcast( message, 1, dataType, root, comm )
        returnvalue = formatReturnValue( returnvalue, "single" )
    elif messageType == SEQUENCE: #non-array sequences
        print "Sequence Case:"
        dataType = getSequenceType( message )
        print dataType
        dataType = int(core.bcast( dataType, 1, core.MPI_INT, root, comm ))
        length = int(core.bcast( len(message), 1, core.MPI_INT, root, comm))
        print message, length, dataType, root, comm
        returnvalue = core.bcast( message, length, dataType, root, comm )
        returnvalue = formatReturnValue( returnvalue, "sequence" )
    elif messageType == ARRAY: #Array Case
        print "Array Case:"
        returnvalue = array.bcast(message, root, comm )
        returnvalue = formatReturnValue( returnvalue, "array" )
    else: #object case
        print "Generic Object Case:"
        returnvalue = sobj.bcast( message, root, comm )# (2) are the same
        returnvalue = formatReturnValue( returnvalue, "object" )
    return returnvalue
Example #4
0
def bcast( array, root, comm ):
    """
    """
    myid = core.comm_rank(comm)
    if(myid == root):
        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.bcast( array, size, datatype, root, comm )
    array = nm.asarray(data)
    array.shape = shape
    return array
Example #5
0
def bcast(  message, root=0,comm=core.MPI_COMM_WORLD ):
    s = pickle.dumps( message )
    length = int(core.bcast(len(s),1,core.MPI_INT,root,comm))
    data = core.bcast( s, length, core.MPI_CHAR, root, comm )
    newmessage = pickle.loads(data)
    return newmessage