Learn R Programming

pbdMPI (version 0.1-5)

communicator: Communicator Functions

Description

The functions provide controls to communicators.

Usage

barrier(comm = .SPMD.CT$comm)
  comm.is.null(comm = .SPMD.CT$comm)
  comm.rank(comm = .SPMD.CT$comm)
  comm.size(comm = .SPMD.CT$comm)
  comm.dup(comm, newcomm)
  comm.free(comm = .SPMD.CT$comm)
  init()
  finalize(mpi.finalize = .SPMD.CT$mpi.finalize)
  comm.disconnect(comm = .SPMD.CT$comm)
  comm.c2f(comm = .SPMD.CT$comm)

Arguments

comm
a communicator number.
newcomm
a new communicator number.
mpi.finalize
if MPI should be shutdown.

Value

  • Most function return an invisible state of MPI call.

Details

Another functions are direct calls to MPI library.

barrier blocks all processors until everyone call this.

comm.is.null returns -1 if the array of communicators is not allocated, i.e. init is not called yet. It returns 1 if the communicator is not initialized, i.e. NULL. It returns 0 if the communicator is initialized.

comm.rank returns the processor's rank for the given comm.

comm.size returns the total processes for the given comm.

comm.dup duplicate a newcomm from comm.

comm.free free a comm.

init initializes a MPI world, and set two global variables .comm.size and .comm.rank in .GlobalEnv.

finalize frees memory and finishes a MPI world if mpi.finalize = TRUE.

comm.disconnect frees a comm.

comm.c2f returns an integer for Fortran MPI support.

References

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

Examples

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

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

### Examples 
comm.print(.comm.size)
comm.print(.comm.rank, all.rank = TRUE)
comm.print(comm.rank(), rank.print = 1)
comm.print(comm.c2f())

### Finish
finalize()

Run the code above in your browser using DataLab