IT301 Lab Exercise 5
IT301 Lab Exercise 5
Name :
Roll No. :
Execute following programs and put screen shots of the output. Write analysis of the result before
uploading in IRIS as a single pdf file. For programming exercises, write the code and also put a
screenshot of the results.
#include <sys/time.h>
#include <stdlib.h>
double time_overhead;
Just before starting parallel region code , note down the time(start time)
gettimeofday(&TimeValue_Start, &TimeZone_Start);
gettimeofday(&TimeValue_Final, &TimeZone_Final);
Calculate the overhead time as follows:
Example: Execute the program and compare sequential and parallel executions. [sequential
result : 1Mark + Parallel Execution 1 Mark=2 Marks]
#include <stdio.h>
#include <sys/time.h>
#include <omp.h>
#include <stdlib.h>
int main(void)
{
struct timeval TimeValue_Start;
struct timezone TimeZone_Start;
struct timeval TimeValue_Final;
struct timezone TimeZone_Final;
long time_start, time_end;
double time_overhead;
double pi,x;
int i,N;
pi=0.0;
N=1000;
gettimeofday(&TimeValue_Start, &TimeZone_Start);
#pragma omp parallel for private(x) reduction(+:pi)
for(i=0;i<=N;i++)
{
x=(double)i/N;
pi+=4/(1+x*x);
}
gettimeofday(&TimeValue_Final, &TimeZone_Final);
time_start = TimeValue_Start.tv_sec * 1000000 + TimeValue_Start.tv_usec;
time_end = TimeValue_Final.tv_sec * 1000000 + TimeValue_Final.tv_usec;
time_overhead = (time_end - time_start)/1000000.0;
printf("\n\n\tTime in Seconds (T) : %lf\n",time_overhead);
pi=pi/N;
printf("\n \tPi is %f\n\n",pi);
}
2. Write a sequential program to add elements of two arrays (c[i]=a[i]*b[i]. Convert the same program for
parallel execution. Initialize arrays with random numbers. Consider an array size as 10k, 50k and 100k.
Analyse the result for maximum number of threads and various schedule() functions. Based on observation,
perform analysis of the total execution time and explain the result by plotting the graph. [increase array size
Schedule() Total Execution Total Execution Total Execution Total Execution time
time for number time for number time for number for number of
of iterations 5K of iterations 10K of iterations 50K iterations 100K
Sequential execution
static
Static, chunksize
Dynamic, chunksize
Guided
runtime
Plot the graph using any software and write your observation.
Observation =1 Marks
Total = 8 Marks