IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
threads.h
Go to the documentation of this file.
1 /**
2  * \file IMP/threads.h
3  * \brief Control for using multiple threads in IMP
4  *
5  * Copyright 2007-2015 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_THREADS_H
10 #define IMPKERNEL_THREADS_H
11 #include "raii_macros.h"
12 #include <IMP/kernel_config.h>
13 
14 IMPKERNEL_BEGIN_NAMESPACE
15 /** \name Number of threads
16  Get and set the default number of threads to use in
17  \imp.
18  @{ */
19 /** Get the current number of threads requested. The default
20  is the number of cores/hardware threads in the machine if
21  there is OpenMP support, or 1 otherwise. */
22 IMPKERNELEXPORT unsigned int get_number_of_threads();
23 /** Set the current number of threads to a number greater or
24  equal to 1. Setting it to 1 disables multithreaded evaluation.
25 */
26 IMPKERNELEXPORT void set_number_of_threads(unsigned int n);
27 /** @} */
28 
29 /** Temporarily set the number of threads
30  */
31 class SetNumberOfThreads : public RAII {
32  int num_;
33 
34  public:
35  IMP_RAII(SetNumberOfThreads, (unsigned int n), { num_ = 0; },
36  {
37  num_ = get_number_of_threads();
39  },
40  {
41  if (num_) set_number_of_threads(num_);
42  num_ = 0;
43  }, );
44 };
45 
46 IMPKERNEL_END_NAMESPACE
47 
48 #endif /* IMPKERNEL_THREADS_H */
Temporarily change something; undo the change when this object is destroyed.
Definition: RAII.h:26
#define IMP_RAII(Name, args, Initialize, Set, Reset, Show)
Declares RAII-style methods in a class.
Definition: raii_macros.h:34
unsigned int get_number_of_threads()
void set_number_of_threads(unsigned int n)
Various general useful macros for IMP.