Skip to content
Prev 634 / 2152 Next

How to check if %dopar% really run parallel?

Definitely works on an 8 core (new shiny toy, oh my!)... I have a return 
series for about 40 instruments dating back to 2000. Before getting 
snow/foreach/dopar to work, I previously would run the command:

chart.VaRSensitivity(R, methods=c("HistoricalVaR", "ModifiedVaR", 
"GaussianVaR"), clean="geltner", colorset=bluefocus, lwd=2)

This took a bit of time to go through all the instruments and generate a 
VaR sensitivity graph

This code, sped that process up significantly on a single 8 core 
machine, to less than 30 seconds by my estimate, code:

#define the parallelization function
run.sens <- function(R) {
         library(PerformanceAnalytics)
         png(file=paste("VAR-Sens-",R,".png", sep=""), width=500, 
height=500)
         chart.VaRSensitivity(R, methods=c("HistoricalVaR", 
"ModifiedVaR", "GaussianVaR"), clean="geltner", colorset=bluefocus, lwd=2)
         dev.off()
     }
#let?s do it, using the instrument returns
foreach(R=MyGlobalInstruments.returns) %dopar% run.sens(R)

As some have mentioned, be careful what you choose to parallelize. This 
particular example does *not* work well across networked clusters due to 
the fact that I'm creating a .png file for each instrument. It *does* 
however make sense to run it across the full 8 cores available to me (or 
X cores is fine, I do the same routine on a 4 core Linux box) on the 
local machine.

  	User	System	Elapsed
Before	722.03	1.57	763.18
After	0.04	0.25	572.01

HTH,
cedrick
On 5/4/2010 9:31 AM, Mario Valle wrote: