Skip to content

Commit

Permalink
Merge pull request #287 from econ-ark/Multithreading-fix-maybe
Browse files Browse the repository at this point in the history
Chris and I discovered that HARK.parallel.multithreadCommands did not work on some of our project code... but only in some Python environments. On Windows, I could only generate this error on Python 3, but everything worked correctly on Python 2. On Mac and/or Linux, Chris found that the error came up when running Python in a terminal, but not when running Spyder; he also tested various web servers.

After some digging, Chris found that recent versions of joblib (which multithreadCommands uses) changed the default backend of joblib from multiprocessing to loky. Apparently something in loky does not play nicely with our class structure, as it can't (de)serialize at least some AgentType subclasses.

This fixes the issue by simply changing the backend argument on the call to Parallel. It also fixes one typo in a comment.
  • Loading branch information
mnwhite authored May 15, 2019
2 parents 06f1a26 + 3f4da42 commit 3ed97e4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions HARK/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ def multiThreadCommands(agent_list,command_list,num_jobs=None):
multiThreadCommandsFake(agent_list,command_list)
return None

# Default umber of parallel jobs is the smaller of number of AgentTypes in
# Default number of parallel jobs is the smaller of number of AgentTypes in
# the input and the number of available cores.
if num_jobs is None:
num_jobs = min(len(agent_list),multiprocessing.cpu_count())

# Send each command in command_list to each of the types in agent_list to be run
agent_list_out = Parallel(n_jobs=num_jobs)(delayed(runCommands)(*args) for args in zip(agent_list, len(agent_list)*[command_list]))
agent_list_out = Parallel(backend='multiprocessing',n_jobs=num_jobs)(delayed(runCommands)(*args) for args in zip(agent_list, len(agent_list)*[command_list]))

# Replace the original types with the output from the parallel call
for j in range(len(agent_list)):
Expand Down

0 comments on commit 3ed97e4

Please sign in to comment.