C++ mpi module for stochmagnet_main Package
openMP.h
1 #ifndef openMP_H
2 #define openMP_H
3 
4 //argmin reduction
5 
6 #include "OMP_ArrayElement.h"
7 #include "CORE_StdValArray.h"
8 #include "functions_array.h"
9 
10 #ifdef _OPENMP
11 
12 
13 //openMP code
14 #include "omp.h"
15 
16 //complex function headers
17 #include "functions_complex.h"
18 
19 #define OMP_IS_ENABLED() true
20 #define STR(a) #a
21 #define STRINGIFY(a) STR(a)
22 #define CMD_PRIVATE(C,P) C private P default(none)
23 #define CMD_SHARED(C,S) C shared S default(none)
24 #define CMD_SHARED_REDUCTION(C,S,R) C shared S default(none) reduction R
25 #define CMD_SHARED_REDUCTIONS(C,S,R1,R2) C shared S default(none) reduction R1 reduction R2
26 #define CMD_PRIVATE_SHARED(C,P,S) C private P shared S default(none)
27 #define CMD_PRIVATE_SHARED_REDUCTION(C,P,S,R) C private P shared S default(none) reduction R
28 #define CMD_PRIVATE_SHARED_REDUCTIONS(C,P,S,R1,R2) C private P shared S default(none) reduction R1 reduction R2
29 
30 
31 
32 //OMP Functions
33 #define OMP_DISABLE_DYNAMIC_THREADS_NUMBER() omp_set_dynamic(0)
34 #define OMP_GET_THREADS_NUMBER() omp_get_num_threads()
35 #define OMP_GET_MAX_THREADS_NUMBER() omp_get_max_threads()
36 #define OMP_GET_THREAD_ID() omp_get_thread_num()
37 #define OMP_SET_THREADS_NUMBER(A) omp_set_num_threads(A)
38 #define OMP_SET_MAX_THREADS_NUMBER(A) omp_set_max_threads(A)
39 #define OMP_GET_TIME() omp_get_wtime()
40 #define OMP_GET_DURATION(S) (1000*(omp_get_wtime()-S))
41 
42 // PARALLEL
43 #define OMP_PARALLEL() _Pragma( STRINGIFY (omp parallel ) )
44 #define OMP_PARALLEL_PRIVATE(P) _Pragma( STRINGIFY( CMD_PRIVATE(omp parallel,P) ))
45 #define OMP_PARALLEL_SHARED(S) _Pragma( STRINGIFY( CMD_SHARED(omp parallel,S) ))
46 #define OMP_PARALLEL_PRIVATE_SHARED(P,S) _Pragma( STRINGIFY( CMD_PRIVATE_SHARED(omp parallel,P,S) ))
47 #define OMP_PARALLEL_SHARED_REDUCTION(S,R) _Pragma( STRINGIFY( CMD_SHARED_REDUCTION(omp parallel,S,R) ))
48 #define OMP_PARALLEL_SHARED_REDUCTIONS(S,R1,R2) _Pragma( STRINGIFY( CMD_SHARED_REDUCTIONS(omp parallel,S,R1,R2) ))
49 #define OMP_PARALLEL_PRIVATE_SHARED_REDUCTION(P,S,R) _Pragma( STRINGIFY( CMD_PRIVATE_SHARED_REDUCTION(omp parallel,P,S,R) ))
50 #define OMP_PARALLEL_PRIVATE_SHARED_REDUCTIONS(P,S,R1,R2) _Pragma( STRINGIFY( CMD_PRIVATE_SHARED_REDUCTIONS(omp parallel,P,S,R1,R2) ))
51 
52 #define OMP_SECTION() _Pragma( STRINGIFY (omp section ) )
53 #define OMP_SECTIONS() _Pragma( STRINGIFY (omp sections ) )
54 
55 // BARRIER
56 #define OMP_BARRIER() _Pragma(STRINGIFY(omp barrier))
57 
58 // FOR LOOP
59 #define OMP_FOR_SIMD_STATIC(B,E,I) _Pragma( STRINGIFY (omp for simd schedule(static) ) ) \
60  for (B;E;I)
61 #define OMP_FOR_STATIC(B,E,I) _Pragma( STRINGIFY (omp for schedule(static) ) ) \
62  for (B;E;I)
63 #define OMP_FOR(B,E,I) _Pragma( STRINGIFY ( omp for simd schedule(runtime) ) ) \
64  for (B;E;I)
65 #define OMP_FOR_SIMD(S,B,E,I) _Pragma( STRINGIFY ( omp for simd schedule(S) ) ) \
66  for (B;E;I)
67 #define OMP_PARALLEL_FOR(S,B,E,I) _Pragma(STRINGIFY(omp parallel for schedule(S))) \
68  for (B;E;I)
69 #define OMP_PARALLEL_FOR_STATIC(B,E,I) _Pragma(STRINGIFY(omp parallel for schedule(static))) \
70  for (B;E;I)
71 #define OMP_FOR_COLLAPSE(S,C,B,E,I) _Pragma(STRINGIFY(omp for schedule(S) collapse(C))) \
72  for (B;E;I)
73 
74 //CRITICAL
75 #define OMP_CRITICAL(A) _Pragma(STRINGIFY(omp critical (A) ))
76 
77 //identifier : type : combiner
78 #pragma omp declare reduction(argrmin: std::pair<tIndex,tReal> : omp_out=OMP_ArrayElement<tReal>::Pmin(omp_in,omp_out))
79 #pragma omp declare reduction(argrmax: std::pair<tIndex,tReal> : omp_out=OMP_ArrayElement<tReal>::Pmax(omp_in,omp_out))
80 #pragma omp declare reduction(array_sum: CORE_StdValArray<tReal> : omp_out=CORE_StdValArray<tReal>::Sum(omp_in,omp_out))
81 #pragma omp declare reduction(valarray_sum : std::valarray<tReal> : std::transform(std::begin(omp_out),std::end(omp_out), std::begin(omp_in), std::begin(omp_out), std::plus<tReal>())) initializer(omp_priv = decltype(omp_orig)(omp_orig.size()))
82 #pragma omp declare reduction(array_realmin: std::valarray<tReal> : omp_out=functions_array::min<tReal>(omp_out,omp_in))
83 #pragma omp declare reduction(array_realmax: std::valarray<tReal> : omp_out=functions_array::max<tReal>(omp_out,omp_in))
84 #pragma omp declare reduction(ComplexMultiply: std::pair<tReal,tReal> : omp_out=functions_complex::multiply<tReal>(omp_in,omp_out))
85 #pragma omp declare reduction(ComplexAdd: std::pair<tReal,tReal> : omp_out=functions_complex::add<tReal>(omp_in,omp_out))
86 
87 
88 #else /* ifndef _OPENMP */
89 
90 //no open MP code
91 #include "CORE_Chrono.h"
92 #include <ctime>
93 
94 //OMP Functions
95 #define OMP_IS_ENABLED() false
96 #define OMP_DISABLE_DYNAMIC_THREADS_NUMBER()
97 #define OMP_GET_THREADS_NUMBER() 1
98 #define OMP_GET_MAX_THREADS_NUMBER() 1
99 #define OMP_GET_THREAD_ID() 0
100 #define OMP_SET_THREADS_NUMBER(A)
101 #define OMP_SET_MAX_THREADS_NUMBER(A)
102 #define OMP_GET_TIME() CORE_Chrono::GetClockTime()
103 #define OMP_GET_DURATION(S) CORE_Chrono::GetClockDuration(S)
104 
105 // PARALLEL
106 #define OMP_PARALLEL()
107 #define OMP_PARALLEL_PRIVATE(P)
108 #define OMP_PARALLEL_SHARED(S)
109 #define OMP_PARALLEL_PRIVATE_SHARED(P,S)
110 #define OMP_PARALLEL_SHARED_REDUCTION(S,R)
111 #define OMP_PARALLEL_SHARED_REDUCTIONS(S,R1,R2)
112 #define OMP_PARALLEL_PRIVATE_SHARED_REDUCTION(P,S,R)
113 #define OMP_PARALLEL_PRIVATE_SHARED_REDUCTIONS(P,S,R1,R2)
114 #define OMP_SECTIONS()
115 #define OMP_SECTION()
116 
117 //BARRIER
118 #define OMP_BARRIER()
119 
120 // FOR LOOP
121 #define OMP_FOR_SIMD_STATIC(B,E,I) \
122  for (B;E;I)
123 #define OMP_FOR_STATIC(B,E,I) \
124  for (B;E;I)
125 #define OMP_FOR(B,E,I) \
126  for (B;E;I)
127 #define OMP_FOR_SIMD(S,B,E,I) \
128  for (B;E;I)
129 #define OMP_PARALLEL_FOR(S,B,E,I) \
130  for (B;E;I)
131 #define OMP_PARALLEL_FOR_STATIC(B,E,I) \
132  for (B;E;I)
133 #define OMP_FOR_COLLAPSE(S,C,B,E,I) \
134  for (B;E;I)
135 
136 // CRITICAL
137 #define OMP_CRITICAL(A)
138 
139 
140 
141 #endif /*ifdef _OPENMP */
142 
143 #endif /* openMP_H */