icc -axW problem

Discussion in 'C++' started by Xiaozhu, Aug 27, 2004.

  1. Xiaozhu

    Xiaozhu Guest

    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!
     
    Xiaozhu, Aug 27, 2004
    #1
    1. Advertising

  2. 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
     
    Thomas Matthews, Aug 27, 2004
    #2
    1. Advertising

  3. Xiaozhu

    Xiaozhu Guest

    Thomas Matthews <> wrote in message news:<>...
    > 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.
     
    Xiaozhu, Aug 28, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Bouchard

    Image conversion with icc profiles

    David Bouchard, May 2, 2005, in forum: Java
    Replies:
    4
    Views:
    612
    David Bouchard
    May 4, 2005
  2. David Bouchard

    Image conversion with icc profiles

    David Bouchard, May 2, 2005, in forum: Java
    Replies:
    0
    Views:
    412
    David Bouchard
    May 2, 2005
  3. David Bouchard

    Images and ICC profiles

    David Bouchard, May 6, 2005, in forum: Java
    Replies:
    0
    Views:
    410
    David Bouchard
    May 6, 2005
  4. David Bouchard

    Using ICC profiles

    David Bouchard, May 10, 2005, in forum: Java
    Replies:
    4
    Views:
    547
    asaguden
    May 11, 2005
  5. eva2002
    Replies:
    2
    Views:
    683
    Lionel B
    May 29, 2007
Loading...

Share This Page