c - omp_set_num_threads should I use it every time or can set it once? -
i have program calls sequently 100 functions - want use omp_set_num_threads every function. should use before every time call ith function? or can use once, lets after int main(int argc, char **argv) , used every function call?
it looks this:
omp_set_num_threads(val); if(call_me_i) call_ith_function; omp_set_num_threads(val); if(call_me_i+1) call_ith+1_function; ...
short answer: need set number of threads once, unless want change later. once set, "remembered".
it sounds me have individual functions have parallel code in them, , want make sure indeed run in parallel. when have large number of if statements, want consider switch.
omp_set_num_threads(val); //<<< set once switch(whatfunction) { case fun1: callfunction1(); break; case fun2: callfunction2(); break; default: // etc } void callfunction1() { int ii; #pragma omp parallel // <<<< loop run in parallel >>>>> for(ii=0; ii<100; ii++) { // stuff } printf("done\n"); printf("really done\n"); printf("totally done\n"); // << not in parallel } void callfunction2() { int jj; for(jj=0; jj<100; jj++) { // stuff } // <<<< loop not run in parallel since there no #pragma in front of }
Comments
Post a Comment