- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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; 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
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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; 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
for( int i = 0; i < 32; i++ )
iArray++;
...
// 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;
for( i = 0; i < 32; i++ )
iArray++;
...
Both cases implement the same logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Barry

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page