I am trying to increase the execution speed of the code below, but I am not sure whether to parallelize the outermost loop only or the outer loop and inner loops. I am working on Ubuntu with 2 processors and I do not know how many threads each processor would create to conduct this task and whether the spanning of many threads would bring any complications that I should be aware of and control with locks. What would you recommend? Thank you
ibrary(foreach)
library(doParallel)
nc = detectCores()
cl = makeCluster(nc, typr = βFORKβ)
registerDoParallel(cl)
pts <- list(chunkSize=2)
foreach (H in 0:HexC, .combine = βcβ) %:%{
for (HN in 0:HNcC, .Combine = βcβ) %dopar%{
for (F in 0:FucC, .Combine = βcβ ) %dopar%{
for (SA in 0:SAC, .Combine = βcβ) %dopar%
for (SO3 in 0:SO3C,{
NAmax<- sum(SA+SO3)
for (NAD in 0:NAmax, .combine = βcβ) %dopar%{
Na_Cnt<- c(Na_Cnt, NAD)
SO3_Cnt<- c(SO3_Cnt, SO3)
SA_Cnt<- c(SA_Cnt, SA)
Fuc_Cnt<- c(Fuc_Cnt, F)
HexNAc_Cnt<- c(HexNAc_Cnt, HN)
Hex_Cnt<- c(Hex_Cnt, H)
Na_Mass<- c(Na_Mass, NAD*NaAdductMass)
SO3_Mass<- c(SO3_Mass, SO3*dels["SO3"])
SA_Mass<- c(SA_Mass, SA*dels["SA"])
Fuc_Mass<- c(Fuc_Mass, F*dels["Fuc"])
HexNAc_Mass<- c(HexNAc_Mass, HN*dels["HexNAc"])
Hex_Mass<- c(Hex_Mass, H*dels["Hex"])
}
}
}
}
}
}