C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

icc -axW problem

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Xiaozhu
Guest





PostPosted: Fri Aug 27, 2004 4:00 pm    Post subject: icc -axW problem Reply with quote



I trid to use icc -axW to optimize the code, but it becomes much slower...
8sec/37sec before and after using this option.

my cpu is Intel(R) Pentium(R) 4 CPU 2.40GHz

the test code is just one loop:

for(int i=0; i<100000000; i++){
p=sin(double(i));
}

What is wrong? Thanks!
Back to top
Thomas Matthews
Guest





PostPosted: Fri Aug 27, 2004 8:32 pm    Post subject: Re: icc -axW problem Reply with quote



Xiaozhu wrote:
Quote:
I trid to use icc -axW to optimize the code, but it becomes much slower...
8sec/37sec before and after using this option.

my cpu is Intel(R) Pentium(R) 4 CPU 2.40GHz

the test code is just one loop:

for(int i=0; i<100000000; i++){
p=sin(double(i));
}

What is wrong? Thanks!

From what you have supplied us, the whole loop
can be optimized away since the value of "p"
is not used anywhere inside the loop nor outside
of the loop.

Another optimization is to remove the assignment
statement. The loop may be a timing loop and thus
needed.

By the way, the argument to the sin function is
in units of radians and there no more than PI/2
radians in a circle. Any number larger than this
causes a modulo on the radians (extra work for
the sin function).

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library


Back to top
Xiaozhu
Guest





PostPosted: Sat Aug 28, 2004 1:43 am    Post subject: Re: icc -axW problem Reply with quote



Thomas Matthews <Thomas_MatthewsSpamBotsSuck (AT) sbcglobal (DOT) net> wrote

Quote:
Xiaozhu wrote:
I trid to use icc -axW to optimize the code, but it becomes much slower...
8sec/37sec before and after using this option.

my cpu is Intel(R) Pentium(R) 4 CPU 2.40GHz

the test code is just one loop:

for(int i=0; i<100000000; i++){
p=sin(double(i));
}

What is wrong? Thanks!

From what you have supplied us, the whole loop
can be optimized away since the value of "p"
is not used anywhere inside the loop nor outside
of the loop.

Another optimization is to remove the assignment
statement. The loop may be a timing loop and thus
neede
d.

By the way, the argument to the sin function is
in units of radians and there no more than PI/2
radians in a circle. Any number larger than this
causes a modulo on the radians (extra work for
the sin function).

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Thank you for your reply...Sure, I understand what you are saying.
This is just a test code though. I actually had a like problem before.
So I want to see what could be the problem. The sin and p are not
important. I also used p outside the loop.

The whole code is:

#include #include <math.h>
#include <iostream>
#include <stdio.h>
using namespace std;

static struct timeval start;
static struct timeval now;

int main()
{
unsigned long t;
gettimeofday(&now, 0);
start = now;

double p;
int i;
for(i=0; i<100000000; i++){
//cout<<"sin("< p=sin(double(i));
}

cout<
gettimeofday(&now, 0);
t = (now.tv_sec - start.tv_sec)*1000000
+ (now.tv_usec - start.tv_usec);
printf("time(seconds): %fn", t/1000000.);
return 0;

The results are:

[Fri Aug 27]mathfun$ icc sin.cpp
[Fri Aug 27]mathfun$ ./a.out
0.809145
time(seconds): 8.138045
[Fri Aug 27]mathfun$ icc -axW sin.cpp
sin.cpp(1Cool : (col. 3) remark: LOOP WAS VECTORIZED.
sin.cpp(11) : (col. 1) remark: main has been targeted for automatic
cpu dispatch.
/opt/intel//include/c++/xlocale(442) : (col. 2) remark: LOOP WAS
VECTORIZED.
/opt/intel//include/c++/xlocale(438) : (col. 2) remark:
_ZSt10_MaklocstrIcEPT_PKcS1_RKSt7_Cvtvec has been targeted for
automatic cpu dispatch.
[Fri Aug 27]mathfun$ ./a.out
0.809145
time(seconds): 37.759714

Still don't know what could be the problem. Thanks.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.