C++ main module for emicrom Package  1.0
openMP.h
Go to the documentation of this file.
1 #ifndef openMP_H
2 #define openMP_H
3 
4 //argmin reduction
5 
6 #include "OMP_ArrayElement.h"
7 
8 #ifdef _OPENMP
9 
10 
11 //openMP code
12 #include "omp.h"
13 
14 
15 
16 #define OMP_IS_ENABLED() true
17 #define STR(a) #a
18 #define STRINGIFY(a) STR(a)
19 #define CMD_PRIVATE(C,P) C P default(none)
20 #define CMD_SHARED(C,S) C S default(none)
21 #define CMD_PRIVATE_SHARED(C,P,S) C P S default(none)
22 #define CMD_PRIVATE_SHARED_REDUCTION(C,P,S,R) C P S default(none) R
23 #define CMD_PRIVATE_SHARED_DEFAULT(C,P,S,D) C P S D
24 #define CMD_PRIVATE_SHARED_DEFAULT_REDUCTION(C,P,S,D,R) C P S D R
25 
26 
27 //OMP Functions
28 #define OMP_DISABLE_DYNAMIC_THREADS_NUMBER() omp_set_dynamic(0)
29 #define OMP_GET_THREADS_NUMBER() omp_get_num_threads()
30 #define OMP_GET_MAX_THREADS_NUMBER() omp_get_max_threads()
31 #define OMP_GET_THREAD_ID() omp_get_thread_num()
32 #define OMP_SET_THREADS_NUMBER(A) omp_set_num_threads(A)
33 #define OMP_SET_MAX_THREADS_NUMBER(A) omp_set_max_threads(A)
34 #define OMP_GET_TIME() omp_get_wtime()
35 #define OMP_GET_DURATION(S) (1000*(omp_get_wtime()-S))
36 
37 // PARALLEL
38 #define OMP_PARALLEL() _Pragma( STRINGIFY (omp parallel ) )
39 #define OMP_PARALLEL_PRIVATE(P) _Pragma( STRINGIFY( CMD_PRIVATE(omp parallel,P) ))
40 #define OMP_PARALLEL_SHARED(S) _Pragma( STRINGIFY( CMD_SHARED(omp parallel,S) ))
41 #define OMP_PARALLEL_PRIVATE_SHARED(P,S) _Pragma( STRINGIFY( CMD_PRIVATE_SHARED(omp parallel,P,S) ))
42 #define OMP_PARALLEL_PRIVATE_SHARED_REDUCTION(P,S,R) _Pragma( STRINGIFY( CMD_PRIVATE_SHARED_REDUCTION(omp parallel,P,S,R) ))
43 #define OMP_PARALLEL_PRIVATE_SHARED_DEFAULT(P,S,D) _Pragma( STRINGIFY( CMD_PRIVATE_SHARED_DEFAULT(omp parallel,P,S,D) ))
44 #define OMP_PARALLEL_PRIVATE_SHARED_DEFAULT_REDUCTION(P,S,D,R) _Pragma( STRINGIFY( CMD_PRIVATE_SHARED_DEFAULT_REDUCTION(omp parallel,P,S,D,R) ))
45 #define OMP_SECTION() _Pragma( STRINGIFY (omp section ) )
46 #define OMP_SECTIONS() _Pragma( STRINGIFY (omp sections ) )
47 
48 // BARRIER
49 #define OMP_BARRIER() _Pragma(STRINGIFY(omp barrier))
50 
51 // FOR LOOP
52 #define OMP_FOR(S,E,I) _Pragma(STRINGIFY(omp for )) \
53  for (S;E;I)
54 #define OMP_PARALLEL_FOR(S,E,I) _Pragma(STRINGIFY(omp parallel for)) \
55  for (S;E;I)
56 #define OMP_FOR_COLLAPSE(C,S,E,I) _Pragma(STRINGIFY(omp for collapse(C))) \
57  for (S;E;I)
58 
59 //CRITICAL
60 #define OMP_CRITICAL(A) _Pragma(STRINGIFY(omp critical (A) ))
61 
62 #pragma omp declare reduction(argrmin: std::pair<tReal,tUIndex> : omp_out=OMP_ArrayElement<tReal>::pmin(omp_out,omp_in))
63 #pragma omp declare reduction(argrmax: std::pair<tReal,tUIndex> : omp_out=OMP_ArrayElement<tReal>::pmax(omp_out,omp_in))
64 
65 #else /* ifndef _OPENMP */
66 
67 //no open MP code
68 #include "CORE_Time.h"
69 #include <ctime>
70 
71 //OMP Functions
72 #define OMP_IS_ENABLED() false
73 #define OMP_DISABLE_DYNAMIC_THREADS_NUMBER()
74 #define OMP_GET_THREADS_NUMBER() 1
75 #define OMP_GET_MAX_THREADS_NUMBER() 1
76 #define OMP_GET_THREAD_ID() 0
77 #define OMP_SET_THREADS_NUMBER(A)
78 #define OMP_SET_MAX_THREADS_NUMBER(A)
79 #define OMP_GET_TIME() CORE_Time::getClockTime()
80 #define OMP_GET_DURATION(S) CORE_Time::getClockDuration(S)
81 
82 // PARALLEL
83 #define OMP_PARALLEL()
84 #define OMP_PARALLEL_PRIVATE(P)
85 #define OMP_PARALLEL_SHARED(S)
86 #define OMP_PARALLEL_PRIVATE_SHARED(P,S)
87 #define OMP_PARALLEL_PRIVATE_SHARED_REDUCTION(P,S,R)
88 #define OMP_PARALLEL_PRIVATE_SHARED_DEFAULT(P,S,D)
89 #define OMP_PARALLEL_PRIVATE_SHARED_DEFAULT_REDUCTION(P,S,D,R)
90 #define OMP_SECTIONS()
91 #define OMP_SECTION()
92 
93 //BARRIER
94 #define OMP_BARRIER()
95 
96 //FOR
97 #define OMP_PARALLEL_FOR(S,E,I) \
98  for (S;E;I)
99 #define OMP_FOR(S,E,I) \
100  for (S;E;I)
101 #define OMP_FOR_COLLAPSE(C,S,E,I) \
102  for (S;E;I)
103 
104 // CRITICAL
105 #define OMP_CRITICAL(A)
106 
107 
108 
109 #endif /*ifdef _OPENMP */
110 
111 #endif /* openMP_H */