Exercise

Planning future

Now imagine you are a user of the fictional package from the previous exercise. At home you have a two-CPU Mac computer, and at work you use a Linux cluster with two 16-CPU computers, called "oisin" and "oscar". Your job is to write a function for each of the hardware that calls freq_fapply() while taking advantage of all available CPUs. For the cluster, you set workers to a vector of computer names corresponding to the number of CPUs, i.e. 16 x "oisin" and 16 x "oscar". For a one-CPU environment, we have created a function fapply_seq().

All objects from the last exercise are loaded, including words and chars which the new functions assume to be global variables. Both functions will use ... and pass it to freq_fapply() for additional arguments.

Instructions

100 XP
  • For the Mac, write function fapply_mc() with arguments cores = 2 and .... The body is analogous to fapply_seq(); type fapply_seq to see the code. Here, use the multicore plan and pass cores into the workers argument of the plan function.
  • For the Linux cluster, write function fapply_cl() with arguments cores = NULL and .... Inside the function:
    • If cores is null, set it to a vector of default computer names c("oisin", "oscar") repeated 16 times as described above.
    • Use the cluster plan, while passing cores as the workers argument.