Debian Codegraph @

src/atlas/parallel/omp/omp.cc

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #include "atlas/parallel/omp/omp.h"
12
13 #ifdef _OPENMP
14 #include <omp.h>
15 #else
16 extern "C" void omp_set_num_threads(int num_threads);
17 extern "C" int omp_get_num_threads(void);
18 extern "C" int omp_get_max_threads(void);
19 extern "C" int omp_get_thread_num(void);
20 extern "C" int omp_get_num_procs(void);
21 extern "C" int omp_in_parallel(void);
22 extern "C" int omp_set_dynamic(int dynamic_threads);
23 extern "C" int omp_get_dynamic(void);
24 extern "C" void omp_set_nested(int nested);
25 extern "C" int omp_get_nested(void);
26 #endif
27
28 #if ATLAS_HAVE_OMP
29 extern "C" {
30 #pragma weak omp_set_num_threads
31 #pragma weak omp_get_num_threads
32 #pragma weak omp_get_max_threads
33 #pragma weak omp_get_thread_num
34 #pragma weak omp_get_num_procs
35 #pragma weak omp_in_parallel
36 #pragma weak omp_set_dynamic
37 #pragma weak omp_get_dynamic
38 #pragma weak omp_set_nested
39 #pragma weak omp_get_nested
40 }
41 #endif
42
43 void atlas_omp_set_num_threads(int num_threads) {
44 #if ATLAS_HAVE_OMP
45 if (omp_set_num_threads) {
46 omp_set_num_threads(num_threads);
47 }
48 #endif
49 }
50
51 int atlas_omp_get_num_threads(void) {
52 #if ATLAS_HAVE_OMP
53 if (omp_get_num_threads) {
54 return omp_get_num_threads();
55 }
56 else {
57 return 1;
58 }
59 #else
60 return 1;
61 #endif
62 }
63
64 int atlas_omp_get_max_threads(void) {
65 #if ATLAS_HAVE_OMP
66 if (omp_get_max_threads) {
67 return omp_get_max_threads();
68 }
69 else {
70 return 1;
71 }
72 #else
73 return 1;
74 #endif
75 }
76
77 int atlas_omp_get_thread_num(void) {
78 #if ATLAS_HAVE_OMP
79 if (omp_get_thread_num) {
80 return omp_get_thread_num();
81 }
82 else {
83 return 0;
84 }
85 #else
86 return 0;
87 #endif
88 }
89
90 int atlas_omp_get_num_procs(void) {
91 #if ATLAS_HAVE_OMP
92 if (omp_get_num_procs) {
93 return omp_get_num_procs();
94 }
95 else {
96 return 1;
97 }
98 #else
99 return 1;
100 #endif
101 }
102
103 int atlas_omp_in_parallel(void) {
104 #if ATLAS_HAVE_OMP
105 if (omp_in_parallel) {
106 return omp_in_parallel();
107 }
108 else {
109 return 0;
110 }
111 #else
112 return 0;
113 #endif
114 }
115
116 void atlas_omp_set_dynamic(int dynamic_threads) {
117 #if ATLAS_HAVE_OMP
118 if (omp_set_dynamic) {
119 omp_set_dynamic(dynamic_threads);
120 }
121 #endif
122 }
123
124 int atlas_omp_get_dynamic(void) {
125 #if ATLAS_HAVE_OMP
126 if (omp_get_dynamic) {
127 return omp_get_dynamic();
128 }
129 else {
130 return 0;
131 }
132 #else
133 return 0;
134 #endif
135 }
136
137 void atlas_omp_set_nested(int nested) {
138 #if ATLAS_HAVE_OMP
139 if (omp_set_nested) {
140 omp_set_nested(nested);
141 }
142 #endif
143 }
144
145 int atlas_omp_get_nested(void) {
146 #if ATLAS_HAVE_OMP
147 if (omp_get_nested) {
148 return omp_get_nested();
149 }
150 else {
151 return 0;
152 }
153 #else
154 return 0;
155 #endif
156 }