Learn R Programming

pbdDMAT (version 0.2-3)

as.ddmatrix: Simplified Syntax to Distribute Matrix Across Process Grid

Description

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

Usage

## S3 method for class 'NULL':
as.ddmatrix(x, bldim = .BLDIM, ICTXT = .ICTXT)
## S3 method for class 'vector':
as.ddmatrix(x, bldim = .BLDIM, ICTXT = .ICTXT)
## S3 method for class 'matrix':
as.ddmatrix(x, bldim = .BLDIM, ICTXT = .ICTXT)

Arguments

x
a numeric matrix
bldim
the blocking dimension for block-cyclically distributing the matrix across the process grid.
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.

See Also

Distribute

Examples

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

library(pbdDMAT, quiet = TRUE)
init.grid()

if (comm.rank()==0){
  x <- matrix(1:16, ncol=4)
} else {
  x <- NULL
}

dx <- as.ddmatrix(x, bldim=c(4,4))
print(dx)

finalize()

Run the code above in your browser using DataLab