You should notice the following files. Note: Most of these are simple example files. Their primary purpose is to demonstrate the basics of how to parallelize a code with OpenMP. Most execute in a second or two.
4. Run your hello executable and notice its output.
Is it what you expected? As a comparison, you can compile and run the provided omp_hello.c or omp_hello.f example program.
How many threads were created? By default, the Intel and GNU compilers will create 1 thread for each core. The PGI compiler will create only 1 thread total.
For the remainder of this exercise, you can use the compiler command of your choice unless indicated otherwise.
Compilers will differ in which warnings they issue, but all can be ignored for this exercise. Errors are different, of course.
6. Vary the number of threads and re-run Hello World
Explicitly set the number of threads to use by means of the OMP_NUM_THREADS environment variable:
setenv OMP_NUM_THREADS 8
Your output should look something like below.
Hello World from thread = 0
Hello World from thread = 3
Hello World from thread = 2
Number of threads = 8
Hello World from thread = 6
Hello World from thread = 1
Hello World from thread = 4
Hello World from thread = 7
Hello World from thread = 5
Run your program several times and observe the order of print statements. Notice that the order of output is more or less random.
Lawrence Livermore National Laboratory
7000 East Avenue • Livermore, CA 94550 | LLNL-WEB-458451
Operated by the Lawrence Livermore National Security, LLC for the
Department of Energy's National Nuclear Security Administration
Learn about the Department of Energy's Vulnerability Disclosure Program