4 %IMP supports multithreaded evaluation
using [OpenMP](https:
5 (version 3.0 or later). This is automatically supported on Linux, but not
6 currently on Mac or Windows (the compilers there
do not support OpenMP).
8 Multithreaded evaluation uses OpenMP tasks, with each
IMP::Restraint or
IMP::ScoreState being made into one or more tasks that are executed independently. %IMP uses the information in the IMP::DepdendencyGraph to automatically determine which
IMP::ScoreState objects can be used in parallel. That is, two score states are independent
if neither depend on data written by the other.
12 By
default, %IMP runs on a single thread (i.e. not parallel). This can be
13 changed by calling the IMP::set_number_of_threads() function, using
14 the RAII class IMP::SetNumberOfThreads, or setting the command line flag
15 "number_of_threads" in executables that use %IMP's flags support.
16 The IMP::get_number_of_threads() returns the current number of threads
19 ## Writing code with OpenMP
21 If you want to parallelize code, see the helper macros in `thread_macros.h`. In particular, you can define a
new task with
IMP_TASK() and make your executable multithreaded with IMP_THREADS(). If you define tasks yourself, be sure to add
25 to make sure all the tasks are finished before returning. In general, you probably need to read various OpenMP documentation to
get things to work right.
IMP::Restraints that want to create tasks should implement IMP::Restraint::do_add_score_and_derivatives() rather than IMP::Restraint::unprotected_evaluate() as it is hard to properly get the return value back otherwise.
#define IMP_TASK(privatev, action, name)