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.
To compile this code, run the following:
gcc -o omp_helloc -fopenmp omp_hello.c
$ export OMP_NUM_THREADS=2
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.
Hands-on course on scientific computing utilizing High Performance Computing (HPC). The goal main of this course is to introduce you with the HPC systems and its software stack: Linux, Slurm, PBS, C/C++, OpenMPI, MPI and CUDA. Revised for 2021.