def recv( count, datatype, source, tag, comm ): """ buffer = recv( count, datatype, source, tag, comm ) 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'. 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: # This is the complement to the 'send' example above all_ones = recv( 10, MPI_INT, 0, 7, MPI_COMM_WORLD ) """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_recv( count, datatype, source, tag, comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.recv")
def send( buffer, count, datatype, destination, tag, comm ): """ error_code = send( buffer, count, datatype, destination, tag, comm ) Send 'buffer', which consists of 'count' elements of type 'datatype', to the processor in 'comm' that has rank 'destination' and is waiting for a message with tag == 'tag'. 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. Destination: Rank in the specified communicator to send this message to. 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: ierr = send( Numeric.ones(10), 10, MPI_INT, 1, 7, MPI_COMM_WORLD ) if( ierr ): print 'unable to send message to node 1' """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_send( buffer, count, datatype, destination, tag, comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.send")
def get_version(): """ result = iprobe( source, tag, comm ) """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_get_version() else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.get_version")
def group_rank( group ): """ rank = group_rank( group, rank ) """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_group_rank( group ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.group_rank")
def probe( source, tag, comm ): """ result = probe( source, tag, comm ) """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_probe( source, tag, comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.probe")
def group_incl( group, n, ranks ): """ group_out = group_incl( group, n, ranks ) """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_group_incl( group, n, ranks ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.group_incl")
def get_count( datatype ): """ count = get_count( datatype ) """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_get_count( datatype ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.get_count")
def comm_group( comm ): """ group = comm_group( comm ) """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_comm_group( comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.comm_group")
def log_event( intevent, intdata, stringdata ): """ errorcode = mpe. """ if ( _mpi.mpi_initialized() ): return handleError(_mpe.mpe_log_event(intevent, intdata, stringdata)) else: raise mpeException, "Attempt to call %s before mpi.init!"%("mpe.log_event")
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)" if ( _mpi.mpi_initialized() ): id,buffer = _mpi.mpi_irecv( count, datatype, source, tag, comm ) return id,buffer else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.irecv")
def error_string(): """ s = error_code() Returns the description that corresponds to the current error / status code. """ if( _mpi.mpi_initialized() ): return _mpi.mpi_error_string() else: raise MpiException,"Attempt to call %s before mpi.init!"%("mpi.error_string")
def error(): """ ierr = error() Returns most recent MPI calls return value/error code. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_error( ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.error")
def comm_size( comm ): """ size_of_comm = mpi.comm_size( comm ) Returns the number of MPI Processors in the communicator 'comm'. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_comm_size( comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.comm_size")
def comm_rank( comm ): """ my_rank_in_comm = mpi.comm_rank( comm ) Returns the rank of this MPI Processor in the communicator 'comm'. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_comm_rank( comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.comm_rank")
def wtime(): """ time = wtime() Returns elapsed time on the calling processor. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_wtime() else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.wtime")
def comm_create( comm, group ): """ newcomm = comm_create( comm, group ) Creates a new communicator from a current communicator and processor group. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_comm_create( comm, group ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.comm_create")
def scatter( sendbuffer, send_count, send_type, receive_count, receive_type, root, comm ): """ receive_buffer = scatter( sendbuffer, send_count, send_type, receive_count, receive_type, root, comm ) """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_scatter( sendbuffer, send_count, send_type, receive_count, receive_type, root, comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.scatter")
def wtick(): """ resolution = wtick() Returns the resolution of wtime. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_wtick() else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.wtick")
def status( ): """ ( source, tag, error ) = status() This function returns 3 mpi status bits describing the source, tag, and error. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_status() else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.status")
def bcast( input, count, datatype, source, comm ): """ answer = bcast( 42, 1, MPI_INT, 0, MPI_COMM_WORLD ) This sends 'count' numbers (in this case just 42) from 'source' to every other processor in 'comm'. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_bcast( input, count, datatype, source, comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.bcast")
def initialized( ): """ init_status = mpi.initialized() Returns 0 if MPI_Init has not been called. Returns Non-Zero if MPI_Init has been called. if ( mpi.initialized() ): print 'MPI_Init has been called!' """ return _mpi.mpi_initialized( )
def finalize( ): """ mpi.finalize() # shutdown MPI You should either call this function when you are done making MPI calls or before your program exits. """ # print "Entering finalize..." if ( _mpi.mpi_initialized() ): # print "Calling _mpi.mpi_finalize()..." return _mpi.mpi_finalize() else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.finalize")
def init_log(): """ errorcode = mpe.init_log() Initialize the MPE logging environment. *Requires that MPI is already initialized before it can be called. See: finish_log """ if ( _mpi.mpi_initialized() ): return handleError(_mpe.mpe_init_log()) else: raise mpeException, "Attempt to call %s before mpi.init!"%("mpe.init_log")
def allreduce( send_buff, count, datatype, op, comm ): """ result = allreduce( send_buff, count, datatype, op, comm ) Example: sum = allreduce( partial_result, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ) 'sum' on all processors of MPI_COMM_WORLD will contain the sum of all the 'partial_results' of all the processors in MPI_COMM_WORLD. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_allreduce( send_buff, count, datatype, op, comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.allreduce")
def barrier( comm ): """ error_code = barrier( mycomm ) Causes all processors in 'mycomm' to synchronize at the call to 'barrier' before proceeding. Barrier is normally used to ensure synchronization between processors. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_barrier( comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.barrier")
def finish_log( filepath ): """ errorcode = mpe.finish_log( filepath ) filepath: write the MPE events to filepath Finalizes the MPE logging environment and writes all logged information to the specificed file path. See: init_log """ if ( _mpi.mpi_initialized() ): return handleError(_mpe.mpe_finish_log(filepath)) else: raise mpeException, "Attempt to call %s before mpi.init!"%("mpe.finish_log")
def stop_log(): """ errorcode = mpe.stop_log() Allows one to dynamically stop the MPE logging system. See: start_log """ if ( _mpi.mpi_initialized() ): return handleError(_mpe.mpe_stop_log()) else: raise mpeException, "Attempt to call %s before mpi.init!"%("mpe.stop_log") return _mpe.mpe_stop_log()
def allgatherv( sendbuffer, sendcount, sendtype, recvcount, displacements, recvtype, comm ): """ receive_buffer = allgather( sendbuffer, sendcount, # number of elements sent by this processor sendtype, # datatype recvcount, # number of elements being received from a single processor recvtype, # datatype comm ) """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_allgatherv( sendbuffer, sendcount, sendtype, recvcount, displacements, recvtype, comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.allgatherv")
def scan( send_buff, count, datatype, op, comm ): """ result = scan( send_buff, count, datatype, op, comm ) Example: if ( rank = 0 ): else: """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_scan( send_buff, count, datatype, op, comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.scan")
def gatherv( sendbuffer, sendcount, sendtype, recvcount, displacements, recvtype, root, comm ): """ receive_buffer = gather( sendbuffer, sendcount, sendtype, recvcount, displacements, recvtype, root, comm) Gatherv is a special case of gather that allows you to specify how the data is distributed by passing a displacements array. """ if ( _mpi.mpi_initialized() ): return _mpi.mpi_gatherv( sendbuffer, sendcount, sendtype, recvcount, displacements, recvtype, root, comm ) else: raise MpiException, "Attempt to call %s before mpi.init!"%("mpi.gatherv")