cop_allreduce: Custom Reduction

Description Usage Arguments Details Value See Also Examples

View source: R/cop_allreduce.r

Description

This performs a reduce/allreduce operation on a matrix with a custom binary operation. Currently, only normal dense/numeric matrices are supported.

Usage

1
2
3
cop_allreduce(x, op, commutative = FALSE, comm = 0L)

cop_reduce(x, op, root = 0L, commutative = FALSE, comm = 0L)

Arguments

x

The input data. Should be a numeric matrix. The matrix should be the same dimensions across all processes.

op

A binary operation for numeric matrices. The function should be associative, and inputs/outputs are assumed to have the same dimensions. See the Details section for more information.

commutative

Is the operation commutative? Should be one of TRUE or FALSE.

comm

MPI communicator number.

root

MPI rank that should receive the return in the non-all version.

Details

This is a generalization of the qr_allreduce()/qr_reduce() methods also offered by this package. Conceptually, qr_reduce() is the same as doing cop_reduce() with op = function(a, b) qr.R(qr(rbind(a, b))) and commutative=TRUE, although the internals of qr_reduce() are actually quite different. In general, it should be faster and use less memory.

The function should take inputs of the same dimension, and the output should be of the same dimension as the inputs. Indeed, for intermediary calculations, the output of the op at one level will be an input for the next evaliation. This criterion is assumed and not validated or tested. Violating it could cause crashes or difficult to understand memory errors.

The operation should be associative, meaning that you should be able to put parentheses wherever you want with 2 or more chained calls. Said another way, a op b op c is the same whether evaluated a op (b op c) or (a op b) op c. The operation does not have to be commutative, which would require that a op b is the same as b op a. However, if it is, then there may be an improvement to performance by correctly specifying it as such via the commutative argument.

Value

If the all version is called or if the calling rank is equal to root, then a numeric matrix is returned, and otherwise NULL.

See Also

qr_allreduce()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
suppressMessages(library(cop))

x = matrix(1:4, 2) + 10*comm.rank()
add = function(a, b) a+b
out = cop_allreduce(x, fun=add, commutative=TRUE)
mpi_print(out)

finalize()

## End(Not run)

RBigData/cop documentation built on March 10, 2021, 8:21 p.m.