home
about
news
download
doc
source
systems
tests
bugs
contact
IMP Reference Guide
2.14.0
The Integrative Modeling Platform
IMP Manual
Reference Guide
Tutorial Index
Modules
Classes
Examples
include
IMP
version 2.14.0
thread_macros.h
Go to the documentation of this file.
1
/**
2
* \file IMP/thread_macros.h
3
* \brief Control for OpenMP
4
*
5
* Copyright 2007-2020 IMP Inventors. All rights reserved.
6
*
7
*/
8
9
#ifndef IMPKERNEL_THREAD_MACROS_H
10
#define IMPKERNEL_THREAD_MACROS_H
11
12
#include "
threads.h
"
13
#include "
utility_macros.h
"
14
#include "
log_macros.h
"
15
#ifdef _OPENMP
16
#include <
IMP/CreateLogContext.h
>
17
#include <omp.h>
18
#endif
19
20
#if defined(IMP_DOXYGEN) || !defined(_OPENMP)
21
22
/** Start a new OpenMP task with the next block passing the
23
list of passed variables.*/
24
#define IMP_TASK(privatev, action, name) action
25
26
/** Start a new OpenMP task with the next block passing the
27
list of passed variables.*/
28
#define IMP_TASK_SHARED(privatev, sharedv, action, name) action
29
30
/** Start a parallel section if one is not already started.
31
*/
32
#define IMP_THREADS(variables, action) action
33
34
/** Pragma for OpenMP */
35
#define IMP_OMP_PRAGMA(x)
36
37
#else
38
39
#define IMP_OMP_PRAGMA(x) IMP_PRAGMA(omp x)
40
41
#define IMP_TASK(privatev, action, name) \
42
if (IMP::get_number_of_threads() > 1) { \
43
IMP_OMP_PRAGMA( \
44
task default(none) firstprivate privatev if (omp_in_parallel())) { \
45
IMP::CreateLogContext task_context(name); \
46
action; \
47
} \
48
} else { \
49
action; \
50
}
51
52
#define IMP_TASK_SHARED(privatev, sharedv, action, name) \
53
if (IMP::get_number_of_threads() > 1) { \
54
IMP_OMP_PRAGMA(task default(none) firstprivate privatev shared \
55
sharedv if (omp_in_parallel())) { \
56
IMP::CreateLogContext task_context(name); \
57
action; \
58
} \
59
} else { \
60
action; \
61
}
62
63
#define IMP_THREADS(variables, action) \
64
if (IMP::get_number_of_threads() > 1) { \
65
IMP_OMP_PRAGMA(parallel shared variables \
66
num_threads(IMP::get_number_of_threads())) { \
67
IMP_PRAGMA(omp single) { \
68
IMP::CreateLogContext parallel_context("parallel"); \
69
action; \
70
} \
71
} \
72
} else { \
73
action; \
74
}
75
#endif
76
77
#endif
/* IMPKERNEL_THREAD_MACROS_H */
threads.h
Control for using multiple threads in IMP.
log_macros.h
Logging and error reporting support.
utility_macros.h
Various general useful macros for IMP.
CreateLogContext.h
Logging and error reporting support.