X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F05_pi_for_critical.cpp;fp=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F05_pi_for_critical.cpp;h=6ada9e5bdadb33f7b8e01074c59a5c684b55ab7b;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/05_pi_for_critical.cpp b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/05_pi_for_critical.cpp new file mode 100755 index 0000000..6ada9e5 --- /dev/null +++ b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/05_pi_for_critical.cpp @@ -0,0 +1,67 @@ +#include +#include "00_pi_tools.h" +#include "OmpTools.h" + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + + + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPforCritical_Ok(int n); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +static double piOMPforCritique(int n); + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPforCritical_Ok(int n) + { + return isAlgoPI_OK(piOMPforCritique, n, "Pi OMP for critique"); + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/** + * synchronisation couteuse! + */ +double piOMPforCritique(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 critical(sum_fpi) + sum += fpi(xi); + } + + return sum * DX; + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +