示例#1
0
文件: array.py 项目: steder/maroonmpi
def irecv( source, tag, communicator ):
    datatype = core.irecv( 1, core.MPI_INT, source, tag, communicator )
    rank = core.irecv( 1, core.MPI_INT, source, tag+1, communicator )
    shape = core.irecv( rank, core.MPI_INT, source, tag+2, communicator )
    size = core.irecv( 1, core.MPI_INT, source, tag+3, communicator )
    request,data = core.irecv( size, datatype, source, tag+4, communicator )
    array = nm.asarray(data)
    array.shape = shape
    return request,array
示例#2
0
def irecv( count, datatype, source, tag, comm ):
    """
    request_id, buffer = irecv( count, datatype, source, tag, communicator )

    irecv and recv have the same argument list but differ in return values.

    receive 'buffer', which consists of 'count' elements of type 'datatype',
    from the processor in 'comm' that has rank 'source' and is waiting
    for a message with tag == 'tag'.

    Request_Id:  This is an integer that provides a handle to pass
    to the functions 'test' and 'wait'.  
    Buffer:  Can be a single numeric value or a numeric array.
    Count:  Number of elements in an array, or 1 for scalar data.
    Datatype:  One of a few type constants defined in the mpi module.
    Source:  Rank in the specified communicator to receive this message from.
    Tag:  An arbitrary value used to route messages more precisely.
          Tags are often ignored (especially in simpler programs).  If
          you don't care what the tag is use:  MPI_ANY_TAG
    Comm:  The communicator that contains 'destination'
    --------------
    Example:

    # Start a recv for a 10 element array:
    >>> request,buffer = mpi.irecv( 10, mpi.MPI_INT, 0, 0, mpi.MPI_COMM_WORLD )
    >>> print 'Request #: %s'%(request)
    Request #: 134985008    
    >>> print 'buffer: %s'%(buffer)
    buffer: [0 0 0 0 0 0 0 0 0 0]
    >>> A = Numeric.array([1,2,3,4,5,6,7,8,9,10],Numeric.Int32)
    >>> send_request = mpi.isend( A, 10, mpi.MPI_INT, 0, 0, mpi.MPI_COMM_WORLD )
    >>> print 'Sending Request: %s'%(send_request)
    Sending Request: -1409286143
    >>> mpi.wait( request )
    >>> print 'buffer(after send): %s'%(buffer)
    buffer(after send): [ 1  2  3  4  5  6  7  8  9 10]

    --------------

    It's important to note that the initial value of 'buffer' is essentially
    undefined.  The values in 'buffer' can not be trusted until the irecv
    operation is complete.

    We can either use test() or wait() to determine that the irecv has
    finished.

    The wait() call blocks while test() returns immediately.

    After the call to wait() buffer is guaranteed to be set.
    """
    #raise NotImplementedError,"Non-Blocking I/O does not work(yet)"
    id,buffer = core.irecv( count, datatype, source, tag, comm )
    request = Request( "recv", id, buffer, count, datatype, source, tag, comm )
    return request,buffer
示例#3
0
def irecv(source=ANY_SOURCE, tag=ANY_TAG, comm=core.MPI_COMM_WORLD ):
    """
    message,request = comm.recv( [source(defaults to ANY_SOURCE), tag(defaults to ANY_TAG)])
    if( test(request) ):
        print 'Received message:', message
    
    Receives a message from any source and tag by default, or from specified source
    and tag.
    
    This is a NON-Blocking receive, meaning this process will not wait for the data if it is not
    yet ready.  The call will return immediately and you will want to call wait or test on
    the request object before actually using the 'message' object returned by this call.
    
    core.probe( source, tag, WORLD )
    count = core.get_count( core.MPI_CHAR )
    """
    messageType = int(core.irecv( 1, core.MPI_INT, source, tag, comm ))
    if messageType == SINGLE: #single elements (integers, characters)
        print "Single Element Case:"
        dataType = int(core.irecv( 1, core.MPI_INT, source, tag+1, comm ))
        returnvalue = core.irecv( message, 1, dataType, source, tag+2, comm )
        returnvalue = (returnvalue[0], returnvalue[1][0])
    elif messageType == SEQUENCE: #non-array sequences
        print "Sequence Case:"
        dataType = int(core.irecv( 1, core.MPI_INT, source, tag+1, comm ))
        length = int(core.irecv( 1, core.MPI_INT, source,tag+2, comm))
        returnvalue = core.irecv( length, dataType, source, tag+3, comm )
    elif messageType == ARRAY: #Array Case
        print "Array Case:"
        returnvalue = array.irecv(message, source, tag+1, comm )
    else: #object case
        print "Generic Object Case:"
        returnvalue = sobj.irecv( message, destinaion, tag+1, comm )# (2) are the same
    return returnvalue