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

Reply via email to