Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why must loop variables be signed in a parallel for?

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

(It doesn't matter much as the expected dimensions are far smaller than INT_MAX, but it does cost me some casts.)

like image 481
Fred Foo Avatar asked Oct 21 '10 14:10

Fred Foo


People also ask

How do you tell if a loop can be parallelized?

A loop is appropriate for explicit parallelization if: It is a DO loop, but not a DO WHILE or Fortran 95 array syntax. The values of array variables for each iteration of the loop do not depend on the values of array variables for any other iteration of the loop.

What is #pragma OMP for?

The OpenMP clause: #pragma omp parallel. creates a parallel region with a team of threads , where each thread will execute the entire block of code that the parallel region encloses.


2 Answers

To answer your first question about gcc. 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 a 64bit ubuntu) doesn't complain and does the right thing.

like image 114
Jens Gustedt Avatar answered Sep 22 '22 05:09

Jens Gustedt


According to OpenMP 3.0 specification: http://www.openmp.org/mp-documents/spec30.pdf, for variable may be of a signed or unsigned integer type, see 2.5.1 Loop Construct. The question is whether given OpenMP implementation matches this latest specification.

like image 28
Alex F Avatar answered Sep 19 '22 05:09

Alex F