Parallel Programming with OpenMP - Tim Mattson

Introduction

This project explores the use of OpenMP for parallel programming in C/C++ via the Intro to OpenMP tutorial by Tim Mattson, Intel Corp.

  • Watch the course video.
  • Read the course notes.
  • Do the exercise files.
  • A useful OpenMP 3.1 API C/C++ syntax quick reference card.

We provide the code solutions to OpenMP coding exercises in C/C++. All of our code is built using CMake and is containerized using Dockers.

The following tools will be used in this project:

  • C/C++
  • OpenMP
  • Docker

Learning Outcome

Find the source code in the repository.

At the end of this project, we should be able to:

  • Use OpenMP in C/C++ for parallel programming in shared memory applications.
  • Build C/C++ code with CMake and run it in a Docker container.

Project Structure

The project structure is as follows:

OpenMP-Tim-Mattson                   # Repository root
├── apps                             # Executables for each exercises
|   ├── CMakeLists.txt               # CMake build for executables
|   ├── linked.c                     
|   ├── mandel.c
|   ├── pi_mc.c
|   ├── prodCons.c           
|   └── tutorial.c                   
├── assets                           # Assets
|   ├── Intro_To_OpenMP_Mattson.pdf  # Tutorial slides
|   └── OpenMP3.1-CCard.pdf          # OpenMP reference card
├── libs                             # Local libraries
│   ├── computepi                     
|   │   ├── CMakeLists.txt           # Library-level CMake build file
|   │   ├── computepi.cpp            # Source file
|   │   └── computepi.h              # Header file
│   ├── helloworld                    
|   │   ├── CMakeLists.txt           # Library-level CMake build file
|   │   ├── helloworld.cpp           # Source file
|   │   └── helloworld.h             # Header file
│   └── random                       
|       ├── CMakeLists.txt           # Library-level CMake build file
|       ├── random.c                 # Source file
|       └── random.h                 # Header file
├── .dockerignore
├── .gitignore
├── CMakeLists.txt                   # Top-level CMake build file
├── docker-compose.yml               # Docker deployment
├── dockerfile                       # To create Docker container
└── README.md                                 

List of exercises

For easy reference, each solution code is named according to the slide on which they appear in the course notes. Instructions to build, setup commands, and to run the solutions for each exercise is given in the following table.

Exercise Instructions to run
Slide 38 - Parallel 'Hello World' program 1) File: `/apps/tutorial.cpp`
2) Build: `docker build -t openmp .` on `Dockerfile`
3) Set: `command: /src/bin/tutorial` in `docker-compose.yaml` file
4) Run: `docker-compose up` on `docker-compose.yaml` file
Slide 48 - Compute Pi in serial
Slide 52 - Compute Pi in parallel with false sharing
Slide 57 - Compute Pi in parallel with padding
Slide 69 - Compute Pi in parallel with synchronization
Slide 88 - Compute Pi with WorkSharing
Slide 119 - Mandel Brot 1) File: `/apps/mandel.c`
2) Build: `docker build -t openmp .` on `Dockerfile`
3) Set: `command: /src/bin/mandel` in `docker-compose.yaml` file
4) Run: `docker-compose up` on `docker-compose.yaml` file
Slide 124 - Linked list computed serially 1) File: `/apps/linked.c`
2) Build: `docker build -t openmp .` on `Dockerfile`
3) Set: `command: /src/bin/linked` in `docker-compose.yaml` file
4) Run: `docker-compose up` on `docker-compose.yaml` file
Slide 128 - Linked list in parallel without Tasks
Slide 143 - Linked list in parallel with Tasks
Slide 166 - Producer Consumer 1) File: `/apps/prodCons.c`
2) Build: `docker build -t openmp .` on `Dockerfile`
3) Set: `command: /src/bin/prodCons` in `docker-compose.yaml` file
4) Run: `docker-compose up` on `docker-compose.yaml` file
Slide 177 - Parallel Monte Carlo computation of PI 1) File: `/apps/pi_mc.c`
2) Build: `docker build -t openmp .` on `Dockerfile`
3) Set: `command: /src/bin/pi_mc` in `docker-compose.yaml` file
4) Run: `docker-compose up` on `docker-compose.yaml` file
Slide 181 - Thread safe random number generator
Slide 185 - Leap frog method to avoid overlapped random number sequence

Updated:

Leave a comment