| send-method | R Documentation |
This method lets a rank send (blocking) an object to the other rank
in the same communicator. The default return is NULL.
send(x, rank.dest = .pbd_env$SPMD.CT$rank.dest,
tag = .pbd_env$SPMD.CT$tag,
comm = .pbd_env$SPMD.CT$comm,
check.type = .pbd_env$SPMD.CT$check.type)
x |
an object to be sent from a rank. |
rank.dest |
a rank of destination where |
tag |
a tag number. |
comm |
a communicator number. |
check.type |
if checking data type first for handshaking. |
A corresponding recv() should be evoked at the corresponding rank
rank.dest.
These are high level S4 methods. By default, check.type is TRUE
and an additional send()/recv() will make a handshaking call first,
then deliver the data next.
i.e. an integer vector of length two (type and length)
will be deliver first between send() and recv() to ensure
a buffer (of right type and right size/length) is properly allocated at
the rank.dest side.
Currently, four data types are considered: integer, double,
raw/byte, and default/raw.object. The default method will
make a serialize() call first to convert the general R object into
a raw vector before sending it away. After the raw vector
is received at the rank.dest side, the vector will be
unserialize() back to the R object format.
check.type set as FALSE will stop the additional
handhsaking call, but the buffer should be prepared carefully
by the user self. This is typically for the advanced users and
more specifically calls are needed. i.e. calling those
spmd.send.integer with spmd.recv.integer correspondingly.
check.type also needs to be set as FALSE for more efficient
calls such as isend()/recv() or send()/irecv(). Currently,
no check types are implemented in those mixed calls.
A NULL is returned by default.
For calling spmd.send.*():
signature(x = "ANY")signature(x = "integer")signature(x = "numeric")signature(x = "raw")Wei-Chen Chen wccsnow@gmail.com, George Ostrouchov, Drew Schmidt, Pragneshkumar Patel, and Hao Yu.
Programming with Big Data in R Website: https://pbdr.org/
isend(), recv(), irecv().
### Save code in a file "demo.r" and run with 2 processors by
### SHELL> mpiexec -np 2 Rscript demo.r
spmd.code <- "
### Initialize
suppressMessages(library(pbdMPI, quietly = TRUE))
.comm.size <- comm.size()
.comm.rank <- comm.rank()
### Examples.
N <- 5
x <- (1:N) + N * .comm.rank
if(.comm.rank == 0){
y <- send(matrix(x, nrow = 1))
} else if(.comm.rank == 1){
y <- recv()
}
comm.print(y, rank.print = 1)
### Finish.
finalize()
"
pbdMPI::execmpi(spmd.code, nranks = 2L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.