public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/33720]  New: A negative value in OpenMP clause num_threasds is not detected at runtime
@ 2007-10-09 20:49 geir at cray dot com
  2007-10-09 23:28 ` [Bug libgomp/33720] " bkoz at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: geir at cray dot com @ 2007-10-09 20:49 UTC (permalink / raw)
  To: gcc-bugs

The 'num_threads' clause in a OpenMP pragma is not being checked to see if it
is a positive integer.  An error should be return if it is not.

The OpenMP API Version 2.5 May 2005 on p. 28 lines 29-30 offers the following
restriction:

" * ... The num_threads expression must evaluate to a positive integer value."


$ cat bug2883.c
/* derived from ISU's RTED_OpenMP/C/Col3_Env_and_Claus_Errs/c_C_1_1_a.c test */
#include <omp.h>
#include <stdio.h>
#include <math.h>
int main() {
  double s, pi;
  int n_thread;
  int actual_num_threads;
  omp_set_num_threads(4);

  s = 0;
  pi = 4.0*atan(1.0);
  n_thread = (int) (sin(-0.25*pi)*10.0);

  printf("pi % 12.4f n_thread %d \n", pi, n_thread);
#pragma omp parallel default(none) shared(actual_num_threads)
num_threads(n_thread)
 {
#pragma omp single
   {
     actual_num_threads = omp_get_num_threads();
   }
 }

 printf("actual_num_threads = %d\n", actual_num_threads);
 return 0;
}

$ gcc -o x -fopenmp bug2883.c -lm
$ ./x 
pi       3.1416 n_thread -7

libgomp: Out of memory allocating 34359738400 bytes
$


-- 
           Summary: A negative value in OpenMP clause num_threasds is not
                    detected at runtime
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: geir at cray dot com


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


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

* [Bug libgomp/33720] A negative value in OpenMP clause num_threasds is not detected at runtime
  2007-10-09 20:49 [Bug c/33720] New: A negative value in OpenMP clause num_threasds is not detected at runtime geir at cray dot com
@ 2007-10-09 23:28 ` bkoz at gcc dot gnu dot org
  2007-11-12 19:37 ` [Bug libgomp/33720] A negative value in OpenMP clause num_threads " jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2007-10-09 23:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bkoz at gcc dot gnu dot org  2007-10-09 23:27 -------

I guess this is from:
http://rted.public.iastate.edu/OpenMP/homepage.html


-- 


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


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

* [Bug libgomp/33720] A negative value in OpenMP clause num_threads is not detected at runtime
  2007-10-09 20:49 [Bug c/33720] New: A negative value in OpenMP clause num_threasds is not detected at runtime geir at cray dot com
  2007-10-09 23:28 ` [Bug libgomp/33720] " bkoz at gcc dot gnu dot org
@ 2007-11-12 19:37 ` jakub at gcc dot gnu dot org
  2008-08-07  2:56 ` manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-11-12 19:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2007-11-12 19:37 -------
I'm not sure we should do anything about this.
We have a warning if the compiler can detect non-positive value at compile
time,
but we certainly can't ever issue any diagnostic at runtime for num_threads
0 (because the implementation uses that value to mean no num_threads clause was
present) and I'm not convinced the runtime library needs to be verbose to
stderr.  So e.g. silently assuming just one thread is IMHO better than doing
gomp_fatal in there.  You shouldn't expect any particular behavior from program
which triggers undefined behavior.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rth at gcc dot gnu dot org


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


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

* [Bug libgomp/33720] A negative value in OpenMP clause num_threads is not detected at runtime
  2007-10-09 20:49 [Bug c/33720] New: A negative value in OpenMP clause num_threasds is not detected at runtime geir at cray dot com
  2007-10-09 23:28 ` [Bug libgomp/33720] " bkoz at gcc dot gnu dot org
  2007-11-12 19:37 ` [Bug libgomp/33720] A negative value in OpenMP clause num_threads " jakub at gcc dot gnu dot org
@ 2008-08-07  2:56 ` manu at gcc dot gnu dot org
  2009-07-31 15:12 ` manu at gcc dot gnu dot org
  2009-09-14 20:00 ` geir at cray dot com
  4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-07  2:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from manu at gcc dot gnu dot org  2008-08-07 02:55 -------
(In reply to comment #2)
> I'm not sure we should do anything about this.
> We have a warning if the compiler can detect non-positive value at compile
> time,
> but we certainly can't ever issue any diagnostic at runtime for num_threads
> 0 (because the implementation uses that value to mean no num_threads clause was
> present) and I'm not convinced the runtime library needs to be verbose to
> stderr.  So e.g. silently assuming just one thread is IMHO better than doing
> gomp_fatal in there.  You shouldn't expect any particular behavior from program
> which triggers undefined behavior.

But in this case the value is negative, not zero, and it seems that gomp_fatal
is already being called:

libgomp: Out of memory allocating 34359738400 bytes

It will be better to print the cause of that "out of memory" error, that is,
that the number of threads was negative.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org,
                   |                            |jakub at gcc dot gnu dot org


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


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

* [Bug libgomp/33720] A negative value in OpenMP clause num_threads is not detected at runtime
  2007-10-09 20:49 [Bug c/33720] New: A negative value in OpenMP clause num_threasds is not detected at runtime geir at cray dot com
                   ` (2 preceding siblings ...)
  2008-08-07  2:56 ` manu at gcc dot gnu dot org
@ 2009-07-31 15:12 ` manu at gcc dot gnu dot org
  2009-09-14 20:00 ` geir at cray dot com
  4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-07-31 15:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2009-07-31 15:11 -------
Geir, have you run the testcase with other compilers? What is the result?


-- 


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


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

* [Bug libgomp/33720] A negative value in OpenMP clause num_threads is not detected at runtime
  2007-10-09 20:49 [Bug c/33720] New: A negative value in OpenMP clause num_threasds is not detected at runtime geir at cray dot com
                   ` (3 preceding siblings ...)
  2009-07-31 15:12 ` manu at gcc dot gnu dot org
@ 2009-09-14 20:00 ` geir at cray dot com
  4 siblings, 0 replies; 6+ messages in thread
From: geir at cray dot com @ 2009-09-14 20:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from geir at cray dot com  2009-09-14 19:59 -------
(In reply to comment #4)
> Geir, have you run the testcase with other compilers? What is the result?
> 

Changed test cast to use 2 threads ("omp_set_num_threads(2);")

  PGI 9.0-3

$ pgcc -mp bug2883.c
$ ./a.out
pi       3.1416 n_thread -7
Error: omp_set_num_threads value (-7) is invalid
$

  Pathscale 3.2.99:

$ pathcc -mp bug2883.c
$ ./a.out
pi       3.1416 n_thread -7
actual_num_threads = 1
$

  Intel/11.1.046:

$ icc -openmp bug2883.c
$ ./a.out
pi       3.1416 n_thread -7
actual_num_threads = 2
$

  Cray 7.1.3:

$ cc -target=native bug2883.c
$ ./a.out
pi       3.1416 n_thread -7
actual_num_threads = 2
$

$


-- 


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


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

end of thread, other threads:[~2009-09-14 20:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-09 20:49 [Bug c/33720] New: A negative value in OpenMP clause num_threasds is not detected at runtime geir at cray dot com
2007-10-09 23:28 ` [Bug libgomp/33720] " bkoz at gcc dot gnu dot org
2007-11-12 19:37 ` [Bug libgomp/33720] A negative value in OpenMP clause num_threads " jakub at gcc dot gnu dot org
2008-08-07  2:56 ` manu at gcc dot gnu dot org
2009-07-31 15:12 ` manu at gcc dot gnu dot org
2009-09-14 20:00 ` geir at cray dot com

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