Learn R Programming

pbdBASE (version 0.1-1)

SlotAccessors: Accessor Functions for Distributed Matrix Slots

Description

Functions to get dimension information, local storage, or current BLACS context from a distributed matrix.

Usage

## S3 method for class 'ddmatrix':
nrow(x)
  ## S3 method for class 'ddmatrix':
ncol(x)
  ## S3 method for class 'ddmatrix':
length(x)
  ## S3 method for class 'ddmatrix':
dim(x)
  ## S3 method for class 'ddmatrix':
submatrix(x)
  ## S3 method for class 'ddmatrix':
ldim(x)
  ## S3 method for class 'ddmatrix':
bldim(x)
  ## S3 method for class 'ddmatrix':
ctxt(x)

Arguments

x
numeric distributed matrix

Value

  • Each of dim(), ldim(), bldim() return a length 2 vector. Each of nrow(), ncol(), and length() return a length 1 vector. Likewise, so does ctxt(). submatrix() returns a matrix; namely, submatrix(x) returns a matrix of dimensions ldim(x).

Details

The functions nrow(), ncol(), length() and dim() are the natural extensions of their ordinary matrix counterparts. ldim() will give the dimension of the matrix stored locally on the process which runs the function. This is a local value, so its return is process-dependent. For example, if the 3x3 global matrix x is distributed as the ddmatrix dx across two processors with process 0 owning the first two rows and process 1 owning the third, then ldim(dx) will return 2 3 on process 0 and 1 3 on process 1. bldim() will give the blocking dimension that was used to block-cyclically distribute the distributed matrix. submatrix() will give the local storage for the requested object. ctxt() will give the current BLACS context for the requested object.

Examples

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

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

# don't do this in production code
x <- matrix(1:9, 3)
x <- as.ddmatrix(x)

y <- list(dim=dim(x), ldim=ldim(x), bldim=bldim(x))
comm.print(y)

finalize()

Run the code above in your browser using DataLab