Learn R Programming

pbdBASE (version 0.5-3)

diag: diag

Description

Grab diagonal or create distributed diagonal matrix.

Usage

base.ddiagtk(x, descx, proc.dest = "all")

base.ddiagmk(diag, descx)

Arguments

x

Matrix.

descx

ScaLAPACK descriptor array.

proc.dest

Who owns the result.

diag

Diagonal.

Value

diagonal elements of matrix or a diagonal matrix

Details

For advanced users only. See pbdDMAT for high-level functions.

Examples

Run this code
# NOT RUN {
spmd.code <- "
  suppressMessages(library(pbdMPI))
  suppressMessages(library(pbdBASE))
  init.grid()

  ### Set data matrix and desc.
  x <- matrix(as.double(1:25), nrow = 5, ncol = 5)
  dim <- dim(x)
  bldim <- c(3L, 3L)
  ldim <- base.numroc(dim = dim, bldim = bldim)
  descx <- base.descinit(dim = dim, bldim = bldim, ldim = ldim)

  ### Get diagonal
  diag.x <- base.ddiagtk(x, descx)
  comm.print(diag.x)

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

spmd.code <- "
  suppressMessages(library(pbdMPI))
  suppressMessages(library(pbdBASE))
  init.grid()

  ### Set data matrix and desc.
  x <- matrix(as.double(1:25), nrow = 5, ncol = 5)
  dim <- dim(x)
  bldim <- c(3L, 3L)
  ldim <- base.numroc(dim = dim, bldim = bldim)
  descx <- base.descinit(dim = dim, bldim = bldim, ldim = ldim)

  ### Set diagonal
  diag.x <- base.ddiagtk(x, descx)
  new.x <- base.ddiagmk(diag.x, descx)
  comm.print(new.x, all.rank = TRUE)

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

# }

Run the code above in your browser using DataLab