Note: this document includes both the lab 5 and 6 assignments. Jump to Lab 6 here.
In these labs we'll use programs from the CSinParallel project and others to explore the basics of OpenMP programming. But first, a word about threads and cores:
To this point we've been vague about the difference between the number of processor cores provided by the hardware and the number of cores reported by the operating system. For example, the Intel i7 is a quadcore machine, but in the Linux terminal if we issue this command:
it reports 8. Try this yourself. The same is true if we run the System Monitor program.
Why the discrepancy? Multicore computer systems distinguish between logical and physical processor cores. For example, Intel uses hyperthreading to fake the operating system into thinking there are twice as many cores available as physically on the chip. “For each processor core that is physically present, the operating system addresses two virtual (logical) cores and shares the workload between them when possible.”
You can learn way more information about the processor by running:
$ more /proc/cpuinfo
which just displays a file containing information about the processor cores on the current system.
You can query this information in MacOS as well, using sysctl:
$ sysctl -n hw.ncpu
reports 8 on a quadcore system such as my MacBook Pro. There are many different options we can give this command, for example:
$ sysctl -n hw.logicalcpu $ sysctl -n hw.physicalcpu
(By the way, since we're talking about MacOS here, the default GCC installation does not include the OpenMP extension. To compile an OpenMP program, use
omp-clang.) For example:
$ clang-omp -g -Wall -fopenmp omp_helloBB.c -o hello
As with MPI and Pthreads, the CSinParallel project includes a set of patternlets to give you an idea of how OpenMP solves the same sorts of problems. Run through the first page (Patterns 0 through 5) and follow the instructions, recording the results of each run. Turn in your results.
Add (typical C) timing code to the serial trap.c and OpenMP timing function to any of the OpenMP versions of the trapezoid rule program from Chapter 5. Run the both programs on representative input and record the results in a table. As before, when the instructions say to run the program and record the results, you need to record the average of multiple runs.