IMP  2.3.1
The Integrative Modeling Platform
threads.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/threads.h
3  * \brief Control for using multiple threads in IMP
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPBASE_THREADS_H
10 #define IMPBASE_THREADS_H
11 #include "raii_macros.h"
12 #include <IMP/base/base_config.h>
13 
14 IMPBASE_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 IMPBASEEXPORT 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 IMPBASEEXPORT void set_number_of_threads(unsigned int n);
27 /** @} */
28 
29 /** Temporarily set the number of threads
30  */
32  int num_;
33 
34  public:
35  IMP_RAII(SetNumberOfThreads, (unsigned int n), { num_ = 0; },
36  {
37  num_ = get_number_of_threads();
39  },
40  {
42  num_ = 0;
43  }, );
44 };
45 
46 IMPBASE_END_NAMESPACE
47 
48 #endif /* IMPBASE_THREADS_H */
#define IMP_RAII(Name, args, Initialize, Set, Reset, Show)
Declares RAII-style methods in a class.
Definition: raii_macros.h:34
void set_number_of_threads(unsigned int n)
unsigned int get_number_of_threads()
Various general useful macros for IMP.