[Openmp-dev] OpenMP slower than serial ( sometmes )
Victor Rodriguez
vm.rod25 at gmail.com
Tue Sep 16 12:05:12 PDT 2014
HI
I am new in Open MP and willing to learn . I am reading the Open MP
documentation and this tutorial
https://computing.llnl.gov/tutorials/openMP/exercise.html
I am really new to parallel programming , I have been searching over
diferent examples and at the end I am trying to create a simple loop faster
in omp than without, here is my code:
#include
<omp.h>
#include
<stdio.h>
#define N
100000
main
()
{
int
i;
float a[N], b[N],
c[N];
/* Some initializations
*/
for (i=0; i < N;
i++)
a[i] = b[i] = i *
1.0;
double start =
omp_get_wtime();
omp_set_dynamic(0);
omp_set_num_threads(4);
#pragma omp parallel shared(a,b,c)
private(i)
{
#pragma omp for
schedule(static)
for (i=0; i < N;
i++)
c[i] = a[i] +
b[i];
} /* end of parallel section
*/
double end =
omp_get_wtime();
printf("%f\n",start);
printf("%f\n",end);
printf("%f\n",end -
start);
}
Same code but with out the #pragma sections , the problem is that is not
always faster than serial code, some times serial code is even faster .
Any clue is more than welcome, if this is not he mailing list to post this
please tell me. I am really interested to lear Open MP
Thanks a lot and regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20140916/0c608b93/attachment.html>
More information about the Openmp-dev
mailing list