Learn R Programming

pbdMPI (version 0.2-3)

sendrecv-method: Send and Receive an Object to and from Other Ranks

Description

This method lets a rank send an object to the other rank and receive an object from another rank in the same communicator. The default return is x.

Usage

sendrecv(x, x.buffer = NULL,
    rank.dest = (comm.rank(.SPMD.CT$comm) + 1) %%
                comm.size(.SPMD.CT$comm),
    send.tag = .SPMD.CT$tag,
    rank.source = (comm.rank(.SPMD.CT$comm) - 1) %%
                  comm.size(.SPMD.CT$comm),
    recv.tag = .SPMD.CT$tag,
    comm = .SPMD.CT$comm, status = .SPMD.CT$status)

Arguments

x
an object to be sent from a rank.
x.buffer
a buffer to store x sent from the other rank.
rank.dest
a rank of destination where x send to.
send.tag
a send tag number.
rank.source
a source rank where x sent from.
recv.tag
a receive tag number.
comm
a communicator number.
status
a status number.

Value

  • A x is returned by default.

Details

A corresponding sendrecv() should be evoked at the corresponding ranks rank.dest and rank.source.

rank.dest and rank.source can be as.integer(NULL) to create a silent sendrecv operation which is more efficient than setting rank.dest and rank.source to be equal.

References

Programming with Big Data in R Website: http://r-pbd.org/

See Also

sendrecv.replace().

Examples

Run this code
### Save code in a file "demo.r" and run with 2 processors by
### SHELL> mpiexec -np 2 Rscript demo.r

### Initial.
library(pbdMPI, quietly = TRUE)
init()
.comm.size <- comm.size()
.comm.rank <- comm.rank()

### Examples.
N <- 5
x <- (1:N) + N * .comm.size
y <- sendrecv(matrix(x, nrow = 1))
comm.print(y, rank.print = 1)

### Finish.
finalize()

Run the code above in your browser using DataLab