Choose and Mark the Best Parallel Opportunities

Using the Survey tool data, choose places in your program to add parallelism and mark those places by inserting Intel Advisor annotations. To do this:

Display the Sources in the Survey Source Window

Double-click a line (or right-click a line and select View Source) in the Survey Report window for the hot subroutine solve (the first Hot Loop) to display the Survey Source window:

Survey Source window

The recursive subroutine call to setQueen uses nearly all of this program's CPU time. You can see the CPU time for individual source lines using the Survey Source:

  • The Total Time column shows the measured time executing this statement or in functions invoked from this statement.

  • The Loop Time column shows the sum of the Total Time for all the code in this loop. It is displayed for one statement in the loop, such as the loop header.

Find Where to Add Intel Advisor Parallel Site and Task Annotations

You want to distribute frequently executed instructions to different tasks that can run at the same time. So rather than looking only at the function consuming all the time, you must also examine all the functions in the call tree from main to the hot subroutine setQueen. In this case, main accepts command-line arguments, initializes an array, and calls the subroutine solve. The solve subroutine calls the setQueen subroutine, which calls itself recursively.

Either use the Survey Source window (double-click or right-click a line and select Edit Source) or the editor in the Solution Explorer to open the source file nqueens_serial.f90. Get familiar with the code execution paths and data use. For example, you need to understand code paths to ensure that any annotations you add will be executed.

The nqueens_Fortran sample includes lines that begin with !ADVISOR COMMENT. In nqueens_serial.f90, notice that:

  • The annotations for the parallel site include the loop in the solve subroutine (shown below). Also, the body of the do loop containing the call to setQueen is a task within that parallel site.

  • The use statement references the Intel Advisor annotations definitions (module file). This is needed because annotations are present in this source file. With your own Fortran application modules that contain annotations, you need to insert this line:

    use advisor_annotate
  • For your convenience, the annotations are inserted as comment lines in this version of this project's source file. For example, this is a site-begin annotation, placed just before the loop:

      !call annotate_site_begin("solve")

    These annotations are also present in the next project's source file (nqueens_annotated.f90).

subroutine solve (queens)
  implicit none
  integer, intent(inout) :: queens(:)
  integer :: i

  !ADVISOR COMMENT: When surveying this is the top function below the main function.  
  !ADVISOR COMMENT: Uncomment the three annotations below to model parallelizing the 
  !ADVISOR COMMENT: Don't forget to uncomment the "use advisor_annotate" at the top

  !call annotate_site_begin("solve")
  do i=1,size
    !call annotate_iteration_task("setQueen")
    ! try all positions in first row
    call SetQueen (queens, 1, i)
  end do
  !call annotate_site_end()
end subroutine solve

In your own program, choosing where to add task annotations may require some experimentation. If your parallel site has nested loops and the computation time used by the innermost loop is small, consider adding task annotations around the next outermost loop.

Adding Parallel Site and Task Annotations to Your Program

When adding annotations to your own program, remember to include the annotations definitions, such as the advisor_annotate module for Fortran programs. For help completing this step, access the Advisor XE Workflow tab and click the button below 2. Annotate Sources to display instructions:

Advisor XE Workflow tab with expanded Step 2 instructions

At the bottom of the Survey Report or Survey Source windows, use the annotation assistant pane to copy the annotation example code that you can paste into your editor:

  • On the right side, select Iteration Loop, Single Task from the drop-down list.

  • View the displayed example annotation code.

  • Click the Copy to Clipboard button to copy the displayed text into the clipboard.

  • Paste the code snippet into an intermediate editing window or directly into your editor. To launch the Visual Studio code editor with that source file opened to the corresponding location, either double-click a source line in the Survey Source window or right click and choose Edit Source.

  • Use the code editor to change the placeholder site and task name parameters to meaningful ones. For example, change the site name from "MySite1" to "solve" before you save the file.

For other task code structures, select the appropriate type from the list:

Intel Advisor annotation assistant drop-down list

For example, if loop(s) within the parallel site (proposed parallel code region) contain multiple tasks or a task does not include the entire loop body, select Loop, One or More Tasks. For multiple function calls that each might be tasks, select Function, One or More Tasks.

You can also copy language-specific build settings to paste into your application's build script by selecting Build Settings and clicking the Copy to Clipboard button.

Alternatively on Windows* OS systems, you can use a wizard to insert annotations into your sources:

  1. Within the Visual Studio code editor, select a code region.

  2. Right-click and select the Intel Advisor XE 2013 > Annotation Wizard from the context menu:

    After you select a code region, right-click to select the Annotation Wizard

  3. In the Choose the Annotation Type drop-down list, choose the type of annotations to be inserted. For example, if you just selected the code region for a parallel site, select Annotate Site only - select task annotations below.

  4. Click Next to specify the parameters of the opening annotation line. Site, task, and other annotations take name arguments. You should replace the placeholder name (such as MySite2) with a name that helps you quickly identify its source location. For example, type a name that describes the hot loop or function.

  5. The annotations appear in red color in the wizard. If the displayed annotations look correct, click Next to proceed. If needed, you can instead click Back.

  6. Click Finish to insert the annotations in the code editor.

  7. If you just inserted parallel site annotations, you can now select the code within the parallel site for a task, and choose one of the task annotation items from the Choose the Annotation Type drop-down list (repeat from step 4).

For more instructions on using the Annotation Wizard, view the wizard's dialog boxes or the relevant help topics.

For more complete information about compiler optimizations, see our Optimization Notice.