void parallelAddition (unsigned N, const double *A, const double *B, double *C)
{
unsigned i;
#pragma omp parallel for shared (A,B,C,N) private(i) schedule(static)
for (i = 0; i < N; ++i)
{
C[i] = A[i] + B[i];
}
}
This example adds two vector (A
and B
into C
) by spawning a team of threads (specified by the OMP_NUM_THREADS
environtment variable, for instance) and assigning each thread a chunk of work (in this example, assigned statically through the schedule(static)
expression).
See remarks section with respect to the private(i)
optionality.