Example Function

The test1 function below is a natural candidate to be parallelized using the workqueuing model. You can express the parallelism by annotating the loop with a parallel taskq pragma and the work in the loop body with a task pragma. The parallel taskq pragma specifies an environment for the while loop in which to enqueue the units of work specified by the enclosed task pragma. Thus, the loop’s control structure and the enqueuing are executed single-threaded, while the other threads in the team participate in dequeuing the work from the taskq queue and executing it. The captureprivate clause ensures that a private copy of the link pointer p is captured at the time each task is being enqueued, hence preserving the sequential semantics.

void test1(LIST p)

{

  #pragma intel omp parallel taskq shared(p)

  {

    while (p != NULL)

    {

      #pragma intel omp task captureprivate(p)

      {

        do_work1(p);

      }

      p = p->next;

    }

  }

}