multithreading - Not working OpenMP in C -


i use function multithread process in while. code runs fine other times stops. have identified problem in multithread process. im newbie multithread , openmp... if have tip solve that... i'll grateful. xp

void paralelsim(petrinet *p, matrix *mconflit, int steps){      matrix ring;      choicesring(p, mconflit, &ring);     clock_t t;      t = clock();     while((ring.row!=0) && ((steps>0) || (steps == continue))){         omp_set_dynamic(0);         omp_set_num_threads(ring.col);         #pragma omp parallel shared(p)         {             firethread(p, ring.m[0][omp_get_thread_num()]);         }          if(steps != continue){             steps--;         }          choicesring(p, mconflit, &ring);     }     t= clock() - t;      printf("%f seconds.\n",t,((float)t)/clocks_per_sec);     printf("m:\n");     showmatrix(&p->m);     printf("steps: %d\n", p->steps); } 

too many information missing on code snippet sure of anything, can @ least give hints of go wrong...

  1. you set number of threads arbitrary value that, assume, can quite large. that's not in openmp's philosophy. indeed, in openmp, don't expect number of threads go far beyond number of cores or hardware threads available on machine. i'm sure run time library can handle more, i'm sure performance penalty can sever , suspect there limit can manage.

  2. you repeatedly forbid nested parallelism. guess doing once enough, unless firethread() set on.

  3. you time runs clock() bad idea, since times cpu time of current threads , children , sums it, instead of reporting wall time. you'll never see if have speed-up, , you'll experience reports of slow-downs. use omp_get_wtime() instead.

  4. your time printing statement wrong 2 values packed 1 in format list.

here tentative re-write of code, can't compile or test, feel more in-line 1 expect of openmp code. maybe improve / solve issue.

void paralelsim(petrinet *p, matrix *mconflit, int steps){     matrix ring;     omp_set_dynamic(0);      choicesring(p, mconflit, &ring);      double t = omp_get_wtime();     while((ring.row!=0) && ((steps>0) || (steps == continue))){         #pragma omp parallel         for(int i=0; i<ring.col; ++i)             firethread(p, ring.m[0][i]);          if(steps != continue){             steps--;         }          choicesring(p, mconflit, &ring);     }     t = omp_get_wtime() - t;      printf("%f seconds.\n",t);     printf("m:\n");     showmatrix(&p->m);     printf("steps: %d\n", p->steps); } 

again, didn't compile there might (likely) typos. moreover, should work not give expected performance, consider move omp parallel part outside of while loop, , use omp single needed.

finally, since didn't know how many cores plan run on, didn't explicitly set number of threads. moment rely on either environment's default, or setting of omp_num_threads environment variable.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -