c++ - OpenMP: pragma cancel for ON NUMA -


---------------------edit-------------------------

i have edited code follows:

#pragma omp parallel private(i, piold, err) shared(threshold_err) reduction(+:pi) schedule (static) {   (i = 0; < 10000000000; i++){ //1000000000//705035067         piold = pi;         pi += (((i&1) == false) ? 1.0 : -1.0)/(2*i+1);         err = fabs(pi-piold);         if ( err < threshold_err){ #pragma omp cancel         }    } }   pi = 4*pi; 

i compile llvm3.9/clang4.0. when run 1 thread expected results pragma cancel action (checked against non pragma cancel version, resulted in faster run).

but when run threads >=2, program goes loop. run code on numa machines. happening? perhaps cancel condition not being satisfied! code takes longer single thread non-pragma-cancel version!! fyi, runs file when omp_cancellation=false.


i have following openmp code. using llvm-3.9/clang-4.0 compile code.

#pragma omp parallel private(i, piold, err) shared(pi, threshold_err) { #pragma omp reduction(+:pi) schedule (static)   (i = 0; < 10000000 ; i++){         piold = pi;         pi += (((i&1) == false) ? 1.0 : -1.0)/(2*i+1);         #pragma omp critical         {         err = fabs(pi-piold);// printf("err: %0.11f\n", err);         }         if ( err < threshold_err){                 printf("cancelling!\n");                 #pragma omp cancel         }    } } 

unfortunately not think #pragma omp cancel for terminating whole for loop. printing out err value in end, again parallelism confusing value being printed. final value of err smaller threshold_err. print cancelling printing in beginning of program, surprising. program keeps running after that!

how make sure correct implementation? btw omp_cancellation set true , small test program returns '1' corresponding function, omp_get_cancellation().

i understand omp cancel break signal, notify no thread created later. threads still running continue until end. see http://bisqwit.iki.fi/story/howto/openmp/ , http://jakascorner.com/blog/2016/08/omp-cancel.html

in fact, in opinion, see program product acceptable approximation. however, variable can keep in smaller scope. suggestion

#include <iostream> #include <cmath> #include <iomanip>  int main() {      long double pi = 0.0;     long double threshold_err = 1e-7;     int cancelfre = 0;  #pragma omp parallel shared(pi, threshold_err, cancelfre)     { #pragma omp reduction(+:pi) schedule (static)         (int = 0; < 100000000; i++){             long double piold = pi;             pi += (((i&1) == false) ? 1.0 : -1.0)/(2*i+1);             long double err = std::fabs(pi-piold);             if ( err < threshold_err){  #pragma omp cancel                cancelfre++;             }          }     }      std::cout << std::setprecision(10) << pi * 4 << " " << cancelfre;      return 0; } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -