A Template for multi-threaded programming on CPU.

This is a template for programming a multi-core CPU system in the AXEL cluster. This example creates 4 threads each add the it's thread ID to the sequence [0, 1, 2, .... N]. Resources related in this document are located in the smp directory after extracting the axel_template package.

Parallelism is achieved by segmenting the loop using fork-join model. The following OpenMP constructs are added to the reference design just outside the main loop.

  omp_set_num_threads(NUM_THREADS);
#pragma omp parallel default(shared) private(i, id, pn)
  {
    id = omp_get_thread_num();
    pn = omp_get_num_threads();
    printf("I am thread %d out of %d.\n", id, pn);
#pragma omp for schedule(static,CHUNK) nowait
.
// main loop here
.
  }

The program utilizing OpenMP must include the omp.h header file and be compiled with option -fopenmp.