- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Can the compiler vectorize simple loops with std::vector? Isawa much earlier post involving std::vector in which it seemed that the compiler can do this. I tried it for myself and got a message saying "dereference too complex":
#include
#include
#include
using
namespace std;static
void foo(vector<int> ints1, vector<int> ints2);int
main() {vector<
int> ints1;vector<
int> ints2;foo(ints1, ints2);
}
void
foo(vector<int> ints1, vector<int> ints2){
#pragma
ivdep#pragma
vector always for (int i = 0; i < 1000; ++i)ints1 = ints2;
}
Thanks,
~Nafis
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In another post (answered by Aart), someone posted the code below and claimed that test1 reported as vectorized. When I compiled it, test1 did not vectorize. Are you able to get this to work?
typedef
std::vector<double> DoubleVector;struct
Test{
DoubleVector v1;
DoubleVector v2;
void test1(const double x); void test2(const double x); void test3(const double x); void test4(const double x);};
void
f1(const double x, const DoubleVector& v1, DoubleVector& v2){
const DoubleVector::size_type size = v1.size(); // this IS vectorized! for(DoubleVector::size_type i = 0; i < size; ++i){
v2 = exp(v1*x);
}
}
void
Test::test1(const double x){
// this IS vectorized!f1(x, v1, v2);
}
void
Test::test2(const double x){
const DoubleVector::size_type size = v1.size(); // this IS NOT vectorized for(DoubleVector::size_type i = 0; i < size; ++i){
v2 = exp(v1 * x);
}
}
void
Test::test3(const double x){
const DoubleVector::size_type size = v1.size(); // this IS NOT vectorized // not even with the 'ignore dependencies' pragma#pragma ivdep
for(DoubleVector::size_type i = 0; i < size; ++i)
{
v2 = exp(v1 * x);
}
}
void
Test::test4(const double x){
const DoubleVector::size_type size = v1.size(); const double* p1 = &v1[0]; double* p2 = &v2[0]; // this IS vectorized! // but goodbye to the vector abstraction for(DoubleVector::size_type i = 0; i < size; ++i){
p2 = exp(p1 * x);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Nafis,
The code in test1() is obviously only vectorized when inlined, so you may want to try Qip, -Qipo, or fast to observe vectorization, depending on your compiler version. You seem to have a great interest in vectorization. Perhaps I may recommend the vectorization handbook as next reading?
http://www.intel.com/intelpress/sum_vmmx.htm
Sincerely,
Aart Bik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Probably not a bad idea. Thanks,
~Nafis
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page