In order to successfully complete this assignment you need to participate both individually and in groups during class. Have one of the instructors check your notebook and sign you out before leaving class. Turn in your assignment using D2L.
ICA 13: OpenMP Critical Sections and Basic Loops
1. Pre class review
✅ DO THIS: Discuss and summarize the importance of synchronization with your group and record the key points here.
Record key points here
2. Scheduling Shared memory jobs
Today we are going to submit OpenMP jobs to the cluster and verify they run properly by inspecting their output. To start lets use the classic OMP hello world program:
#include "omp.h"
#include "stdio.h"
int main()
{
#pragma omp parallel
{
int ID = omp_get_thread_num();
printf("hello(%d)",ID);
printf(" world(%d) \n",ID);
}
}
✅ DO THIS: Compile and test the above program on the command line. Make a submission script and run the program with 7 cores on the HPCC.
HINT: Try adding the srun
command before your parallel commands. This command does some checks to make sure everything is running properly. Although not required for OpenMP, it definitely comes in handy with GPU and MPI jobs.
3. Benchmark Loops
✅ DO THIS: Write a more advanced submission script that requests 20 shared memory cores and uses your homework solution (HW 1). Include a bash loop in the script which will change the OMP_NUM_THREADS
environment variable. The first iteration of the loop should run on one core, the second should run on 2, and continue until the code is running on all cores. Output the timing information in such a way that it will be easy to grep
the results and graph them in python.
Graph Results: Graph your test results.
CHALLENGE: For an advanced challenge see if you can rewrite the script to avoid idle cores. In this case you would want to run the 20 core test by itself but 1 and 19 could run at the same time just like 2 and 18.
Congratulations, we’re done!
Have one of the instructors check your notebook and sign you out before leaving class. Turn in your assignment using D2L.
Written by Dr. Dirk Colbry, Michigan State University (Updated by Dr. Nathan Haut in Spring 2025)

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.