Commit 6a6c107a authored by Alejandro E. Rendon's avatar Alejandro E. Rendon
Browse files

Time in Omp operation

parent 867ffdff
......@@ -22,12 +22,19 @@ void add(int *a, int *b, int *c, int n) {
c[i] = a[i] + b[i];
}
void addOmp(int *a, int *b, int *c, int n) {
#pragma omp parallel for
for (int i = 0; i < n; i++)
c[i] = a[i] + b[i];
}
int main(int argc, char const *argv[]) {
if (argc < 2)
cout << "I need more inputs" << endl;
else {
int vec_size = stoi(argv[1]);
int *a, *b, *c;
double begin, end;
a = (int *)malloc(vec_size * sizeof(int));
b = (int *)malloc(vec_size * sizeof(int));
......@@ -39,10 +46,15 @@ int main(int argc, char const *argv[]) {
//print("a = ", a, vec_size);
//print("b = ", b, vec_size);
double begin = omp_get_wtime();
begin = omp_get_wtime();
add(a, b, c, vec_size);
double end = omp_get_wtime();
cout << end - begin << endl;
end = omp_get_wtime();
cout << "Sequential -> " << end - begin << endl;
begin = omp_get_wtime();
addOmp(a, b, c, vec_size);
end = omp_get_wtime();
cout << "OpenMP -> " << end - begin << endl;
//print("c = ", c, vec_size);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment