icc -axW problem

X

Xiaozhu

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!
 
T

Thomas Matthews

Xiaozhu said:
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
 
X

Xiaozhu

Thomas Matthews said:
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 <sys/time.h>
#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("<<i<<") = "<<sin(double(i))<<endl;
p=sin(double(i));
}

cout<<p<<endl;

gettimeofday(&now, 0);
t = (now.tv_sec - start.tv_sec)*1000000
+ (now.tv_usec - start.tv_usec);
printf("time(seconds): %f\n", 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(18) : (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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top