public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/61050] New: OpenMP: wrong behavior of 'omp for' on corner cases
@ 2014-05-03 22:04 guido at vanguardiasur dot com.ar
  2014-05-04  5:53 ` [Bug c/61050] " jakub at gcc dot gnu.org
  2014-05-04 21:52 ` guido at vanguardiasur dot com.ar
  0 siblings, 2 replies; 3+ messages in thread
From: guido at vanguardiasur dot com.ar @ 2014-05-03 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61050
           Summary: OpenMP: wrong behavior of 'omp for' on corner cases
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: guido at vanguardiasur dot com.ar

Created attachment 32728
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32728&action=edit
example input

Note: by infinite loop, we mean something of the form 'for (i=0; i>=0; i++)',
not considering overflow.

#pragma omp for changes the behavior of empty/infinite loops. Some empty loops
are entered once per thread, and some infinite loops are either not entered at
all or entered once. An example is attached and more are found in [1].

In the attached example, this loop:

    char i;
    #pragma omp for
    for (i=100; i<90; i--)
        printf("Hello %i %i\n", i, omp_get_thread_num());

is entered exactly once, with i = 100, when it should never be entered. There
are no parallel directives.

We believe this is caused by a miscalculation of the number of iterations, or a
wrong empty loop check (or both).
The calculated number of iterations (extracted from the assembly) for the
previous example is 12, when it should probably be zero. Also, some loops give
a negative loop count but are still entered (once).

This happens on gcc 4.9.0, 4.8.2 and some older versions too. We've reproduced
it easily. We checked the OpenMP specification and it does not mention an
exception in these cases. Also note, this behavior does not seem to occur in
fortran.

gcc -v -save-temps output at http://sprunge.us/TfaC.

[1]
    http://sprunge.us/TbWj
    http://sprunge.us/NCeA
    http://sprunge.us/PAZD
    http://sprunge.us/faTD
    http://sprunge.us/CIMN


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

end of thread, other threads:[~2014-05-04 21:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-03 22:04 [Bug c/61050] New: OpenMP: wrong behavior of 'omp for' on corner cases guido at vanguardiasur dot com.ar
2014-05-04  5:53 ` [Bug c/61050] " jakub at gcc dot gnu.org
2014-05-04 21:52 ` guido at vanguardiasur dot com.ar

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