CS402 LAB SESSION 2: OPENMP
1. Introduction
OpenMP (Multiprocessing) is an API and runtime which enables the program- ming of multiple processing cores with shared memory. The API is a collection of functions and pragmas; the former allows the querying of information such as the number of active threads, and the latter allows the definition of parallel regions. In these parallel regions, threads are spawned by the OpenMP runtime and the code within is executed on multiple cores. These threads are then able to communicate with each other using shared memory.
This lab will give a basic introduction on how to use the OpenMP API to exploit parallelism in applications.
Copyright By PowCoder代写 加微信 powcoder
2. Remote Working
As with the first lab sheet, you will once again be working remotely for this lab session. We recommend that you make use of the DCS managed Batch Compute System1 for completing the following lab exercises. This section will explain how to get started with the DCS cluster, and how you can make use of it to run any programs you write during completion of this lab sheet.
First, connect to one of the DCS Login/Remote nodes using one of the follow- ing two commands (where u1XXXXXX is be replaced by your username and nn in remote-nn is replaced by the last two digits of your username):
Then, connect to the login node of the cluster, kudu: $ ssh kudu
Once you have connected to kudu you will see that you can access all of the files that you have saved in your DCS file system. It’s important that you do not run your C programs directly on the login node, but instead submit them using a batch submission script. In order to do this, firstly load the necessary environment module for the compiler using the following command:
1Further information on the Batch Compute System can be found here: https://warwick. ac.uk/fac/sci/dcs/intranet/user_guide/batch_compute
2 CS402 LAB SESSION 2: OPENMP
$ module load cs402-mpi
As was the case in the previous lab sheet, this will give you access to the required compilers. Once you have compiled your code, it can be submitted for execution using a submission script. A sample job submission script is provided below:
#!/bin/bash
#SBATCH –job-name=example-job # Job name for tracking
#SBATCH –partition=cs402
#SBATCH –nodes=1
#SBATCH –ntasks-per-node=1
#SBATCH –cpus-per-task=2
#SBATCH –time=00:01:00
module load cs402-mpi
srun ./
# Partition you wish to use
# Number of compute nodes used by your job
# Number of CPU cores used on each node
Listing 1: A sample Batch Script for job submission (submit.sbatch)
Save this script to a file called submit.sbatch – you can then copy/adjust this script as necessary once you begin to tackle the lab exercises. For example, if you take a look at the Hello World in OpenMP exercise (Section 4.1), it might be sensible to change the job name to hello-world. The final line of your script would also need to be changed to srun ./helloWorldOMP. If you want to run your programs using more cores/threads, you can adjust the cpus-per-task parameter in the script. The compute nodes that you will be using on kudu have 12 CPU cores (dual socket, with 6 cores per socket), however for the majority of the exercises in this lab sheet, running your code using only 2 OpenMP threads should be appropriate.
When you have successfully prepared your script, your job can be submitted using the following command (where