Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Possible case for a warning in the compiler?

$
0
0

Hello everyone,

While I was making several changes in my code, I came across a case when using pragmas, that I managed to reduce to the following very simple testcase, contained in the file phitest.c:

#include <stdio.h>

int main()
{
        int     i, a = 0;

#if 0
#pragma offload target(mic) inout(a) \
#else
#pragma offload target(mic) inout(a)
#endif
#pragma omp parallel for
        for (i = 0; i < 100000000; i++) {
                #pragma omp atomic
                a++;
        }

        printf("a = %d\n", a);

        return(0);
}

I compile the code using icc 14.0.2 with:

icc -O3 -fopenmp -o phitest phitest.c

Notice the backslash at the end of the first pragma. This program compiles without a problem, but it executes on the CPU. Technically speaking, this is the correct behavior. With the backslash, the "#else" goes with the previous line, so the two offload pragmas are actually inside the "#if 0". Of course, if I delete the backslash the program behaves as expected.

However, it took me several hours to find this error. The offload pragmas in my case were very long and the backslash was not visible until I scrolled to the end of the line. Maybe a lesson for me to turn on line breaking in my editor :-) Although I still haven't found a good way to parallelize my application for the Phi, this made me scratch my head for hours trying to figure out why the code is not executed on the Phi at all.

You think some warning message would be appropriate in this case or not? What is your opinion?

Ioannis E. Venetis


Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>