0

I have to use VS 2010 which supports OpenMP 2.0 I have a large single linked list and I'd like to distribute processing of nodes for threads team using OpenMP. I found some articles about using single thread to iterate and then assigning copy of each node to every thread member from the team:

#pragma omp parallel
{
    #pragma omp single default(none)
    {
        element *p = listHead;
        while( p != NULL )
        {
            #pragma omp task private(p)
            Process( p );

            p = p->next;
        }
    }
}

Here 'single' directive specifies that one thread should do iteration and inside - directive 'private' specifies that each thread receives copy of 'p' variable and do processing. Though I need something else. I'd like to distribute different nodes to threads. For example if my list contains 10 nodes and I set to use 4 threads, I'd like that first thread receives 3 nodes, second 3 nodes, third 2 nodes and fourth 2 nodes. This is just approximate assumption. Basically I'd like that each thread gets different node. I was thinking to use 'single' or 'master' directive to specify that one thread should perform iteration through the list, but I don't know how to specify this nodes distribution. Any ideas?

Update: And no it is not a duplicate as @Zulan suggested cause answer from All OpenMP Tasks running on the same thread cannot be used in VS2010. 'task' directive is not supported on OpenMP 2.0 which VS2010 deploys.

Community
  • 1
  • 1
Milos Ljumovic
  • 403
  • 4
  • 16
  • Possible duplicate of [All OpenMP Tasks running on the same thread](http://stackoverflow.com/questions/23656592/all-openmp-tasks-running-on-the-same-thread) - The question may sound different, but the answers are very fitting. @HristoIliev provides a limited way to emulate tasks with ancient compilers. – Zulan Apr 26 '17 at 17:01
  • Don't use OpenMP 2.0 with C++, see also [this post](http://stackoverflow.com/questions/13837696/can-i-safely-use-openmp-with-c11). What you can use is [tbb](https://www.threadingbuildingblocks.org/) which is build on and supports task-based parallelism using a thread pool with work-stealing. If you want to know more, ask another question. – Walter Apr 27 '17 at 08:12

0 Answers0