Pyrogenesis  trunk
openmp.h
Go to the documentation of this file.
1 /* Copyright (c) 2015 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef INCLUDED_EXTERNAL_LIBRARIES_OPENMP
24 #define INCLUDED_EXTERNAL_LIBRARIES_OPENMP
25 
26 // allows removing all OpenMP-related code via #define ENABLE_OPENMP 0
27 // before including this header. (useful during debugging, because the
28 // VC debugger isn't able to display OpenMP private variables)
29 #ifdef ENABLE_OPENMP
30 # if ENABLE_OPENMP && !defined(_OPENMP)
31 # error "either enable OpenMP in the compiler settings or don't set ENABLE_OPENMP to 1"
32 # endif
33 #else // no user preference; default to compiler setting
34 # ifdef _OPENMP
35 # define ENABLE_OPENMP 1
36 # else
37 # define ENABLE_OPENMP 0
38 # endif
39 #endif
40 
41 #if ENABLE_OPENMP
42 # include <omp.h>
43 #else
44 # define omp_get_num_threads() 1
45 # define omp_get_thread_num() 0
46 # define omp_in_parallel() 0
47 #endif
48 
49 // wrapper macro that evaluates to nothing if !ENABLE_OPENMP
50 // (much more convenient than individual #if ENABLE_OPENMP)
51 #if ENABLE_OPENMP
52 # if MSC_VERSION
53 # define OMP(args) __pragma(omp args)
54 # elif GCC_VERSION
55 # define OMP _Pragma("omp " #args)
56 # else
57 # error "port"
58 # endif
59 #else
60 # define OMP(args)
61 #endif
62 
63 #endif // #ifndef INCLUDED_EXTERNAL_LIBRARIES_OPENMP