Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / BilatTools_OMP / src / core / OMP_Tools / cpp / OmpTools.cpp
1 #include <omp.h>
2 #include "OmpTools.h"
3
4 #define MULTIPLIER 1366
5 #define ADDEND 150889
6 #define PMOD 714025
7
8 long random_last = 0;
9 #pragma omp threadprivate(random_last)
10
11 /*----------------------------------------------------------------------*\
12 |* Implementation *|
13 \*---------------------------------------------------------------------*/
14
15 /*--------------------------------------*\
16 |* Constructor *|
17 \*-------------------------------------*/
18
19 OmpTools::OmpTools()
20 {
21 // rien
22 }
23
24 OmpTools::~OmpTools()
25 {
26 // rien
27 }
28
29 /*--------------------------------------*\
30 |* Methodes *|
31 \*-------------------------------------*/
32
33 /*----------------------*\
34 |* static public *|
35 \*---------------------*/
36
37 int OmpTools::setAndGetNaturalGranularity()
38 {
39 // ko sur ARM, 1 core detecte only
40 // {
41 // int nbThread = omp_get_num_procs();
42 // omp_set_num_threads(nbThread);
43 // return nbThread;
44 // }
45
46 #ifndef __arm__
47
48 int nbThread = omp_get_num_procs();
49
50 #else
51
52 //omp_get_num_procs ne donne pas la bonne valeurs sur kayla
53
54 int nbThread=4;//4 car kayla à 4 coeurs.
55
56 #endif
57
58 omp_set_num_threads(nbThread);
59 return nbThread;
60 }
61
62 /*--------*\
63 |* get *|
64 \*-------*/
65
66 int OmpTools::getNbCore()
67 {
68 return omp_get_num_procs();
69 }
70
71 int OmpTools::getNbThread()
72 {
73 return omp_get_num_threads();
74 }
75
76 int OmpTools::getTid()
77 {
78 return omp_get_thread_num();
79 }
80
81 /*--------*\
82 |* set *|
83 \*-------*/
84
85 void OmpTools::setNbThread(int nbThread)
86 {
87 omp_set_num_threads(nbThread);
88 }
89
90 /*--------*\
91 |* math *|
92 \*-------*/
93
94 double OmpTools::uniform01(void)
95 {
96 long random_next;
97
98 random_next = (MULTIPLIER * random_last + ADDEND) % PMOD;
99 random_last = random_next;
100
101 return ((double) random_next / (double) PMOD);
102 }
103
104 double OmpTools::uniform(double a, double b)
105 {
106 return a + uniform01() * (b - a);
107 }
108
109 /*----------------------------------------------------------------------*\
110 |* End *|
111 \*---------------------------------------------------------------------*/
112