ROSE  0.9.9.76
autoPar

Overview

This tool is an implementation of automatic parallelization using OpenMP. It can automatically insert OpenMP 3.0 directives into input serial C/C++ codes. For input programs with existing OpenMP directives, the tool will double check the correctness when the right option is turned on.

Installation

Type make install-core -j4 under $ROSE_build will build and install the tool, autoPar, into $ROSE_INSTALL/bin.

User Instructions

The tool accepts a set of options:

1 autoPar -help
2 
3 Auto parallelization-specific options
4 -rose:autopar:enable_debug run automatic parallelization in a debugging mode
5 -rose:autopar:enable_patch additionally generate patch files for translations
6 -rose:autopar:unique_indirect_index assuming all arrays used as indirect indices have unique elements (no overlapping)
7 -rose:autopar:enable_distance report the absolute dependence distance of a dependence relation preventing parallelization
8 -annot filename specify annotation file for semantics of abstractions. This option can be repeated in one command line to load multiple annotation files.
9 -dumpannot dump annotation file content

Examples

An Simple One

For an example input code:

/* Only the inner loop can be parallelized
*/
void foo()
{
int n=100, m=100;
double b[n][m];
int i,j;
for (i=0;i<n;i++)
for (j=0;j<m;j++)
b[i][j]=b[i-1][j-1];
}

You can run the tool as follows:

1 autoPar -rose:autopar:unique_indirect_index -rose:autopar:enable_patch inner_only.c
2 
3 Enabling generating patch files for auto parallelization ...
4 Assuming all arrays used as indirect indices have unique elements (no overlapping) ...
5 
6 Unparallelizable loop at line:8 due to the following dependencies:
7 2*2 TRUE_DEP; commonlevel = 2 CarryLevel = (0,0) Is precise SgPntrArrRefExp:b[i][j]@10:14->SgPntrArrRefExp:b[i - 1][j - 1]@10:21 == -1;* 0;||* 0;== -1;||::
8 
9 Automatically parallelized a loop at line:9

The generated output file rose_inner_only.c should look like:

/* Only the inner loop can be parallelized
*/
#include "omp.h"
void foo()
{
int n = 100;
int m = 100;
double b[n][m];
int i;
int j;
for (i = 0; i <= n - 1; i += 1) {
#pragma omp parallel for private (j) firstprivate (n,m,i)
for (j = 0; j <= m - 1; j += 1)
b[i][j] = b[i - 1][j - 1];
}
}

Using Annotations

Annotation files provide additional program information which is traditionally hard for compilers to extract, such as aliasing, side effect information. Multiple annotations files can be loaded in one command line Example annotation files are https://github.com/rose-compiler/rose-develop/blob/master/projects/autoParallelization/tests/floatArray.annot and https://github.com/rose-compiler/rose-develop/blob/master/projects/autoParallelization/tests/funcs.annot .

To use annotation files:

1 autoPar -annot floatArray.annot -annot funcs.annot -c interp1_elem2.C

Generating Patches

Often users want to see the changed lines only instead of seeing a big output file.

To use the patch generation feature:

1 autoPar -rose:autopar:unique_indirect_index -rose:autopar:enable_patch -c jacobi_seq.c
2 Enabling generating patch files for auto parallelization ...
3 Assuming all arrays used as indirect indices have unique elements (no overlapping) ...
4 
5 Automatically parallelized a loop at line:83
6 
7 Unparallelizable loop at line:84 due to the following dependencies:
8 1*1 OUTPUT_DEP; commonlevel = 1 CarryLevel = (0,0) Is precise SgPntrArrRefExp:f[i][0]@89:6->SgPntrArrRefExp:f[i][0]@89:6 <= -1;||::
9 1*1 OUTPUT_DEP; commonlevel = 1 CarryLevel = (0,0) Is precise SgPntrArrRefExp:f[i][0]@89:6->SgPntrArrRefExp:f[i][0]@89:6 <= -1;||::
10 
11 Automatically parallelized a loop at line:143
12 
13 Automatically parallelized a loop at line:144
14 
15 Automatically parallelized a loop at line:147
16 
17 Automatically parallelized a loop at line:148
18 
19 Automatically parallelized a loop at line:185
20 
21 Automatically parallelized a loop at line:186

The generated patch file should look like:

1 cat jacobi_seq.c.patch
2 
3 diff -ar /home/liao6/workspace/autoPar/sourcetree/projects/autoParallelization/tests/jacobi_seq.c rose_jacobi_seq.c
4 0a1
5 > #include <omp.h>
6 82a83
7 > #pragma omp parallel for private (xx,yy,i,j) firstprivate (n,m)
8 142a143
9 > #pragma omp parallel for private (i,j)
10 143a144
11 > #pragma omp parallel for private (j)
12 146a147
13 > #pragma omp parallel for private (resid,i,j) reduction (+:error)
14 147a148
15 > #pragma omp parallel for private (resid,j) reduction (+:error) firstprivate (omega,ax,ay,b)
16 184a185
17 > #pragma omp parallel for private (xx,yy,temp,i,j) reduction (+:error)
18 185a186
19 > #pragma omp parallel for private (xx,yy,temp,j) reduction (+:error) firstprivate (dx,dy)

Checking Correctness

AutoPar can examine pre-existing OpenMP directives in an application and verifies that they have correctly accounted for private, reductions and other OMP data-sharing attributes. Sample input file

#include <stdio.h>
#include <omp.h>
int main(int argc, char *argv[]) {
int N = 20;
int total ;
int i,j;
#pragma omp parallel for
for (j=0;j<N;j++) {
for (i=0;i<N;i++) {
total += i+j ;
}
}
printf("%d\n", total) ;
return 0;
}

The code above contains a real OpenMP bug someone struggled with while trying to add OMP annotations to their code, submitted here: http://openmp.org/forum/viewtopic.php?f=3&t=821

Running the autoPar as an OpenMP directive checker produces this result:

% autoPar -rose:unparse_tokens -rose:autopar:unique_indirect_index -rose:autopar:enable_diff -fopenmp -c OMPcheck.cc
<<<<<<<<<
user defined : #pragma omp parallel for
--------
OMPcheck.cc:11
compiler generated:#pragma omp parallel for private (i) reduction (+:total)
>>>>>>>>

The output above from autoPar indicates that the OMP pragma is missing an OpenMP 'private' declaration for the variable 'i', and a reduction annotation for the variable 'total'.

This page is generated from $ROSE/docs/Rose/Tools/autoPar.dox