OpenMP 3.0, currently available in gcc and the Intel compiler, has a task directive that allows a thread to delegate a task to a thread.
Inspired by this answer and this course , I wrote these code that works great for me:
map< int,string >::iterator datIt; ... #pragma omp parallel for #pragma omp single nowait { for(datIt=dat.begin();datIt!=dat.end();datIt++)
One cycle (one directive) throughout the map and puts each task for each element of the map in pulling tasks. Other tasks of the OMP stream process remain in this tension. For other OMP tasks, there is no need to wait for the end of the for loop to start processing the task (nowait). Each task has an element pointer on the map for processing (firstprivate (datIt)).
Limitation: each task must be independent, and the map must not be changed to the end.
source share