473,327 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

icc -axW problem

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
2 2464
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: =?utf-8?B?5LiA6aaW6K+X?= | last post by:
Hi all! Have u tried genaxmodule.py provided by wxPython to create a wrapper module for an activex control? For me, some times it works, but some times, it doesn't....
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.