17 lines
326 B
R
Raw Normal View History

2025-01-12 00:52:51 +08:00
# 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))