By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

icc -axW problem

P: n/a
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!
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
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

Jul 22 '05 #2

P: n/a
Thomas Matthews <Th*************************@sbcglobal.net> wrote in message news:<41**************@sbcglobal.net>...
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 <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.
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.