3.4. Taskwait constructΒΆ

Apart from implicit synchronization (task dependences) OmpSs-2 also offers mechanism which allow users to synchronize task execution. The taskwait construct is an stand-alone directive (with no code block associated) and specifies a wait on the completion of all direct descendant tasks.

The syntax of the taskwait construct is the following:

#pragma oss taskwait [clauses]

The valid clauses for the taskwait construct are the following:

  • on(list-of-variables) - It specifies to wait only for the subset (not all of them) of direct descendant tasks. The taskwait with an on clause only waits for those tasks referring any of the variables appearing on the list of variables.

The on clause allows to wait only on the tasks that produces some data in the same way as in clause. It suspends the current task until all previous tasks with an out over the expression are completed. The following example illustrates its use:

int compute1 (void);
int compute2 (void);

int main()
  int result1, result2;

  #pragma oss task out(result1)
  result1 = compute1();

  #pragma oss task out(result2)
  result2 = compute2();

  #pragma oss taskwait on(result1)
  printf("result1 = %d\n",result1);

  #pragma oss taskwait on(result2)
  printf("result2 = %d\n",result2);

  return 0;