In this studio, you will:
Configure the way that OpenMP executes a parallel program
Please complete the required exercises below, as well as any optional enrichment exercises that you wish to complete.
As you work through these exercises, please record your answers in a text file. When finished, submit your work by sending your text file and source code to dferry@slu.edu with the phrase OpenMP Part 2 in the subject line.
Make sure that the name of each person who worked on these exercises is listed in the first answer, and make sure you number each of your responses so it is easy to match your responses with each exercise.
printf()
statement.
Use the function omp_get_thread_num()
to access the currently
executing thread's number. Copy and paste your program output.
Note- the OpenMP functions are not included in Linux's man pages, but you
can access a reference sheet at the following link. Be sure to include
omp.h
and compile with -fopenmp
http://www.openmp.org/mp-documents/OpenMP-4.5-1115-CPP-web.pdf
omp_get_max_threads()
. Print out your result.
omp_set_num_threads()
, and then re-run your loop from the first
exercise. Copy and paste your results.
sleep()
function to cause the first five loop iterations to sleep for one second. That is,
inside your loop insert the statement: if ( index <= 4 ) sleep(1);
.
What do you think will happen? If the work is split evenly across five threads then the program should take about one second. However, if the first five loop iterations are allocated to a single thread, then the program will take about five seconds.
Run your program and confirm or deny your hypothesis. Time your program with
the time
command.
#pragma omp parallel for schedule( dynamic, 1 )
How long does your program take now?
schedule()
modifier is
called the chunk size. Modify this value and observe the effects. What
do you think the chunk size specifies?