User Tools

Site Tools


cs415pdc:lab5

OpenMP Basics

Purpose - learn to use programs from the CSinParallel project and others to explore the basics of OpenMP programming. But first, a word about threads and cores:

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, in 2017 our Intel i7 processors were quadcore machines, but when we issued this command:

$ nproc

it reported 8. Try this yourself and record what our current machines report.

Why the discrepancy? Multicore computer systems distinguish between logical and physical processor cores. For example, Intel uses hyperthreading to fool 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 even more information about the processor by running:

$ lscpu

From the information reported, record the Architecture, # of CPUs, # threads per core, # CPUs per socket (there is usually just 1 socket), and the reported clock speed.

Linux records more information than you probably ever wanted to know about the individual cores in a file called /proc/cpuinfo; to give it a quick look, do:

$ less /proc/cpuinfo

Here we're just displaying a file containing information about each processor core on the current system.

You can query this information in MacOS as well, using sysctl. For example the command:

$ 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

Oh, and since we're talking about MacOS here, you should know the default GCC installation does not typically include the OpenMP extension. To compile an OpenMP program, use clang-omg. For example:

$ clang-omp -g -Wall -fopenmp omp_helloBB.c -o hello 

OpenMP Basics

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. Click the “Next Topic” and run through the patternlets on this page (Patterns 0 through 5). Follow the instructions given in each file's comment header, recording the results of each run. Turn in your results.

cs415pdc/lab5.txt · Last modified: 2022/03/22 20:29 by scarl