Learn R Programming

pbdDMAT (version 0.5-1)

as.ddmatrix: Non-Distributed object to Distributed Object Converters

Description

A simplified interface to the distribute() and redistribute() functions.

Usage

as.ddmatrix(x, ...)

distribute(x, bldim = .pbd_env$BLDIM, xCTXT = 0, ICTXT = .pbd_env$ICTXT)

# S4 method for matrix as.ddmatrix(x, bldim = .pbd_env$BLDIM, ICTXT = .pbd_env$ICTXT)

# S4 method for `NULL` as.ddmatrix(x, bldim = .pbd_env$BLDIM, ICTXT = .pbd_env$ICTXT)

# S4 method for vector as.ddmatrix(x, bldim = .pbd_env$BLDIM, ICTXT = .pbd_env$ICTXT)

Arguments

x

a numeric matrix

...

Additional arguments.

bldim

the blocking dimension for block-cyclically distributing the matrix across the process grid.

xCTXT

the BLACS context number for initial distribution of the matrix x.

ICTXT

BLACS context number for return.

Value

Returns a distributed matrix.

Details

A simplified wrapper for the distribute() function, especially in the case that the matrix x is global (which you really should not ever let happen outside of testing, but I won't stop you).

The function will only work if x is stored on all processes, or x is stored on a single process (does not matter which) and every other process has NULL stored for x.

If several processes own pieces of the matrix x, then you can not use this function. You will have to create an appropriate ddmatrix on all processes and redistriubte the data with the redistribute() function.

As usual, the ICTXT number is the BLACS context corresponding to the process grid onto which the output distributed matrix will be distributed.

Examples

Run this code
# NOT RUN {
spmd.code = "
  library(pbdDMAT, quiet = TRUE)
  init.grid()
  
  if (comm.rank()==0){
    x <- matrix(1:16, ncol=4)
  } else {
    x <- NULL
  }
  
  dx <- as.ddmatrix(x, bldim=2)
  dx
  
  ### Can also be common to all ranks
  y <- matrix(1:25, 5, bldim=2)
  dy <- as.ddmatrix(y)
  dy

  finalize()
"

pbdMPI::execmpi(spmd.code = spmd.code, nranks = 2L)

# }

Run the code above in your browser using DataLab