declaration error

declaration error

Igot the following error mesage when I compiled my code with icc.

InitializeScenarioData.c (192) error: Cilk_for initilization must be a declaration

cilk_for ( j = 0; j < (*Env).nz_SSP[i]; j+1 ) {
^

I declared j as an integer. I also am using i (also declared as an integer) it is initialized and declared. Why am I getting this error?

Thanx in advance.

Newport_j

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Are you coding in C or C++? The C++ dialect of Cilk requires you to declare the loop control variable in the cilk_for statement. ie:

 cilk_for ( int j = 0; j < (*Env).nz_SSP[i]; j+1 ) {

This was done to emphasize that the scope of the loop control variable is limited to within the loop. It was only relaxed for C because we had no choice.

- Barry

It seems that most if the time you do not have to declare a variable in the for statement in c, but sometimes it does require you to. I can think of no other reason that that for this error.

Newport_j

In OpenMP, some of us prefer to use C99 rather than C89, so that we can define the loop counter in the for() initialization rather than requiring it to be designated as private. For consistency, I personally would prefer the local declaration, not that such reasoning carries any weight.

Quoting newport_j...It seems that most of the time you do not have to declare a variable in the for statement in C...
That depends on a C/C++compiler andsupported version of aC/C++ LanguageStandard.

Please take a look at two genericcases:

// Case 1 - Variable 'i' isdeclared in each 'for'statement.For some legacy C/C++compilersitwill be a
compilation error.

...
int iArray[32];

for( int i = 0; i < 32; i++ )
iArray[i] = i;

for( int i = 0; i < 32; i++ )
iArray[i]++;
...

// Case 2 - Variable 'i' is declared outside of both'for' statements. In that case the code could be
successfully compiled with legacy and modern C/C++compilers.These are more
portablecodes.

...
int i;
int iArray[32];

for( i = 0; i < 32; i++ )
iArray[i] = i;

for( i = 0; i < 32; i++ )
iArray[i]++;
...

Both cases implement the same logic.

If you give me a complete program that reproduces the problem, we can look at whether this is a bug or a misunderstanding. At this point I don't have enough information to tell.

- Barry

Login to leave a comment.