Skip to content
Snippets Groups Projects
helloworld-sections.c 647 B
#include <omp.h>
#include <stdio.h>
 
int main(void)
{
int tid, nthreads;

#pragma omp parallel  private(tid) shared(nthreads)
{

#pragma omp master
nthreads = omp_get_num_threads();

#pragma omp sections
{

#pragma omp section
    {
    tid = omp_get_thread_num();
    printf("Hello world from section 1 thread %d of %d\n", tid, nthreads);
    }
#pragma omp section
    {
    tid = omp_get_thread_num();
    printf("Hello world from section 2 thread %d of %d\n", tid, nthreads);
    }

#pragma omp section
    {
    tid = omp_get_thread_num();
    printf("Hello world from section 3 thread %d of %d\n", tid, nthreads);
    }
}
}

    return 0;
}