vectorization issue

kalven
Total Points:
425
Status Points:
375
Green Belt
October 20, 2008 12:12 AM PDT
Rate
 
#1
Quoting - h_krishnan

In my application, I have the following pattern occurring at many places:

loop_over_i(i)
{
   do_something(i); // common for all loops
   do_remaining_things(i);
}

The do_something part is common for most loops and so I am trying to extract it out with a class. However, the loop no longer vectorizes. A sample code is given below:

#include <iostream>
using namespace std;

class Loop
{
public:
    Loop(int max) : max_(max), count_(0), sqr_(0)
    { }
    void more()
    { 
      ++count_ ;
      sqr_ = count_ * count_;
    }
    bool done() const
    {
      return count_ >= max_;
    }
    operator int() const
    {
      return count_;
    }
    int sqr() const
    {
      return sqr_;
    }
private:
    int count_, max_, sqr_;
};

int main()
{
    int square[50];
    // this loop vectorizes
    for (int i = 0; i < 50; ++i)
      {
        square[i] = i*i;
      }
    // this loop doesn't vectorize
    for (Loop loop(50); !loop.done(); loop.more())
    {
      square[loop] = loop.sqr();
    }
}
How can I implement what I need in a way that the loop vectorizes?

 



Intel Software Network Forums Statistics

8491 users have contributed to 31629 threads and 100764 posts to date.
In the past 24 hours, we have 32 new thread(s) 141 new posts(s), and 200 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to Crash when loading skeleton The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member shadowwolf99