Exercise

Exporting global objects

Using clusterEvalQ() for setting global variables as in the last example assigns them only on the nodes and not on the master. If you want to share the same objects between master and the nodes, use the function clusterExport(). Here we use the same function as in the last exercise, myrdnorm() and initialize the global objects first on the master. Then you will use clusterExport() to export those objects to the workers.

clusterExport() takes two arguments: a cluster object and a character vector of variable names to copy from the master to the nodes.

The parallel package, a cluster object of size four, cl, the function myrdnorm(), and the number of numbers to generate, n, are available.

Instructions

100 XP
  • On the master, set global objects mean and sd to 20 and 10, respectively.
  • Load the extraDistr package on workers using clusterEvalQ().
  • Using clusterExport(), export mean and sd to the cluster nodes.
  • As in the previous exercise, evaluate myrdnorm() in parallel, assigning to res.