Workshops differ in how this is done. The instructor will go over this beforehand.
In your home directory, create a pthreads subdirectory for the example codes, copy the example codes and then cd into your pthreads subdirectory and cd to it. Then copy the Pthreads example codes.
mkdir pthreads cp /usr/global/docs/training/blaise/pthreads/* ~/pthreads cd pthreads
You should notice quite a few files. The table below lists and describes these files.
|Data decomposition by loop distribution. Fortran example only works under IBM AIX: see comments in source code for compilation instructions.|
|Demonstrates how to explicitly create pthreads in a detached state.|
|Mutex variable example using a dot product program. Both a serial and pthreads version of the code are available.|
|Simple "Hello World" example|
|"Hello World" pthreads program demonstrating thread scheduling behavior.|
|One correct way of passing the pthread_create() argument.|
|Another correct method of passing the pthread_create() argument, this time using a structure to pass multiple arguments.|
|Demonstrates how to explicitly create pthreads in a joinable state for portability purposes. Also shows how to use the pthread_exit status parameter.|
|A "series" of programs which demonstrate the progression for a serial dot product code to a hybrid MPI/Pthreads implementation. Files include the serial version, Pthreads version, MPI version, hybrid version and a makefile.|
|Examples with bugs.|
icc -pthread -o hello hello.c pathcc -pthread -o hello hello.c pgcc -lpthread -o hello hello.c gcc -pthread -o hello hello.c
Try these other pthreads codes before moving on to the mpithreads or bugX.c sets of codes. Some of these are similar to what was shown in the tutorial and some aren't. Compile them as you did for hello.c, but NOTE that you will need to include the -lm flag if it complains about references to sin() and tan().
Part of the learning process is to see what happens when things go wrong. There are many things that can go wrong when developing pthreads programs. The bugX.c series of programs demonstrate just a few. See if you can figure out what the problem is with each case and then fix it.
Use icc -pthread to compile each code as appropriate.
The buggy behavior will differ for each example. Some hints are provided below.
|bug5.c||Threads die and never get to do their work|
|Wrong answer - run it several times to prove this|
These codes implement a dot product calculation and are designed to show the progression of developing a hybrid MPI / Pthreads program from a a serial code. The problem size increases as the examples go from serial, to threads/mpi to mpi with threads.
Suggestion: simply making and running this series of codes is rather unremarkable. Using the available lab time to understand what is actually happening is the intent. The instructor is available for your questions.
make -f mpithreads.makefile
Be sure to examine the makefile so that you are familiar with the actual compiler commands used.
|Serial version - no threads or MPI|
|Threads only version of the code using 8 threads|
srun -n8 -ppReserved mpithreads_mpi
|MPI only version with 8 tasks running on a single node in the special workshop pool|
srun -N4 -ppReserved mpithreads_both
|MPI with threads using 4 tasks running on 4 different nodes, each of which spawns 8 threads, running in special workshop pool|
This completes the exercise.
|Please complete the online evaluation form if you have not already done so for this tutorial.|
Where would you like to go now?