Using Guided Auto-Parallelization for Embedded Development

GAP Overview

The guided auto parallelism feature of the Intel® compiler is a tool that offers selective advice to improve the performance of serially coded applications by suggesting changes that will take advantage of the compiler's ability to automatically vectorize and parallelize your code as well as improve the efficiency of data operations. Despite having the words "auto parallelism" in its name, this tool does not require you to implement threaded code in order to improve the execution performance of your code nor does it require that your code is already threaded or parallel code.

To use GAP feature, you need to use the -guide option. Any advice generated by the compiler when using the guided auto parallelism tool is optional; you can either implement it or reject it. The advice typically falls under three broad categories:

  • Advice for source modifications: the compiler advices you to make source changes that are localized to a loop-nest or a routine.
  • Advice to apply pragmas: the compiler advises you to apply a new pragma on a certain loop-level if the pragma semantics can be satisfied (you must verify this). In many cases, you may be able to apply the pragma (thus implicitly asserting new program/loop properties) that the compiler can then take advantage of to perform enhanced optimizations.
  • Advice to add compiler options: the compiler advises you to add command-line options that assert new properties.

Thia article will help you to understand the GAP feature of Intel® compiler in the Intel® System Studio product, it will introduce both the command line usage and Eclipse* usage of GAP.

Command line usage

1. -guide(=n)

You only need to add "-guide(=n)" option to your command line to enable GAP feature. Compiler will build your code and then give you advice about how to improve the performance

The argument "n" is the level of the guidance, the values available are 1 through 4

2. run GAP to provide guidance for auto-vectorization, auto parallelism or data transformation

GAP will give guidance for three aspects, which are auto-vectorization, auto parallelism or data transformation. You may also run GAP for each kind of guidance. The options are:

  • -guide-vec[=n]: provide guidance for auto-vectorization
  • -guide-par[=n]: provide guidance for auto parallelism
  • -guide-data-trans[=n]: provide guidance for data transformation

Same with "-guide", the argument "n" is the level of the guidance, the values available for these three options are 1 and 2.

3. Save GAP results/messages to a file

When GAP is enabled, compiler will report GAP messages to console (stderr) by default. You may want to save the GAP messages to a file to analysis. The option to save GAP message to a file is:

-guide-file[=filename] (or -guide-file-append[=filename])

4. Run GAP for certain code

When you compile a source file with GAP option, it will give guidance for the file. To run GAP on a whole project, you only need to make sure all files are compiled with GAP. But, you can also run GAP on certain code. You can use "-guide-opts=string" to tell the compiler to analyze certain code and generate recommendations that may improve optimizations. The argument "string" Is the text denoting the code to analyze and the string must appear within quotes. The possible forms are:

  • filename 
  • filename, routine 
  • filename, range [, range]... 
  • filename, routine, range [, range]...

You can specify more than one of the above forms in a string, using a semicolon between each form. Please see compiler's "User and Reference Guides" for the option to understand more details about "filename", "routine" and "range".

5. Example

See below is a example to show how to compile with GAP and what the GAP messages will look like:


#cat gap.c

	#define N 10000000

	double A[N];

void foo(int cond1, int cond2) {

	    int i, t=7;

	    for (i=0; i<N; i++) {

	#ifdef TEST_GPA

	        t=0;

	#endif

	        if (cond1) {

	            t = i+1;

	        }

        if (cond2) {

	            t = i-1;

	        }

	        A[i] = t;

	    }

	}

	#icc gap.c -c -guide

	GAP REPORT LOG OPENED ON Sat Feb 16 17:34:51 2013

remark #30761: Add -parallel option if you want the compiler to generate recommendations for improving auto-parallelization.

Number of advice-messages emitted for this compilation session: 0.

	END OF GAP REPORT LOG

	#icc gap.c -c -guide -parallel

	GAP REPORT LOG OPENED ON Sat Feb 16 17:34:58 2013

gap.c(6): remark #30523: (PAR) Assign a value to the variable(s) "t" at the beginning of the body of the loop in line 6. This will allow the loop to be parallelized. [VERIFY] Make sure that, in the original program, the variable(s) "t" read in any iteration of the loop has been defined earlier in the same iteration. [ALTERNATIVE] Another way is to use "#pragma parallel private(t)" to parallelize the loop. [VERIFY] The same conditions described previously must hold.

Number of advice-messages emitted for this compilation session: 1.

	END OF GAP REPORT LOG

	#icc gap.c -c -guide -parallel -DTEST_GPA

	GAP REPORT LOG OPENED ON Sat Feb 16 17:35:15 2013

Number of advice-messages emitted for this compilation session: 0.

	END OF GAP REPORT LOG

	#

If you need help to understand the GAP messages, you can read compiler's "User and Reference Guides" document for more details (search "GAP Message").

Using GAP in Eclipse*

1. Integrate Intel® Compiler into Eclipse*

To use GAP in Eclipse*, you need to make sure Intel® Compiler is integrated into Eclipse*. Please refer to the article "using intel compiler in eclipse for embedded development" about how to do the integration.

2. Running GAP Analysis on a Project
To run GAP analysis on a project, you have two options:

(1) Run analysis as part of a normal project build
Select “Project > Properties > C/C++ Build > Settings > Compilation Diagnostics” and enable analysis by selecting one of the values from "Enable Guided Auto Parallelism Analysis" drop-down list. See below:

You can also see options to save the GAP messages to a file there.

(2) Run a one-time analysis for the current project

Click menu item “Intel Tools > Guided Auto Parallelism > Analysis project <project name>”, see below:

Then, it will pop up a dialog to configure GAP:

You can configure the GAP options (such as guidance levels, saving GAP messages to a file etc.). After clicking OK button, it will run GPA on your project and the result will be in “Console” window:

If you double click on the GAP message (above red part), it will jump to the line which should be updated according to GAP message (if the advice involves updating a source file). See below (it jumps to the line 6 of gpa.c and displays with “i” in front of the line):

3. Running GAP Analysis on a File or within a File

Use the "Intel Tools->Guided Auto Parallelism" context menu item from "Project Explorer" or "source code Editor" in Eclipse* to run analysis on the following:

Folder: Select a folder in "Project Explorer" and right-click
Single file: Select a file in "Project Explorer" and right-click, or, right-click in the source code editor area
Function: Select the function name and right-click in
Range of lines: Select one or more lines (in source code editor) for analysis and right-click.

Note: you may also select a folder or file in "Project Explorer" and then, click the menu item "Intel Tools > Guided Auto Parallelism > Analysis folder/file xxx", the menu item text will be changed according to what you selected (project, folder or file).

Below is an example of right-clicking in the source code editor with selecting a range of lines:

Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.