IMP  2.2.1
The Integrative Modeling Platform
parallel/local_distance.py

This is a simple demonstration of the parallel functionality. It uses the module to make a simple plot of score versus distance for a harmonic distance restraint, dividing the work between several slaves.

1 ## \example parallel/local_distance.py
2 # This is a simple demonstration of the parallel functionality. It uses the
3 # module to make a simple plot of score versus distance for a harmonic
4 # distance restraint, dividing the work between several slaves.
5 #
6 
7 import IMP.parallel
8 import tasks
9 
10 # Set up a Manager to keep track of slaves and our tasks
12 
13 # Add slaves (two processors on the local machine)
15 m.add_slave(s)
17 m.add_slave(s)
18 
19 # Generate a context (an environment on each slave in which tasks will be
20 # run). Provide a setup function for this context. Note that setup functions
21 # and task functions are sent across the network to the slaves using Python's
22 # 'pickle' module, which requires them to be defined in a separate module
23 # (tasks.py in this case).
24 c = m.get_context(tasks.setup)
25 
26 # Add 10 tasks with different input parameters
27 for dist in range(0, 10):
28  c.add_task(tasks.Task(dist))
29 
30 # Run all 10 tasks, distributed between the two slaves. Get the results in
31 # the order they are returned (not necessarily the order they were created).
32 # This produces a simple table of score versus distance for a harmonic distance
33 # restraint (see tasks.py for the actual calculations).
34 for x in c.get_results_unordered():
35  print x