Session Ready
Exercise

Using doParallel

In one of the previous exercises, you parallelized the function myrdnorm() which uses the package extraDistr to generate discrete random numbers. Here you will implement a parallel foreach solution to the same problem, using the doParallel backend. doParallel provides an argument .packages which ensures that external packages are loaded on all nodes.

doParallel and the function myrdnorm() are loaded in your namespace.

Instructions
100 XP
  • Register a cluster of 3 nodes using registerDoParallel() and argument cores.
  • Write a parallel foreach loop that evaluates the myrdnorm() function 100 times generating 1000 random numbers in each iteration. Thus, the iterator r is a vector of length 100. Results should be combined into a matrix. Within foreach() use the .packages argument to load "extraDistr" on workers.
  • Assign the dimensions of res to dim_res.