IMP logo
IMP Reference Guide  2.17.0
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 workers.

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 workers.
5 #
6 
7 import IMP.parallel
8 import tasks
9 import sys
10 
11 IMP.setup_from_argv(sys.argv, "local distance")
12 
13 # Set up a Manager to keep track of workers and our tasks
15 
16 # Add workers (two processors on the local machine)
18 m.add_worker(s)
20 m.add_worker(s)
21 
22 # Generate a context (an environment on each worker in which tasks will be
23 # run). Provide a setup function for this context. Note that setup functions
24 # and task functions are sent across the network to the workers using Python's
25 # 'pickle' module, which requires them to be defined in a separate module
26 # (tasks.py in this case).
27 c = m.get_context(tasks.setup)
28 
29 # Add 10 tasks with different input parameters
30 for dist in range(0, 10):
31  c.add_task(tasks.Task(dist))
32 
33 # Run all 10 tasks, distributed between the two workers. Get the results in
34 # the order they are returned (not necessarily the order they were created).
35 # This produces a simple table of score versus distance for a harmonic distance
36 # restraint (see tasks.py for the actual calculations).
37 for x in c.get_results_unordered():
38  print(x)