public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgomp/35912]  New: "omp parallel for"  wrong result
@ 2008-04-12  3:50 whitelilis at gmail dot com
  2008-04-12  4:28 ` [Bug libgomp/35912] " pinskia at gcc dot gnu dot org
  2008-04-14 14:29 ` bangerth at dealii dot org
  0 siblings, 2 replies; 3+ messages in thread
From: whitelilis at gmail dot com @ 2008-04-12  3:50 UTC (permalink / raw)
  To: gcc-bugs

I just write the following code:
--------------------------------
int main() {
        int i = 0;
        int s = 0;

#pragma omp parallel for
        for(i = 0; i < 10001; i++) {
                /* uncommenting the follow line, it works */
                printf("thread %d : %d\n", omp_get_thread_num(), s = s + i);

                /* uncommenting the follow line, it gets wrong */
                /* s += i; */

                /* but when uncommenting the follow line, the above line works
*/
                /* printf("%d\n", s); */

        }
        printf("%d\n", s);

}
------------------------------------------------
The above runs just as I described in the comment.
when I said "it gets worng", I mean that, when I run it many time, it returns
different result, but every one is wrong.
such as:
----------------------------------------
 $ ./another
31653559
lfs_625:wizard | Sat 12 Apr 2008 11:46:05 AM GMT | ~/programe/c/openMP
 $ ./another
50005000
lfs_625:wizard | Sat 12 Apr 2008 11:46:06 AM GMT | ~/programe/c/openMP
 $ ./another
24946634
lfs_625:wizard | Sat 12 Apr 2008 11:46:07 AM GMT | ~/programe/c/openMP
 $ ./another
19633725
lfs_625:wizard | Sat 12 Apr 2008 11:46:07 AM GMT | ~/programe/c/openMP
 $ ./another
49257506
lfs_625:wizard | Sat 12 Apr 2008 11:46:08 AM GMT | ~/programe/c/openMP
----------------------------------------


-- 
           Summary: "omp parallel for"  wrong result
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: whitelilis at gmail dot com
  GCC host triplet: "omp parallel for" gets the wrong result


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libgomp/35912] "omp parallel for"  wrong result
  2008-04-12  3:50 [Bug libgomp/35912] New: "omp parallel for" wrong result whitelilis at gmail dot com
@ 2008-04-12  4:28 ` pinskia at gcc dot gnu dot org
  2008-04-14 14:29 ` bangerth at dealii dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-04-12  4:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2008-04-12 04:27 -------
I don't think this is a bug as you did not mark the operations on s as atomic.


-- 


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libgomp/35912] "omp parallel for"  wrong result
  2008-04-12  3:50 [Bug libgomp/35912] New: "omp parallel for" wrong result whitelilis at gmail dot com
  2008-04-12  4:28 ` [Bug libgomp/35912] " pinskia at gcc dot gnu dot org
@ 2008-04-14 14:29 ` bangerth at dealii dot org
  1 sibling, 0 replies; 3+ messages in thread
From: bangerth at dealii dot org @ 2008-04-14 14:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bangerth at dealii dot org  2008-04-14 14:28 -------
(In reply to comment #1)
> I don't think this is a bug as you did not mark the operations on s
> as atomic.

Yes, exactly. 


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-04-14 14:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-12  3:50 [Bug libgomp/35912] New: "omp parallel for" wrong result whitelilis at gmail dot com
2008-04-12  4:28 ` [Bug libgomp/35912] " pinskia at gcc dot gnu dot org
2008-04-14 14:29 ` bangerth at dealii dot org

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).