PGI is even slower than gcc?

I have CentOS x86-64 installed in my machine which has 4 Athlon64/Opteron and 16G RAM. I wrote a simple program in C to test the performance of PGI compiler and gcc

long test(void)
{ long i, j, k, p, m=0;
for (i=0; i<200000; i++)
{
for (j=0; i<1000000; i++)
{
for (k=0; k<2000; k++)
{
for (p=0; p<1000; p++)
{
m = m+i-j+k-p;
}
}
}
}
return m;
}

To compile that program with gcc, I run

gcc -O2 -o foo foo.c

It takes around 30ms to run that. So fast!

But with PGI, I try

pgcc -fast -o foo foo.c
./foo -pgcc -np 4

it takes almost forever to run that (around 40320 ms), why’s that? How to make code run faster (at lease comparable with gcc)?

Hi,

I have a question to ask about your code.

For a for loop j, it is a typo or it is your intention to have a loop as

for (j = 0, i<1000000; i++)

If you try with

(j = 0; j < 1000000; j++) , timing on gcc will be quite different.


Thank you,
Hongyon

Thanks for your reply. It is a typo. But no matter if it is typo or not, since we are compile the same code by different compiler, so it is not a big deal. The problem is gcc is much faster than pgcc !?

You are absolutely right that this particular code is faster with gcc. Do we use or code it with that type of loop(for loop j) in a program? I don’t know.

If all the code does is just add and subtract and nothing else in an inner loop, perhaps there is a better way to write the code by removing the loops using formula of n*(n+1)/2 for i,k,p. Ignore j because it is not actually used.

Hongyon

Thanks for reply again. In my case, I have lots of searching algorithm need that nest loops (might be not common in others cases). Well, my question is: I don’t expect pgi will be much faster than gcc in this case, but if you run the code, you will find that it’s around 100 times slower than the code compiled with gcc, just want to find out why

Hi,

We will need to see actual loops with actual arrays(so we can see what kind of arrays you have) to determine why and how to get it run faster. If you are uncomfortable to post it here, please send to trs@pgroup.com.

Thank you,
Hongyon