0% found this document useful (0 votes)
5 views18 pages

02 Vector

The document contains multiple implementations of a parallel program using OpenMP to perform element-wise addition of two arrays. Each implementation initializes two arrays with specific values, computes their sum, and prints the results along with the thread ID that performed the computation. The execution time for each implementation is measured and printed at the end.

Uploaded by

cs23b2017
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views18 pages

02 Vector

The document contains multiple implementations of a parallel program using OpenMP to perform element-wise addition of two arrays. Each implementation initializes two arrays with specific values, computes their sum, and prints the results along with the thread ID that performed the computation. The execution time for each implementation is measured and printed at the end.

Uploaded by

cs23b2017
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <stdio.

h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();
execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];


printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)
{

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;
startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

{
double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>
#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;


printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

}
}

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();
a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)


{

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;


int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000
int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);
}

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

}
endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]


c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;

startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for


for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

#include <stdio.h>

#include <omp.h>

#define n 100000

int main()

double a[n],b[n], c[n];

float startTime, endTime,execTime;

int i;

int omp_rank;
startTime = omp_get_wtime();

#pragma omp parallel private (i) shared (a,b,c)

#pragma omp for

for(i=0;i<n;i++)

omp_rank = omp_get_thread_num();

a[i] = i * 10.238393838389992828282926; // Use Random function and assign a[i]

b[i] = i * 152.1287228727728222728722872723; // Use Random function and assign b[i]

c[i] = a[i] + b[i];

printf("The value of a[%d] = %lf and b[%d] = %lf and result c[%d] = %lf done by worker
Thread ID = %d\n", i, a[i], i, b[i], i, c[i], omp_rank);

endTime = omp_get_wtime();

execTime = endTime - startTime;

printf("%f \n",execTime);

return(0);

You might also like