Why should loop variables be signed in parallel?

I am just learning OpenMP from online lessons and resources. I want the square of the matrix (multiply it by itself) using a parallel for loop. In the IBM compiler documentation, I found that "the iteration variable must be an integer signed ." Is this also true in the implementation of GCC? Is this specified in the OpenMP standard? If so, is there a reason for this requirement?

(This does not really matter, since the expected sizes are much smaller than INT_MAX , but it will come in handy for me.)

+6
c ++ c parallel-processing openmp signed
source share
4 answers

According to the OpenMP 3.0 specification: http://www.openmp.org/mp-documents/spec30.pdf , a variable can have an integer type with or without a signature, see 2.5.1 Loop Construct, The question is whether whether this implementation of OpenMP is of this latest specification.

+5
source share

Quote from Why are unsigned OpenMP index variables not specified? :

According to the OpenMP 2.0 C / C ++ API (pdf), section 2.4.1, which is one of the limitations of the for loop. There is no reason for this, but I suspect that it will simply simplify the assumptions that the code and the compiler should do, since there is special code that ensures the range does not exceed the maximum type value.

OpenMP 3.0 seems to allow unsigned types too, but I haven't seen it in action yet.

In short, part of the standard and the next version will allow unsigned integers.

+8
source share

Here is a possible reason for this. The same article states that

  • b, ub, incr are cyclic invariant signed integer expressions and
  • exit_cond takes the form: iv <= ub or iv < ub or iv >= ub or iv > ub (where iv is the iteration variable you are asking about)

since the exit_cond condition includes comparison and the comparison is performed with the signed variable ub , the loop variable iv must be signed in order to avoid possible sign / unsigned comparison problems.

+7
source share

To answer your first gcc question. No, it seems that gcc easily accepts unsigned or size_t loop variables in something like

 #pragma omp parallel for for (size_t i = 0; i < N; ++i) { /* do it */ } 

at least mine (gcc v 4.4 on 64-bit ubuntu) does not complain and does the right thing.

+1
source share

All Articles