خرید بک لینک

Vote count: 0

I'm trying to process two 3d arrays using parallel computing in R. I have a function that takes two vectors as input, so I need to loop through the rows and columns of my arrays. Doing this in serial code is simply too slow and R gets stuck as the arrays are large.

I've not found a solution for doing this with parallel functions and would appreciate any suggestions. I've tried parApply but do not know how to incorporate a second input, and mcmapply but it is hard to use over rows/cols. Ideally the output should also be an array of the same dimension.

Below is a reproducible example of what I'm trying to do in serial code. Any help on how this could be written in parallel code would be much appreciated!

fun <- function(a,b)
{
  a*b
}

input1 <- array(data=1:1000, dim=c(10,10,10))
input2 <- array(data=2:1001, dim=c(10,10,10))

result <- array(data=NA, dim=c(10,10,10))

for(i in 1:nrow(mat1))
{ for(j in 1:ncol(mat1)) {
    result[,i,j] <- fun(input1[,i,j], input2[,i,j])
}}

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 20 ارديبهشت 1395 ساعت: 19:58

صفحه بندی