|
| View previous topic :: View next topic |
| Author |
Message |
QOS
Joined: 01 May 2009 Posts: 7
|
Posted: Mon Jun 29, 2009 7:43 pm Post subject: 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)? |
|
| Back to top |
|
 |
hongyon
Joined: 19 Jul 2004 Posts: 551
|
Posted: Tue Jun 30, 2009 8:53 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
QOS
Joined: 01 May 2009 Posts: 7
|
Posted: Tue Jun 30, 2009 9:16 am Post subject: |
|
|
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 !?
| hongyon wrote: | 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 |
|
|
| Back to top |
|
 |
hongyon
Joined: 19 Jul 2004 Posts: 551
|
Posted: Tue Jun 30, 2009 12:28 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
QOS
Joined: 01 May 2009 Posts: 7
|
Posted: Tue Jun 30, 2009 5:47 pm Post subject: |
|
|
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
| hongyon wrote: | 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 |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|