Session Ready
Exercise

Loading package on nodes

In this example, you will run a simple application in parallel that requires the package extraDistr. You will see that if you load it only on the master, the code will fail. Then you will use the function clusterEvalQ() to load the package on all cluster nodes.

The parallel package and a 4-node cluster object cl with socket backend is available in your workspace. You will use a pre-defined function myrdnorm() that takes n, mean, and sd as arguments and passes it to the rdnorm() function from extraDistr to generate n random numbers from the discrete normal distribution with given mean and standard deviation.

Instructions 1/2
undefined XP
  • 1
    • Create a vector, n, of n_numbers_per_replicate, rep()eated n_replicates times.
    • Load extraDistr on master (the standard way).
    • Use clusterApply() to try to apply myrdnorm to n in parallel.
    • 2
      • Load extraDistr on master again.
      • Use clusterEvalQ() to also load extraDistr on each node.
      • Use clusterApply() to apply myrdnorm to n in parallel.
      • Run the plotting code to see the result.