OPEN CATALOG

Best practices for performance

forall pattern

A forall is a loop that updates the elements of an array, each iteration updating a different element of the array.

for (i=0; i<N; ++i) {
    A[i]=...
} 

A is the array variable and i is the loop index variable, which can be determined at compile-time.

Example #

C

 for (i=0; i<n; ++i) {
     D[i] = a * X[i] + Y[i];
 } 

Fortran

 do (i=1, n)
    D(i) = a * X(i) + Y(i)
 end do

Parallelizing foralls into parallel foralls with OpenMP or OpenACC #

OpenMP and OpenACC provide built-in support for the computation of a forall pattern in parallel. The programmer needs to identify the forall pattern and provide the relevant directives to the compiler (the parallel loop directive in both OpenMP and OpenACC).