Skip to content

Instantly share code, notes, and snippets.

@niklasfi
Last active December 20, 2015 09:29
Show Gist options
  • Save niklasfi/6107879 to your computer and use it in GitHub Desktop.
Save niklasfi/6107879 to your computer and use it in GitHub Desktop.
#include <omp.h>
int main(){
//Algorithm alg(double* m) uses m to calculate result
double sum=0;
int i;
#pragma omp parallel for
for(i=0; i < 1000; ++i)
double* m = malloc(sizeof(double) * 20);
sum+=alg(m);
free(m);
}
//Algorithm alg(double* m) uses m to calculate result
double sum=0;
int i;
double* m = malloc(sizeof(double) * 20 * omp_num_threads());
#pragma omp parallel for
for(i=0; i < 1000; ++i)
sum+=alg(m+20*omp_thread_num());
}
free(m);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment