Exercise

Timings parSapply()

Running the dice game is embarrassingly parallel. These types of simulations usually (but not always) produce a good speed-up. As before, we can use microbenchmark() or system.time(). For simplicity, we'll use system.time() in this exercise.

Instructions

100 XP

The play() function has been defined in your workspace. We'll assume that we want to play one hundred thousand games.

  • Set no_of_games to 1e5.
  • Use system.time() to time play() being repeatedly called in serial.
    • Call sapply() with 1:no_of_games and the play() wrapper function.
    • Assign the result to serial.
    • Wrap this call in system.time() to time it.
  • Create a 4 core cluster object and export the play() function to it.
  • Use system.time() to time play() being repeatedly called in parallel.
    • Rework the code you used to create serial, but make it work in parallel.