Skip to content

Instantly share code, notes, and snippets.

@tilast
Created June 9, 2015 08:56
Show Gist options
  • Save tilast/b782521623db5df374fb to your computer and use it in GitHub Desktop.
Save tilast/b782521623db5df374fb to your computer and use it in GitHub Desktop.
openmp
#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