Lab # 1
Lab # 1
Lab # 1
Objectives:
1- Know how to install unix operating systems in your computer
2- Know how to install gcc and g++ compilers
3- Know how to configure OpenMP
4- Know how to compile C and C++ program codes using OpenMP
Configuring OpenMP:
We can check whether the OpenMP features are configured into our
compiler or not, using the command:
If OpenMP is not featured in the compiler, we can configure it use using the
command:
Setting the number of threads:
In OpenMP, before running the code, we can initialize the number of
threads to be executed using the following command. Here, we set the
number of threads to be getting executed to be 8 threads.
if (tid == 0) {
Compile command:
gcc -o program.exe -fopenmp program1.c
*** If “stdio.h: No such file or directory” error appears write the following
command in Ubuntu terminal:
Execute command:
./program.exe
nproc
or
cat /proc/cpuinfo
or
lscpu
In case of asking to use –fix-broken or –fix-missing during the
installation of any package use the following command to try to fix it:
1) What is the UNIX command that can be used to compile this C program
code?
#include <stdio.h>
#include <omp.h>
int main() {
int a[N];
//initialize
a[i] = i;
//compute sum
local_sum =0;
local_sum += a[i];
}
sum += local_sum;
1) What is the UNIX command that can be used to compile this C program
code?
#include <stdlib.h>
#include <omp.h>
/**
* @details This code prints the number of threads at two specific locations:
**/
omp_set_num_threads(8);
return EXIT_SUCCESS;}
1) What is the UNIX command that can be used to compile this C program
code?
return 0;
}
Exercise 4: Name the C program code in the below table as “program4.c”.
Then, answer the following questions:
1) What is the UNIX command that can be used to compile this C program
code?
#include <stdio.h>
#include <stdlib.h>
#define MAX_THREADS 8
double step;
int i,j;
double x;
omp_set_num_threads(j);
sum = 0.0;
x = (i+0.5)*step;
pi = step * sum;
}
Exercise 5: Name the C program code in the below table as “program5.c”.
Then, answer the following questions:
1) What is the UNIX command that can be used to compile this C program
code?
#include <stdio.h>
#include <stdlib.h>
#define MAX_THREADS 8
int j;
omp_set_num_threads(j);
sum=0;
start=0;
sum +=i;
}
}}