For each package in Parallel R Programming basically provides a new looping construct which is used to execute a series of statements repeatedly. This looping construct performs the same work that is done by other looping constructs such as for and while. But, the main advantage of the for each Parallel Processing in R package is that it can execute the loop in parallel across multiple cores of a system.
To execute a set of statements in Parallel R Programming using for each package, we need to use do Parallel R Programming package which is a parallel backend for each package. We need to register the do Parallel to be used by for each using register Do Parallel(cores=n)function. The argument to that function specifies how many cores that have to be used for performing the operation.
Time series data were taken in order to a comparison between for each Parallel R Programming package and normal R code(sequential). Time series data consists of 586 rows and 42 columns where each row represents time series data for one location(time series object) and column represents month wise data. The chart below represents time taken by for each package with different cores and without using for each package i.e. sequential.
From the above result, we can see that using 4 cores in for each Parallel R Programming package is 3.77 times faster than R code which runs sequentially for time series data.
Here are the results when rolling forecast was done using for each Parallel-R Programming package.
From the above result, we can see that using 4 cores in for each Parallel R Programming package is 3.73 times faster than R code which runs sequentially.
Above analysis was done on Desktop machine with 4 cores and 8GB of RAM.