Run a series of tasks using multiple CPUs on a single computer.
Initialised with arguments:
The task (defined by a function or class, see below) will be called on each item in items, and the results saved to dataman. Results are stored in the format (key, val) where key is a unique but meaningless identifier. Results can be retrieved using dataman.values() or (for large data sets that should be iterated over) dataman.itervalues().
The task can either be a function or a class. If it is a function, it will be called for each item in items. If the items are tuples, the function will be called with those tuples as arguments (e.g. if the item is (1,2,3) the function will be called as task(1, 2, 3)). If the task is a class, it can have an __init__ method that is called once for each process (each CPU) at the beginning of the task run. If the __init__ method has a process_number argument, it will be passed an integer value from 0 to numprocesses-1 giving the number of the process (note, this is not the process ID). The class should define a __call__ method that behaves the same as above for task being a function. In both cases (function or class), if the arguments include a keyword report then it will be passed a value that can be passed as the report keyword in Brian’s run() function to give feedback on the simulation as it runs. A task function can also set self.taskname as a string that will be displayed on the GUI to give additional information.
Warning
On Windows, make sure that run_tasks() is only called from within a block such as:
if __name__=='__main__':
run_tasks(...)
Otherwise, the program will go into a recursive loop.
Note that this class only allows you to run tasks on a single computer, to distribute work over multiple computers, we suggest using Playdoh.