Add logging code to replicate and pmap

This commit adds optional hooks to pmap. The first executes code
after a worker is assigned to the task but before the task is
executed on that process. The second hook executes after the task
terminates and is returned to the main process.

These hooks are used to make a version of replicate that writes
to logfiles before and after each process is executed.
Add code to save state of RNG

This commit adds an optional random number generator as an argument to
replicate. If it is provided, the state of the RNG will be saved before
each call of 'dgp' and will be saved at the end of the simulations.
This should make debugging easier and also make it possible to extend
the simulations from their final stopping point.