SKR 3308 Lab Assignment 4 OpenACC

SKR 3308 Sem II 2022/2023
Lab 5 – OpenACC

Objectives

i. To practice students with OpenACC library with Simple Load Balancing Program

Steps to execute OpenACC program
1. Set Enviroment Variables for nvc Compiler, write all the commands.

$ NVARCH=`uname -s`_`uname -m`; export NVARCH
$ NVCOMPILERS=/opt/nvidia/hpc_sdk; export NVCOMPILERS
$ MANPATH=$MANPATH:$NVCOMPILERS/$NVARCH/21.2/compilers/man; export MANPATH
$ PATH=$NVCOMPILERS/$NVARCH/21.2/compilers/bin:$PATH; export PATH

2. Compile for serial, multicore and gpu. Follow the step as below

· Compile on host (serial execution): nvc acc.c -o acc_host -acc=host -Minfo=accel

· Compile on multicore execution: nvc acc.c -o acc_core -acc=multicore -Minfo=accel

· Compile on GPU execution: nvc acc.c -o acc_gpu -acc=gpu -Minfo=accel

3. Run the program acc. c and record the execution time differences between three compilations. (Use time tools to record the time)

4. Print screen and comment your results.

#include
#include
#include
#include

#define LOAD 10000000

int main(int argc, char *argv[]){

double summation_array[100];
struct timeval start_chronos, end_chronos, elapsed_chronos;

gettimeofday(&start_chronos, NULL);

#pragma acc kernels //Step 3.3.1.A
for(int i=0; i<100; i++){ #pragma acc loop independent //Step 3.3.1.B for(int j=0; j