[llvm-dev] Issues with omp simd

Tobias Grosser via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 2 03:16:05 PST 2018


On Sat, Dec 30, 2017, at 20:49, hameeza ahmed via llvm-dev wrote:
> i changed my code to following;
>    #pragma omp simd
>         for (int i=0; i<size; ++i)
>         {
>              a[i]=2; b[i]=3; c[i]=4;
>             c[i]= a[i] + b[i];
>     printf("c value %f",c[i]);
>         }
> 
> still no effect of omp simd?
> 
> On Sun, Dec 31, 2017 at 12:26 AM, Craig Topper <craig.topper at gmail.com>
> wrote:
> 
> > The for loop has no effect on the observable behavior of the program. If
> > you run the program there is no way to tell if the numbers were added or
> > not. So the loop doesn’t matter, so the compiler deleted the code. You need
> > to print the contents of c or something so that it matters.

Printing within the loop is likely also not a good idea, as the side-effects of printf make vectorization harder. I typically just print
c[42] after the loop. Also, why don't you use -O3 rather than -O0?

Best,
Tobias

> >
> >
> >
> > On Sat, Dec 30, 2017 at 11:19 AM hameeza ahmed <hahmed2305 at gmail.com>
> > wrote:
> >
> >> I even tried following;
> >>
> >> int main(int argc, char **argv)
> >> {
> >>     const int size = 1000000;
> >>
> >>
> >>     float a[size], b[size],c[size];
> >>
> >>
> >>
> >>         #pragma omp simd
> >>         for (int i=0; i<size; ++i)
> >>         {
> >>              a[i]=2; b[i]=3; c[i]=4;
> >>             c[i]= a[i] + b[i];
> >>         }
> >>
> >>
> >>     return 0;
> >> }
> >> but the output with and without openmp simd is same. why is that so?
> >>
> >> On Sun, Dec 31, 2017 at 12:01 AM, Craig Topper <craig.topper at gmail.com>
> >> wrote:
> >>
> >>> I didn’t look at the assembly, but you didn’t initialize your arrays.
> >>> Your program isn’t meaningful.
> >>>
> >>> On Sat, Dec 30, 2017 at 9:08 AM hameeza ahmed <hahmed2305 at gmail.com>
> >>> wrote:
> >>>
> >>>> hello,
> >>>>
> >>>> i am trying to optimize omp simd loop as follows
> >>>>
> >>>> int main(int argc, char **argv)
> >>>> {
> >>>>     const int size = 1000000;
> >>>>
> >>>>
> >>>>     float a[size], b[size],c[size];
> >>>>
> >>>>
> >>>>
> >>>>         #pragma omp simd
> >>>>         for (int i=0; i<size; ++i)
> >>>>         {
> >>>>             c[i]= a[i] + b[i];
> >>>>         }
> >>>>
> >>>>
> >>>>     return 0;
> >>>> }
> >>>>
> >>>> i run it using the following command;
> >>>>
> >>>> g++ -O0 --std=c++14 -fopenmp-simd lab.cpp  -Iinclude -S -o lab.s
> >>>>
> >>>> when i compared it with code as follows without simd
> >>>>
> >>>>
> >>>> int main(int argc, char **argv)
> >>>> {
> >>>>     const int size = 1000000;
> >>>>
> >>>>
> >>>>     float a[size], b[size],c[size];
> >>>>
> >>>>
> >>>>
> >>>>         for (int i=0; i<size; ++i)
> >>>>         {
> >>>>             c[i]= a[i] + b[i];
> >>>>         }
> >>>>
> >>>>
> >>>>     return 0;
> >>>> }
> >>>>
> >>>> using following command
> >>>>
> >>>> g++ -O0 --std=c++14  lab.cpp -Iinclude -S -o lab.s
> >>>>
> >>>> I am getting the same assembly. Why is that so? why not omp simd is
> >>>> more efficient?
> >>>>
> >>>> Please help
> >>>>
> >>>>
> >>>> --
> >>> ~Craig
> >>>
> >>
> >> --
> > ~Craig
> >
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list