HPC++ Level 1

[HPC++ Tutorial Homepage][Introduction]

The level 1 library has three componenets. The first component is a set of
simple loop directives that control parallelism within a single context. The
compiler is free to ignore these directives, but if there is more than one
processor available, it can use the directives to parallelize simple loops.

HPC++ Loop directives are very simple. The HPC++ programmer can identify a
loop and annotate it with a #pragma directive to inform the compiler it
is "independent". This means that each iteration is independent of every other
iteration, and they are not ordered. Consequently, the compiler may choose to execute
the loop in parallel, and generate the needed synchronization for the end of the loop.
In addition, variables that do not carry loop dependences can be labeled as PRIVATE so
that one copy of the variable is generated for each iteration. Furthermore, in the
case of reductions, it is possible to label a statement with the REDUCE directive so
that the accumulation operations will be atomic. Here is a simple example : the
following function will multiply an n by n matrix with a vector.

    void Matvec(double **A, int n, double *X, double *Y)
    {
       double tmp;

       #pragma HPC_INDEPENDENT, PRIVATE tmp
       for(int i = 0; i < n; i++){
          tmp = 0;
          #pragma HPC_INDEPENDENT
          for(int j = 0; j < n; j++){
             #pragma HPC_REDUCE.
             tmp += A[i][j]*X[j];
             }
          y[i] = tmp;
       }
    }
    

Benjamin Temko
Last modified: Thu Oct 9 11:43:48 EST 1997