As a disclaimer, this is my first post, and would I welcome any constructive criticism on appropriate postings in the future.
The input to my function is an array. When I input the array using the %do% option of foreach, I get the desired output array. I have searched through the various foreach threads, and have not found a similar problem. However, when I run the %dopar% option, I only get the input array back in return. Here is the basic outline of my code; I can post the full script if that would be best, but it is quite long. Ultimately, I will be scaling the array to a size where calculations will have to be done in parallel for the sake of time.
#libraries for constructing a parallel for loop
library(foreach)
library(doParallel)
cores <- detectCores()-1
#establish cluster
cl <- makeCluster(cores)
#to register the doparallel backend
registerDoParallel(cl,cores=7)
#input array
Q <- matrix(0,20,20)
Q[1:5,1:5] <- 2
#function in question....
dyn_rec_proto20_parallel <- function(vegmat){
distance <- matrix(0,length(vegmat[1,]),length(vegmat[1,]))
recruitment_prob_mat <- matrix(0,length(vegmat[1,]),length(vegmat[1,]))
foreach(i=1:length(vegmat[1,]),.export = c('IDW_scoring','roll_for_rec','Q','ageing20_parallel' ),)%dopar%{
for(j in 1:length(vegmat[1,])){
if(vegmat[i,j]==0){ #do a bunch of updates to vegmat
}
}
return(vegmat)
}