gcc openmp tasks do not work -


i have used openmp "pragma omp for" loops , wanted try openmp tasks now. simple program, should run 2 tasks parallel not seem work. did misunderstand use of tasks or wrong here?

#include<iostream> #include<omp.h>  //ubuntu 12.04 lts, gcc 4.6.3 //g++ test_omp.cpp -fopenmp  int main() {  #pragma omp parallel  {   #pragma omp single   {        #pragma omp task       {           while(true)            {            usleep(1e6);            #pragma omp critical (c_out)             std::cout<<"task1"<<std::endl;           }       }        #pragma omp task       {           while(true)            {            usleep(1e6);            #pragma omp critical (c_out)             std::cout<<"task2"<<std::endl;           }       }    }  } } 

the output is: task1 task1 task1 .....

so second task not running.

from openmp spec:

when thread encounters task construct, task generated code associated structured block. data environment of task created according data-sharing attribute clauses on task construct, per-data environment icvs, , defaults apply.

the encountering thread may execute task, or defer execution. in latter case, thread in team may assigned task. completion of task can guaranteed using task synchronization constructs. task construct may nested inside outer task, task region of inner task not part of task region of outer task.

(emphasis mine)

the way read this: single thread starts executing single section. reaches task directive, @ point may decide either run task itself, or give thread. problem occurs when decides run task - never returns.

i'm not quite sure why have task/single in example though. want seems case omp parallel sections instead:

int main() {  #pragma omp parallel sections num_threads(2)  {       #pragma omp section       {           while(true)           {            usleep(3e5);            #pragma omp critical (c_out)             std::cout<<"task1"<<std::endl;           }       }       #pragma omp section       {           while(true)           {            usleep(5e5);            #pragma omp critical (c_out)             std::cout<<"task2"<<std::endl;           }       }  } } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -