Tutorial by Examples

There are many compilers that support different versions of the OpenMP specification. OpenMP maintains a list here with the compiler that support it and the supported version. In general, to compile (and link) an application with OpenMP support you need only to add a compile flag and if you use the ...
#include <omp.h> #include <stdio.h> int main (int argc, char *argv[]) { #pragma omp parallel { printf ("Hello world! I'm thread %d out of %d threads.\n", omp_get_thread_num(), omp_get_num_threads()); } return 0; } This code simply ...
double res[MAX]; int i; #pragma omp parallel { #pragma omp for for (i=0;i< MAX; i++) { res[i] = huge(); } } The for loop will be executed in parallel. huge() is some method which can take too long to get execute. OpenMP supports a shortcut to write the ab...
#include <omp.h> void main () { int i; double ZZ, func(), res=0.0; #pragma omp parallel for reduction(+:res) private(ZZ) for (i=0; i< 1000; i++){ ZZ = func(I); res = res + ZZ; } } In the last line: Actually added to a private ...

Page 1 of 1