c++ - Boost MultiArrays performance is poor -
i noticed boost mutiarrays performing badly compared stl vector. came upon this question asked earlier, liked reply stated
1) boost fast native array
2) need alter order in access info elements best performance out of boost multiarray. also, need run in release mode, , not debug.
well, did that, , yet performance of multiarrays pretty shabby.
i posting code here :
a) default ordering
#include <windows.h> #define _scl_secure_no_warnings #define boost_disable_asserts #include <boost/multi_array.hpp> #include <stdio.h> #include <conio.h> #include <iostream> int main(int argc, char* argv[]) { const int x_size = 400; const int y_size = 400; const int iterations = 500; unsigned int starttime = 0; unsigned int endtime = 0; // create boost array typedef boost::multi_array<double, 2> imagearraytype; imagearraytype boostmatrix(boost::extents[x_size][y_size]); // create native array double *nativematrix = new double [x_size * y_size]; //------------------measure boost---------------------------------------------- starttime = ::gettickcount(); (int = 0; < iterations; ++i) { (int y = 0; y < y_size; ++y) { (int x = 0; x < x_size; ++x) { boostmatrix[x][y] *= 2.345; } } } endtime = ::gettickcount(); printf("[boost] elapsed time: %6.3f seconds\n", (endtime - starttime) / 1000.0); //------------------measure native----------------------------------------------- starttime = ::gettickcount(); (int = 0; < iterations; ++i) { (int y = 0; y < y_size; ++y) { (int x = 0; x < x_size; ++x) { nativematrix[x + (y * x_size)] *= 2.345; } } } endtime = ::gettickcount(); printf("[native]elapsed time: %6.3f seconds\n", (endtime - starttime) / 1000.0); homecoming 0; } b) inverted ordering
#include <windows.h> #define _scl_secure_no_warnings #define boost_disable_asserts #include <boost/multi_array.hpp> #include <stdio.h> #include <conio.h> #include <iostream> int main(int argc, char* argv[]) { const int x_size = 400; const int y_size = 400; const int iterations = 500; unsigned int starttime = 0; unsigned int endtime = 0; // create boost array typedef boost::multi_array<double, 2> imagearraytype; imagearraytype boostmatrix(boost::extents[x_size][y_size]); // create native array double *nativematrix = new double [x_size * y_size]; //------------------measure boost---------------------------------------------- starttime = ::gettickcount(); (int = 0; < iterations; ++i) { (int x = 0; x < x_size; ++x) { (int y = 0; y < y_size; ++y) { boostmatrix[x][y] *= 2.345; } } } endtime = ::gettickcount(); printf("[boost] elapsed time: %6.3f seconds\n", (endtime - starttime) / 1000.0); //------------------measure native----------------------------------------------- starttime = ::gettickcount(); (int = 0; < iterations; ++i) { (int x = 0; x < x_size; ++x) { (int y = 0; y < y_size; ++y) { nativematrix[x + (y * x_size)] *= 2.345; } } } endtime = ::gettickcount(); printf("[native]elapsed time: %6.3f seconds\n", (endtime - starttime) / 1000.0); homecoming 0; } in every possible permutation, benchmarks approximately same :
1) native code : 0.15s
2) boost multiarray : 1.0s using visual studio 2010.
my question : given using visual studio, how performance boost multiarrays?
update :
i switched on visual studio 2013. there, enabled qvec-report2 compiler switch. , interestingly, when compiled, started receiving info message saying compiler failing vectorize. here sample info message looks warning. received several such messages simplest of code.
--- analyzing function: void __cdecl `vector constructor iterator'(void * __ptr64,unsigned __int64,int,void * __ptr64 (__cdecl*)(void * __ptr64)) 1> d:\workspace\test\scrap\scrap\source.cpp : info c5002: loop not vectorized due reason '1301'
i think major clue why boost multiarrays performing slower on visual studio while perform alright on gcc. given information, can please think of way resolve problem?
@admins : kindly unmark question answered. have made major edit.
c++ performance optimization boost boost-multi-array
No comments:
Post a Comment