Let us write a simple "Hello, World!" program where the text will be placed in the parallel region and will be printed several times by different threads.
We will use OpenMP C/C++ Application Program Interface (API)
C Program
#include <stdio.h> #include <omp.h> int main() { #pragma omp parallel { printf("Hello, World! From -> Thread %d.\n",omp_get_thread_num()); } return 0; }
Output
$ vim hello.c $ gcc -fopenmp hello.c -o hello $ ./hello Hello, World! From -> Thread 2. Hello, World! From -> Thread 3. Hello, World! From -> Thread 0. Hello, World! From -> Thread 1.
# of printf() may differ..