In many parallel codes, the problem space is divided in a multi-dimensional grid, where the computations are performed. When the computations on the grid are independent one from another, it is possible to divide the work among multiple resources (e.g. CPUs). This pattern typically results in codes with multi-nested loops, iterating over the grid space.
The following pseudo-code shows the structure of the nested loops. An outer and two nested loops with different sizes (Nk, Nj, Ni) compute work on a three-dimensional array.
DO K = 1, Nk DO J = 1, Nj DO I = 1, Ni !! work to do END DO END DO END DO
How to use:
For this kernel, both the best-practice and patterns codes can be build with Makefile command
make which generates an executable file. To run the code, first define the number of threads to be used and then launch the application, for example replace Ni, Nj, Nk and Niter in the following, where these are respectively the number of iterations for the innermost, middle and outer OpenMP loop, and number of repeats of the very outer loop.
export OMP_NUM_THREADS=4; ./main.exe Ni Nj Nk Niter