X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F06_pi_for_atomic.cpp;fp=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F06_pi_for_atomic.cpp;h=ca8878b041bf802af37a5279397f85488645bd42;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/06_pi_for_atomic.cpp b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/06_pi_for_atomic.cpp new file mode 100755 index 0000000..ca8878b --- /dev/null +++ b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/06_pi_for_atomic.cpp @@ -0,0 +1,67 @@ +#include +#include "00_pi_tools.h" +#include "OmpTools.h" + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + + + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPforAtomic_Ok(int n); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +static double piOMPforAtomic(int n); + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPforAtomic_Ok(int n) + { + return isAlgoPI_OK(piOMPforAtomic, n, "Pi OMP for atomic"); + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/** + * synchronisation couteuse! + */ +double piOMPforAtomic(int n) + { + double sum = 0; + double xi; + const double DX = 1.0/(double)n; + + #pragma omp parralel for private(xi) + for (int i = 0; i < n; i++) + { + xi = i*DX; + #pragma omp atomic + sum += fpi(xi); // Uniquement l'operateur += est atomi, 'fpi' est exécuté en parralèle. + } + + return sum * DX; + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +