public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vincenzo.innocente at cern dot ch" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libgomp/58482] New: gomp4: user defined reduction produce wrong result
Date: Fri, 20 Sep 2013 10:52:00 -0000	[thread overview]
Message-ID: <bug-58482-4@http.gcc.gnu.org/bugzilla/> (raw)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58482

            Bug ID: 58482
           Summary: gomp4: user defined reduction produce wrong result
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincenzo.innocente at cern dot ch
                CC: jakub at gcc dot gnu.org

I acknowledge  that my understanding of "omp declare" is still limited.
Still the example below produces different result with and w/o -fopenmp

gcc version 4.9.0 20130919 (experimental) [gomp-4_0-branch revision 202766]
(GCC) 
pb-d-128-141-131-94:vectorize innocent$ c++ -std=c++11  ured_omp4.cpp -O
-ftree-vectorizer-verbose=1; ./a.out
523776,-523776
pb-d-128-141-131-94:vectorize innocent$ c++ -std=c++11  ured_omp4.cpp -O
-ftree-vectorizer-verbose=1 -fopenmp; ./a.out
ured_omp4.cpp:26:8: note: loop turned into non-loop; it never loops
ured_omp4.cpp:26:8: note: loop turned into non-loop; it never loops
523776,523776


cat ured_omp4.cpp
#define Type float

struct TwoInt {
  Type a=0;
  Type b=0;

#pragma omp declare simd
  TwoInt & operator+=(TwoInt rh) {
    a+=rh.a;
    b-=rh.b;
  }

#pragma omp declare simd
  TwoInt & add(TwoInt rh) {
    a+=rh.a;
    b-=rh.b;
    return *this;
  }


};

#pragma omp declare reduction (foo:struct TwoInt: omp_out.add(omp_in))


TwoInt sum(Type const * q, int NN) {
  TwoInt s;
#pragma omp simd reduction(foo:s)
  for (int i=0;i<NN;++i) {
    TwoInt l; l.a=q[i]; l.b = q[i];
    s.add(l);
  }
  return s;
}

#include<iostream>
int main() {
  constexpr int NN=1024;
  Type q[NN];
  Type a=0;
  for (auto & e: q) e=a++;

  auto s = sum(q,NN);
  std::cout << s.a << "," << s.b << std::endl;


  return 0;
}


             reply	other threads:[~2013-09-20 10:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-20 10:52 vincenzo.innocente at cern dot ch [this message]
2013-09-20 11:16 ` [Bug libgomp/58482] " jakub at gcc dot gnu.org
2013-09-20 13:28 ` jakub at gcc dot gnu.org
2013-09-21 15:47 ` vincenzo.innocente at cern dot ch
2013-09-21 19:04 ` jakub at gcc dot gnu.org
2013-09-26  7:58 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-58482-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).