R: MPI_Send, MPI_Isend, MPI_Recv, and MPI_Irecv APIs
mpi.send
R Documentation
MPI_Send, MPI_Isend, MPI_Recv, and MPI_Irecv APIs
Description
The pair mpi.send and mpi.recv are two most used blocking
calls for point-to-point communications. An int, double or char vector
can be transmitted from any source to any destination.
The pair mpi.isend and mpi.irecv are the same except that
they are nonblocking calls.
Blocking and nonblocking calls are interchangeable, e.g., nonblocking
sends can be matched with blocking receives, and vice-versa.
Usage
mpi.send(x, type, dest, tag, comm = 1)
mpi.isend(x, type, dest, tag, comm = 1, request=0)
mpi.recv(x, type, source, tag, comm = 1, status = 0)
mpi.irecv(x, type, source, tag, comm = 1, request = 0)
Arguments
x
data to be sent or received. Must be the same
type for source and destination. The receive buffer must be as large as
the send buffer.
type
1 for integer, 2 for double, and 3 for
character. Others are not supported.
dest
the destination rank. Use mpi.proc.null for a
fake destination.
source
the source rank. Use mpi.any.source for any source.
Use mpi.proc.null for a fake source.
tag
non-negative integer. Use mpi.any.tag for any tag flag.
comm
a communicator number.
request
a request number.
status
a status number.
Details
The pair mpi.send (or mpi.isend) and mpi.recv
(or mpi.irecv) must be used together, i.e., if there is a sender,
then there must be a receiver. Any mismatch will result a deadlock
situation, i.e., programs stop responding. The receive buffer must be
large enough to contain an incoming message otherwise programs will be
crashed. One can use mpi.probe (or mpi.iprobe) and
mpi.get.count to find the length of an incoming message
before calling mpi.recv. If mpi.any.source or
mpi.any.tag is used in mpi.recv, one can use
mpi.get.sourcetag to find out the source or tag of the
received message. To send/receive an R object rather than an int, double
or char vector, please use the pair mpi.send.Robj and
mpi.recv.Robj.
Since mpi.irecv is a nonblocking call, x with enough buffer
must be created before using it. Then use nonblocking completion calls
such as mpi.wait or mpi.test to test if
x contains data from sender.
If multiple nonblocking sends or receives are used, please use request
number consecutively from 0. For example, to receive two messages from two
slaves, try
mpi.irecv(x,1,source=1,tag=0,comm=1,request=0)
mpi.irecv(y,1,source=2,tag=0,comm=1,request=1)
Then mpi.waitany, mpi.waitsome or mpi.waitall can be
used to complete the operations.
Value
mpi.send and mpi.isend return no value. mpi.recv
returns the int, double or char vector sent from source. However,
mpi.irecv returns no value. See details for explanation.
#on a slave
mpi.send(1:10,1,0,0)
#on master
x <- integer(10)
mpi.irecv(x,1,1,0)
x
mpi.wait()
x
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Rmpi)
Error in library(Rmpi) : there is no package called 'Rmpi'
Execution halted