Intel® Advisor User Guide

ID 766448
Date 6/24/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Parallelize Functions - OpenMP Tasks

You can enable multiple function calls to run in parallel as two or more tasks. This is useful for functions in library code for which the source is not available. The statements to run in parallel are not limited to function calls (see the help topic Data and Task Parallelism).

When the outermost statements in the annotation site have been placed into tasks, as shown in the following serial example, it is easy to execute them in parallel.

TIP:
After you rewrite your code to use OpenMP* parallel framework, you can analyze its performance with Intel® Advisor perspectives. Use the Vectorization and Code Insights perspective to analyze how well you OpenMP code is vectorized or use the Offload Modeling perspective to model its performance on a GPU.

Consider the C/C++ annotated code:

    ANNOTATE_SITE_BEGIN(sitename);
        ANNOTATE_TASK_BEGIN(task1);
            statement-1;
        ANNOTATE_TASK_END();
        ANNOTATE_TASK_BEGIN(task2);
            statement-2;
        ANNOTATE_TASK_END();
        ANNOTATE_TASK_BEGIN(task3);
            statement-3;
        ANNOTATE_TASK_END();
    ANNOTATE_SITE_END();

For the C/C++ parallel code, OpenMP provides explicit support using #pragma omp parallel sections and related pragmas within a parallel code region:

 #pragma omp parallel sections
 {
     #pragma omp section
     {
         statement-1;
     }
     #pragma omp section
     {
         statement-2;
     }
      . . .
 }

Consider the annotated Fortran code:

call annotate_site_begin("sitename")
   call annotate_task_begin("task_1")
     call subroutine_1
   call annotate_task_end

   call annotate_task_begin("task_2")
     call subroutine_2
   call annotate_task_end
call annotate_site_end
...

For the parallelized Fortran code, OpenMP provides the !$omp sections and related directives that can often replace the corresponding annotations within a parallel code region:

!$omp parallel
 !$omp sections 
 !$omp section
   call subroutine_1 
 !$omp section
   call subroutine_2 
 !$omp end sections 
!$omp end parallel
...