Created
June 9, 2016 10:47
-
-
Save petarjs/16d2564f74767e888a14b69a0cbd1967 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <omp.h> | |
void main(int argv, char** argc) { | |
int i; | |
int sum = 0; | |
int a[100]; | |
int b[100]; | |
for(i=0; i<100; i++) { | |
a[i] = 2*i + 1010; | |
b[i] = 4*i + 130; | |
} | |
// sequential | |
for(i=0; i<100; i++) { | |
sum += a[i] * b[i]; | |
} | |
// paralel | |
#pragma omp parallel for { | |
for(i=0; i<100; i++) { | |
#pragma omp critical | |
sum += a[i] * b[i]; | |
} | |
} | |
// parallel reduction | |
#pragma omp parallel for recuction(+:sum) { | |
for(i=0; i<100; i++) { | |
sum += a[i] * b[i]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment