Course


OpenMP- Hello world!

Hands-on hello world! program with OpenMP.

Hello world!

Let's print the statement "Hello world!" using all the threads. Here the variable tid gives your thread id. Our server has only two threads. Threfore, the Hello world! will be printed twice.

C++ (9.2.0)
  • Show Input  

How to compile and run?

To compile this code, run the following:

gcc -o omp_helloc -fopenmp omp_hello.c
$ export OMP_NUM_THREADS=2
$ ./omp_helloc
Hello World from thread = 0
Hello World from thread = 1
Number of threads = 2

Note that the environment variable OMP_NUM_THREADS was used to specify number of threads.