Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
6 Views

Compilation issues with -parallel option (FLOW, ANTI, OUTPUT)

Hi,

I have a program to reverse a string

ex: "Its a nice intel compiler"(I/P) -> "compiler intel nice a Its"(O/P)

The logic is to reverse the words in the string first in the 1st nested loop and then reversing the complete string as a whoel in the second loop.

I am trying to compile the code for this with intel c++ compiler (icpc) with '-parallel' option. Below is the code:


1 #include
2 #include
3
4 int main()
5 {
6 char s[]="proud to be indian";
7 int i=0, j=0, k=0;
8 char temp;
9 int size = strlen(s);
10 int a[] = {0,0,0,0,0,0,0,0,6,0,0,9,0,0,0,0,0,0,12};

11/************ THIS IS THE BLOCK WHICH HAS THE REMARKS ***************/

12 for(i=0; i<=size; i++)
13 {
14 if( (s == ' ') || (s == '\0') )
15 {
16 k = i-1;
17 j = a;
18
19 while(j20 {
21 temp = s;
22 s=s;
23 s=temp;
24 k--;
25 j++;
26 }
27
28 }
29 }

30/**********************END OF BLOCK*******************************************/

31 printf("the string is: %s\n",s);
32 i=0;
33 j = size-1;
34
35 while(i < j)
36 {
37 temp = s;
38 s = s;
39 s = temp;
40 i++;
41 j--;
42 }
43 printf("the string is: %s\n",s);
44 }

I am facing some compiler errors as :
stringrev.cpp(12): (col. 2) remark: loop was not parallelized: existence of parallel dependence.
stringrev.cpp(23): (col. 5) remark: parallel dependence: proven FLOW dependence between s line 23, and s line 21.
stringrev.cpp(21): (col. 5) remark: parallel dependence: proven ANTI dependence between s line 21, and s line 23.

stringrev.cpp(23): (col. 5) remark: parallel dependence: proven OUTPUT dependence between s line 23, and s line 22.
stringrev.cpp(22): (col. 5) remark: parallel dependence: proven OUTPUT dependence between s line 22, and s line 23.

stringrev.cpp(23): (col. 5) remark: parallel dependence: proven FLOW dependence between s line 23, and s line 22.
stringrev.cpp(22): (col. 5) remark: parallel dependence: proven ANTI dependence between s line 22, and s line 23.

stringrev.cpp(23): (col. 5) remark: parallel dependence: proven OUTPUT dependence between s line 23, and s line 23.
stringrev.cpp(23): (col. 5) remark: parallel dependence: proven OUTPUT dependence between s line 23, and s line 23.

stringrev.cpp(22): (col. 5) remark: parallel dependence: proven FLOW dependence between s line 22, and s line 14.
stringrev.cpp(14): (col. 3) remark: parallel dependence: proven ANTI dependence between s line 14, and s line 22.

stringrev.cpp(22): (col. 5) remark: parallel dependence: proven OUTPUT dependence between s line 22, and s line 22.
stringrev.cpp(22): (col. 5) remark: parallel dependence: proven FLOW dependence between s line 22, and s line 22.
stringrev.cpp(22): (col. 5) remark: parallel dependence: proven ANTI dependence between s line 22, and s line 22.



Most of the remarks are for the inner loop of the 1st nested loop. i.e. the swap loop. But i see logically the loop is parallely independent in the 1st nested loop.

Can somebody please help me out in understanding where i am going wrong.

Thanks in advance.

Regards
Kiran.
0 Kudos
1 Reply
Highlighted
Employee
6 Views


Hi Kiran,

What you see are data dependencies that are important to look into especially when deciding to parallleize the code regionssince multiple threads will work on same code.For effective parallelism, its best to eliminate dependencies as it can prevent parallelism and some can be worked around. Many dependencies do occur in loops. One way for finding out a loop carried dependency is to work your way running the loop backwards and see if the results are the same. If it's not, then it has a loop carried data dependency. Control dependencies for example require splitting of tasks properly and data dependencies can be eliminated mostly through looptransformations etc.

In your code, line 21 temp is modified with s assignment, while it is read in line 23. This is flow dependency meaning there's a Read after Write. Likewise if there's a Write after a Read, then it results in anti dependency (meaning a variable is read is statement 1, while it's being writtehn in statement 2 and so on.

So, the vectorizer will output those three vector dependencies (flow, anti, and output) as diagnostic messages when you use -par-report option on why the loop could not be auto parallelized. You'll have to then try to eliminate the dependency to enable vectorization of the loop......

-regards,
Kittur
0 Kudos