How can I run a for loop in parallel (so I can use all the processors on my windows machine) with the result being a 3 dimension array? The code I have now takes about an hour to run and is something like:
guad = array(NA,c(1680,170,15))
for (r in 1:15)
{
name = paste("P:/......",r,".csv",sep="")
pp = read.table(name,sep=",",header=T)
#lots of stuff to calculate x (which is a matrix)
guad[,,r]= x #
}
I have been looking at related questions and thought I could use foreach but I couldn't find a way to combine the matrices into an array.
I am new to parallel programming so any help will be very much appreciated!
.combineparameter offoreach. You don't need to pre-allocateguadwithforeachand each iteration should only return a matrix. All matrices can then be combined to an array byforeach. Study the help pages and package vignette..combinebut it only allows c,cbind,rbind or a function so how can I combine the matrices to an array?.combinethat binds matrices into an array?