Created
June 9, 2015 08:56
-
-
Save tilast/b782521623db5df374fb to your computer and use it in GitHub Desktop.
openmp
This file contains 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 <omp.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define N 10 | |
int main() | |
{ | |
srand(time(NULL)); | |
double *array = (double*)malloc(sizeof(double) * N); | |
for(int i = 0; i < N; ++i) | |
{ | |
array[i] = rand() % 100 - 50; | |
printf("%lf\n", array[i]); | |
} | |
#pragma omp parallel for | |
for(int i = 0; i < N; ++i) | |
{ | |
if(i % 2 == 1) | |
{ | |
array[i] = 0; | |
} | |
} | |
printf("\n"); | |
for(int i = 0; i < N; ++i) | |
{ | |
printf("%lf\n", array[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment