Software Archive
Read-only legacy content
17060 Discussions

cilkifying c source

newport_j
Beginner
818 Views


I am trying to cilkify a program that now hasthe following loop

cilk_for(i=o;i<(*Env).Nfreq;I++)

I got the error:

Cilk_for initialization must be a declaration. I know that on cilkifying c++ you must declare i to be an intteger, but you do not have to do this in c. My program is in c. However, just to experiment I added int i=0 instead of i=0. I got the same error. What is going on? It should have no problemusing i=o without i beingdeclared an integer.

Thanks in advance.

Newport_j
0 Kudos
11 Replies
Barry_T_Intel
Employee
818 Views
Please post the exact source line (spacing maymatter) and the exact error text.

- Barry
0 Kudos
newport_j
Beginner
818 Views


The screenshot is a picture of the output after I tried to compile. It gives the exact source code and the compiler response. I should not have to specify i to be an integer. IfI do specify i to be an integer, then I still get the same error.

Any help appreciated.

Newport_j
0 Kudos
Pablo_H_Intel
Employee
818 Views
Your compilation command is hidden behind a script. I'm wondering what command line you're using to compile. You should be using icc for C code. If you're using icpc, that would explain the problem.
0 Kudos
newport_j
Beginner
818 Views

Iam using the icc command - not icpc. I will show you the complete command asI used it.I have attached a screenshot so now nothing is hidden. I have also included a cut down version of the file prc_ray2.c. By simply using the command

icc prc_ray2.c

you will see the output. You will also see a lot irrelevant errors. please ignore them, they are not important. The only error that matters is on line 116. The last error.


I have so many of these in my legacy code; I must find a solution to this problem.I have so many similar occurences; a solution is needed orI cannot use Intel Cilk Plus. Why is it insisting on a declaration when it says in the manual (andI have proven in other examples) that when using c one does not have to declare the for loop index. In additonifIinsert a declare, it then still gives sameerror messages.

I read that it might be a spacing problem. I hope not. I added spaces about 1 hour ago and got no improvement.

Newport_j
0 Kudos
Barry_T_Intel
Employee
818 Views

Something's not right. Thejpeg of the buildclaims that the error is on line 163. Looking at the source you provided, line 163 is in the middle of the call to VRT_RAY2 after the comment "Unfold trailing rays into virtual rays."

Also, there's no way we can compile the file. There are include files we don't have, from WAFmutex.h to WEGFunDefs.h.

Is there any possibility of extracting this down to just something simple like thecilk_forafter the comment "Initializeweighted sums."? We'dstill need the definition of Env, but it would be a start. When we try to use sample code like:

#include 

int main()
{
    int i;
    int ary[42];

    cilk_for(i = 0; i < 42; i++)
	ary = i;

    return 0;
}

It compiles as expect, issuing an error with the command

icpc newport_j.c

And compiles correctly with the command

icc newport_j.c

- Barry

0 Kudos
newport_j
Beginner
818 Views

I took a snapshotafter the compile to answer the previous postabout maybe I used icpc. I did not use icpc! I used icc. I then modified the files to send to you asmall example of the file. I did at that point changes the line number.I removed several ines.

I will send to you my output on runing the file with icc. I will show you that it does not workfor me.I get the initilization error. I also sent output when I gave the command:

icc -v.

I must solve this.

See attached files.

Newport_j









0 Kudos
Barry_T_Intel
Employee
818 Views

Jim pointed out something that appears to reproduce the problem you're seeing:

#include 

int main()
{
    int j, k;
    int ary[42];

    cilk_for(j = 0; j < 42; j++)
    {
        ary = j;
        cilk_for(k = 0; k < 42; k++)
        {
            ary = k;
        }
    }

    return 0;
}

In your code, you've got nested cilk_for's in PRC_RAY2:

  • the loop indexed by "IRAY"
  • the loop nestedunder itindexed by "i"

The inner loop will be racing to access "i", which is declared at the function-level scope. In my example, moving the declaration of "k" into the outer cilk_for fixed the problem.

Fixed code:

#include 

int main()
{
    int j;
    int ary[42];

    cilk_for(j = 0; j < 42; j++)
    {
        int k;
        ary = j;
        cilk_for(k = 0; k < 42; k++)
        {
            ary = k;
        }
    }

    return 0;
}

I'm going to submit this to the compiler group since it's a confusing error message. But it is an error.

- Barry

0 Kudos
BradleyKuszmaul
Beginner
818 Views
It looks like you need to include
-std=c99
to make this compile.
This command line works:
[bash]icc foo4.c -c -W -Wall -std=c99[/bash] when foo4.c is as shown below (I added some typedefs and #defines to make it all compile). I don't know if this is a bug or not.
Also, I'm not an Intel person, but I'll take the liberty of offering you (newport_j) some unasked-for advice:
1) Don't take it badly when someone suggests an explanation that doesn't match your situation. I'm sure Barry is trying to help, so don't get upset. No, you didn't use icpc. But you didn't make it easy to figure out the problem, and he had to rule out this error.
2) When you submit a bug report, try to simplify the bug to just one problem (those other errors may not be important, but they got in the way of figuring out your problem).
3) Be complete. When you submit code, submit all the code. When you submit instructions to reproduce the bug, submit everything.
3) Provide exact information for what your program was, and how you compiled it. I like the fact that you did "icc -v" in your screen shot.
4) If possible cut and paste the text of your compilation session instead of a screen shot.
-Bradley
[cpp]#include #include #include #include #include /* #include #include "thread.h" #include "WAFmutex.h" #include "WAFmathBase.h" #include "SIMdefines.h" #include "envstructdefs.h" #include "WEGStrDefs.h" #include "WEGFunDefs.h" */ typedef struct trd { int ZRAY, TRAY, PCOS, PSIN, NSRF, NBTM, ORAY, NUPR, NLWR, FRAY[3], URAY[3]; } TEST_RAY_DATA; typedef int LOGICAL; typedef int EIGEN_RAY; typedef struct edef { int Nfreq; int frequency_Hz[3]; } ENV_DEF; #define MAXVCT 100 #define MAX_NUM_FREQ 10 #define TIMTOL 10 #define M_PI 3.0 extern void VRT_RAY2(); extern void NRM_BND2(); void PRC_RAY2( double ZTRG, double PTRG, /* LOGICAL SCST, double APER, */ TEST_RAY_DATA *TRD, double *ZSRF, double COSSRF, double SINSRF, double *ZBTM, double COSBTM, double SINBTM, int IRAY1, int IRAY2, double TIMv1, double TIMv2, double RRAY, int NCRSo, int IRAYu1, int IRAYu2, double ZVRTu1, double ZVRTu2, LOGICAL *FSRFu1, LOGICAL *FSRFu2, LOGICAL *FBTMu1, LOGICAL *FBTMu2, double *PRS2, EIGEN_RAY **eigen_ray_data, ENV_DEF *Env){ /* ZRAYu = unfolded ray depth (km) TRAYu = unfolded ray time (s) PCOSu = unfolded ray horizontal slowness (s/km) PSINu = unfolded ray vertical slowness (s/km) SRFSUM = weighted number of surface reflections sum BTMSUM = weighted number of bottom reflections sum UPRSUM = weighted number of upper vertexes sum LWRSUM = weighted number of lower vertexes sum SRCSUM = weighted source angle sum (rad) PWRSUM = pressure squared sum (uPa^2) TIMSUM = weighted time sum (s) PHSSUM = weighted phase sum (rad) PCSSUM = weighted horizontal slowness sum (s/km) PSNSUM = weighted vertical slowness sum (s/km) IMAFLG = eigenray flag {0,1} for {real,imag} eigenrays NSRFu = number of unfolded surface reflections NBTMu = number of unfolded bottom reflections NUPRu = number of unfolded upper vertexes NLWRu = number of unfolded lower vertexes URAYu = unfolded ray attenuation (nepers) FRAYu = unfolded ray factor (pres ratio) ORAYu = unfolded ray phase (rad) */ int IRAY, JRAY1, JRAY2, NSRFo, NBTMo, IMAFLG; double dTIMv, TIMv; double ZRAYu[MAXVCT], TRAYu[MAXVCT], PCOSu[MAXVCT], PSINu[MAXVCT]; int NSRFu[MAXVCT], NBTMu[MAXVCT], NUPRu[MAXVCT], NLWRu[MAXVCT]; double URAYu[MAXVCT*MAX_NUM_FREQ], FRAYu[MAXVCT*MAX_NUM_FREQ]; double ORAYu[MAXVCT]; double UPRSUM, LWRSUM; double SRCSUM, RCVSUM, PWRSUM[MAX_NUM_FREQ]; double TIMSUM, PHSSUM[MAX_NUM_FREQ]; double PCSSUM, PSNSUM; /*----------------------------------------------- Compute the imaginary vertical time derivative. -----------------------------------------------*/ if( TRD[IRAY1].ZRAY != TRD[IRAY2].ZRAY ) { dTIMv = (TIMv2-TIMv1) / (TRD[IRAY2].ZRAY-TRD[IRAY1].ZRAY); } else { dTIMv = 0.0; }; /*----------------------------------------- Copy the ray type into the unfolded type. -----------------------------------------*/ for(IRAY=IRAY1;IRAY<=IRAY2;IRAY++){ cilk_for(long i=0;i<(*Env).Nfreq;i++){ URAYu[IRAY*MAX_NUM_FREQ+i] = TRD[IRAY].URAY - 2.0 * M_PI * (*Env).frequency_Hz * TIMv; FRAYu[IRAY*MAX_NUM_FREQ+i] = TRD[IRAY].FRAY; }; ORAYu[IRAY] = TRD[IRAY].ORAY; }; /*------------------------- Initialize weighted sums. -------------------------*/ UPRSUM = 0.0; LWRSUM = 0.0; SRCSUM = 0.0; TIMSUM = 0.0; PCSSUM = 0.0; PSNSUM = 0.0; cilk_for(int i=0;i<(*Env).Nfreq;i++){ PWRSUM = 0.0; PHSSUM = 0.0; }; /*-------------------------------------- Unfold leading rays into virtual rays. --------------------------------------*/ JRAY2 = IRAY1 - 1; VRT_RAY2( IRAY1, IRAYu1,JRAY2, TIMv1, FSRFu2, *ZSRF, COSSRF, SINSRF, FBTMu2, *ZBTM, COSBTM, SINBTM, TRD, ZRAYu, TRAYu, PCOSu, PSINu, NSRFu, NBTMu, NUPRu, NLWRu, URAYu, FRAYu, ORAYu, Env ); /*--------------------------------------- Unfold trailing rays into virtual rays. ---------------------------------------*/ JRAY1 = IRAY2 + 1; VRT_RAY2( IRAY2, JRAY1, IRAYu2,TIMv2, FSRFu1, *ZSRF, COSSRF, SINSRF, FBTMu1, *ZBTM, COSBTM, SINBTM, TRD, ZRAYu, TRAYu, PCOSu, PSINu, NSRFu, NBTMu, NUPRu, NLWRu, URAYu, FRAYu, ORAYu, Env ); /*----------------------------------------------- Integrate the ray bundles within [ZVRT1,ZVRT2]. -----------------------------------------------*/ NSRFo = TRD[IRAY1].NSRF; NBTMo = TRD[IRAY1].NBTM; /* INT_BND2( ZTRG, PTRG, SCST, APER, TRD, IRAYu1, IRAYu2, ZVRTu1, ZVRTu2, RRAY, ZRAYu, TRAYu, PCOSu, PSINu, NSRFo, NBTMo, NUPRu, NLWRu, NCRSo, URAYu, FRAYu, ORAYu, &UPRSUM, &LWRSUM, &SRCSUM, &RCVSUM, PWRSUM, &TIMSUM, PHSSUM, &PCSSUM, &PSNSUM, &IMAFLG, Env ); */ /*----------------------- Normalize the eigenray. -----------------------*/ NRM_BND2( PTRG, NSRFo, NBTMo, &UPRSUM, &LWRSUM, &SRCSUM, &RCVSUM, PWRSUM, &TIMSUM, PHSSUM, &PCSSUM, &PSNSUM, &IMAFLG, PRS2, eigen_ray_data, ZTRG, RRAY, Env ); } [/cpp]
[cpp] [/cpp]
0 Kudos
Barry_T_Intel
Employee
818 Views
The bug indentified in reply 7 has been enteredas DPD200181389.

- Barry
0 Kudos
Barry_T_Intel
Employee
818 Views

For those trying to track this issue, my bug has been closed as a duplicate of DPD200261033.

- Barry

0 Kudos
Barry_T_Intel
Employee
818 Views
For those who are interested, DPD200261033 has not yet been fixed.

- Barry
0 Kudos
Reply