Skip to content

Simple Example

Adding OpenMP

// Base Example

int main()
{




    {
        printf("hello, world!\n"); // Execute in parallel
    } // Implicity join
    return 0;
}
#include <omp.h>

int main()
{
    omp_set_num_threads(16); // OPTIONAL - Can also use 
                            // OMP_NUM_THREADS environment variable

    #pragma omp parallel
    {
        printf("hello, world!\n"); // Execute in parallel
    } // Implicity join
    return 0;
}
#include <omp.h>

int main()
{
    omp_set_num_threads(16); // OPTIONAL - Can also use 
                            // OMP_NUM_THREADS environment variable

    #pragma omp parallel num_threads(8) // Restrict team size locally
    {
        printf("hello, world!\n"); // Execute in parallel
    } // Implicity join
    return 0;
}

Compiling

gcc -fopenmp ...
icc -openmp ...