HPC - Simulate “schedule()” directives

Moreno Marzolla

Last updated: 2023-10-23

OpenMP allows the use of the schedule(static) and schedule(dynamic) clauses to assign loop iterations to OpenMP threads. The purpose of this exercise is to simulate these clauses without using the omp parallel for construct.

The file omp-schedule.c contains a serial program that creates two arrays vin[] and vout[] of length \(n\) such that vout[i] = Fib(vin[i]) for each \(i\), where Fib(k) the k-th number of the Fibonacci sequence. Fib(k) is intentionally computed using the inefficient recursive algorithm, so that the computation time varies widely depending on \(k\).

There are two functions, do_static() and do_dynamic() that perform the computation above.

  1. Modify do_static() to distribute the loop iterations as would be done by the schedule(static, chunk_size) clause, but without using a omp parallel for directive (you may use omp parallel).

  2. Modify do_dynamic() to distribute the loop iterations according to the master-worker paradigm, as would be done by the schedule(dynamic, chunk_size) clause. Again, you are not allowed to use omp parallel for, but only omp parallel.

See the source code for suggestions.

To compile:

    gcc -std=c99 -Wall -Wpedantic -fopenmp omp-schedule.c -o omp-schedule

To execute:

    ./omp-schedule [n]

Example:

    OMP_NUM_THREADS=2 ./omp-schedule

Files