2025-01-12 04:36:52 +08:00

17 lines
326 B
R

# simple (and inefficient) parallel matrix multiply
library(foreach)
# generate the input matrices
x <- matrix(rnorm(16), 4)
y <- matrix(rnorm(16), 4)
# multiply the matrices
z <- foreach(y=iter(y, by='col'), .combine=cbind) %dopar% (x %*% y)
# print the results
print(z)
# check the results
print(all.equal(z, x %*% y))