task - OpenMP scheduler -


i have problem distributing tasks in openmp. have next code:

#include <stdio.h> #include <unistd.h>  int cnttotal = 0; int cnt1 = 0, cnt2 = 0;  int main() {     int i;     #pragma omp parallel     #pragma omp single nowait     (i = 0; < 60; i++) {         if (cnttotal < 1) {             cnttotal++;             #pragma omp task             {                 #pragma omp atomic                 cnt1++;                 usleep(10);                 cnttotal--;             }         } else {             #pragma omp task             {                 #pragma omp atomic                 cnt2++;                 sleep(1);             }         }     }  printf("cnt1 = %d; cnt2 = %d\n", cnt1, cnt2);      return 0; } 

what didn't, cnt1 = 1, cnt2 = 59. think problem in openmp scheduler. or there don't catch.

my feeling confuse task instantiation actual execution of task. #pragma omp task refers instantiaton of task , extremely fast. thing idle thread of openmp runtime looks list ready tasks , executes it.

going problem posted. in code running thread (say t1) enters first iteration (i=0), enters first if , sets cnttotal 1 , instantiates first task (cnt1). after instantiation, t1 keeps instantiating remaining tasks while idle thread (say t2) executes task cnt1 takes approx 10us , sets cnttotal 0 again.

so in brief, happens thread instantiates task faster execute 10us in task cnt1.

for instance, in intel(r) core(tm) i7-2760qm cpu @ 2.40ghz if changed code loop runs until = 500 , sleeps 1 (usleep (1)) get:

cnt1 = 2; cnt2 = 498

which shows instantiation of tasks extremely fast.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -