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 sources in the Survey Source window.
- Find where to add Intel Advisor parallel site and task annotations.
- Add parallel site and task annotations.
Display the Sources in the 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 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 annotations for the parallel site include the loop in the solve subroutine (shown below). Also, the body of the
doloop containing the call to setQueen is a task within that parallel site.
usestatement 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:
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:
These annotations are also present in the next 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:
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 paste buffer.
Paste the code snippet into an intermediate editing window or directly into your editor. To launch the 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. Within the Intel Advisor GUI, click File > Options > Editor to choose the Linux* editor displayed for each source language.
Use the code editor to change the placeholder site and task name parameters to meaningful ones. For example, change the site name from
"solve"before you save the file.
For other task code structures, select the appropriate type from the 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.