Shared memory programming.
OpenMP: Quick reference (3.1, 4.0, 4.5, 5.0), home page, tutorial (LLNL).Tools
> icpc -c -qopenmp
-guide *.cpp 2> gap.txt
make gap_par_report
.#pragma ivdep
pgc++ -mp
-Mnodepchk *.cpp
#pragma pgi nodepchk
> sudo apt install libomp5 libomp-dev libomp-doc
> export OMP_NUM_THREADS=4
How to OpenMP-parallelize the inner product:
Original code for inner product:double scalar(const int N, const double x[], const double y[]) { double sum = 0.0; for (int i=0; i<N; ++i) { sum += x[i]*y[i]; } return sum; }
int main()
{
...
double s = scalar(n,a,b);
...
}
double scalar(const unsigned int N, const double x[], const double y[]) { double sum = 0.0; unsigned int i; #pragma omp parallel for private(i) shared(x,y) schedule(static) reduction(+:sum) for (i = 0; i < N; ++i) { sum += x[i] * y[i]; } return sum; }
int main(int argc, char **argv) {
... {
double s = scalar(N, x, y);
}
...
}
g++ -fopenmp
skalar.cpp
icpc -qopenmp
skalar.cpp (also
possible:
icpc -fopenmp
skalar.cpp )
pgc++ -mp
skalar.cpp
clang++ -fopenmp
skalar.cpp