IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
local_distance.py
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
7import IMP.parallel
8import tasks
9import sys
10
11IMP.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)
18m.add_worker(s)
20m.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).
27c = m.get_context(tasks.setup)
28
29# Add 10 tasks with different input parameters
30for 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).
37for x in c.get_results_unordered():
38 print(x)
A worker running on the same machine as the manager.
Manages workers and contexts.
Distribute IMP tasks to multiple processors or machines.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.