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:
mkdir pthreads
cp /usr/global/docs/training/blaise/pthreads/* ~/pthreads
cd pthreads
You should notice a number of files as shown in the tables below.
File Name</span> | Description</span> | |
---|---|---|
arrayloops.c arrayloops.f | Data decomposition by loop distribution. Fortran example only works under IBM AIX: see comments in source code for compilation instructions. | |
condvar.c | Condition variable example file. Similar to what was shown in the tutorial | |
detached.c | Demonstrates how to explicitly create pthreads in a detached state. | |
dotprod_mutex.c dotprod_serial.c | Mutex variable example using a dot product program. Both a serial and pthreads version of the code are available. | |
hello.c | Simple "Hello World" example | |
hello32.c | "Hello World" pthreads program demonstrating thread scheduling behavior. | |
hello_arg1.c | One correct way of passing the pthread_create() argument. | |
hello_arg2.c | Another correct method of passing the pthread_create() argument, this time using a structure to pass multiple arguments. | |
join.c | Demonstrates how to explicitly create pthreads in a joinable state for portability purposes. Also shows how to use the pthread_exit status parameter. | |
mpithreads_serial.c mpithreads_threads.c mpithreads_mpi.c mpithreads_both.c mpithreads.makefile | 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. |
Visit the Compilers Currently Installed on LC Platforms webpage.
Click on the name of the workshop Linux cluster (sierra) in the summary table near the top of the page. This will take you to a table of available compilers.
You can also view the available compilers in the Compilers section of the Linux Clusters Overview tutorial.
Now, in your cluster login window, try the use -l compilers
command to display available compilers. You should see GNU, Intel and PGI compilers - several versions of each.
dpkg-defaults
command and look for the asterisk.Using your favorite text editor (vi/vim, emacs, nedit, gedit, nano…) open a new file - call it whatever you’d like.
pthread.h
header filepthread_exit
to finish.pthread_exit
as the last thing it does
If you need help, see the provided hello.c file.icc -pthread -o hello myhello.c
pgcc -lpthread -o hello myhello.c
gcc -pthread -o hello myhello.c
When you get a clean compile, proceed.
hello
executable and notice its output. Is it what you expected? As a comparison, you can compile and run the provided hello.c example program.Review the example code hello32.c
. Note that it will create 32 threads. A sleep();
statement has been introduced to help insure that all threads will be in existence at the same time. Also, each thread performs actual work to demonstrate how the OS scheduler behavior determines the order of thread completion.
Compile and run the program. Notice the order in which thread output is displayed. Is it ever in the same order? How is this explained?
Review the hello_arg1.c
and hello_arg2.c
example codes. Notice how the single argument is passed and how to pass multiple arguments through a structure.
Compile and run both programs, and observe output.
Now review, compile and run the bug3.c
program. What’s wrong? How would you fix it? See the explanation in the bug programs table above.
Review, compile (for gcc include the -lm
flag) and run the bug5.c
program.
What happens? Why? How would you fix it?
See the explanation in the bug programs table above.
Review, compile (for gcc include the -lm
flag) and run the join.c
program.
Modify the program so that threads send back a different return code - you pick. Compile and run. Did it work?
For comparison, review, compile (for gcc include the -lm flag) and run the detached.c
example code.
Observe the behavior and note there is no “join” in this example.
Review, compile and run the bug2.c program.
What happens? Why? How would you fix it?
See the explanation in the bug programs table above. Also review and try out bug2fix.c
program.