This forum has been archived. All content is frozen. Please use KDE Discuss instead.

std::map bad_alloc with dynamic sized Matrix

Tags: None
(comma "," separated)
kp0987
Registered Member
Posts
21
Karma
0
I am getting bad_alloc with std::map<string, MatrixXd> under Cygwin (GCC4.3.4). The following code fragment works fine on MacOSX (GCC 4.2.1) and MSVC2010, but not Cygwin (GCC 4.3.4).

Code: Select all
  MatrixXd tmp_mat(1,1);
  std::map<std::string, Eigen::MatrixXd> datamap;
 
  cout << "START" << endl;
  datamap["KEY"] = tmp_mat; 
  cout << "END" << endl;


I also tried using the aligned_allocator in http://eigen.tuxfamily.org/dox/TopicStlContainers.html even though this is only for fixed types, but still get the problem.

Any help appreciated. Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
That's a very strange issue. For dynamic size matrices such as MatrixXd there should not be any alignment trouble. Nevertheless, you could try to use:

Matrix<double,Dynamic,Dynamic,DontAlign>

as your matrix type. If that works for you, you could try to use that type only for the std::map object to see if the issue really comes from the use of std::map or not.
kp0987
Registered Member
Posts
21
Karma
0
Thanks. I tried this. It compiles OK, but I still get the bad_alloc exception. Does that mean it is some issue unrelated to alignment?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
hm bad_alloc means you are running out of memory. Perhaps a memory leak?
kp0987
Registered Member
Posts
21
Karma
0
It took a while, but I found out that the following code will work/not work depending on compiler options:
Code: Select all
// map_test.cpp

// Will pass:
// g++        -g -o map_test map_test.cpp -I ../ext_lib/eigen
// g++ -msse  -g -o map_test map_test.cpp -I ../ext_lib/eigen

// Will fail, unless also #define EIGEN_DONT_VECTORIZE
// g++ -msse2 -g -o map_test map_test.cpp -I ../ext_lib/eigen
// g++ -msse3 -g -o map_test map_test.cpp -I ../ext_lib/eigen
// g++ -msse4 -g -o map_test map_test.cpp -I ../ext_lib/eigen

//#define EIGEN_DONT_VECTORIZE

#include <map>
#include <Eigen/Core>

using namespace Eigen;
using namespace std;

int main()
{
  MatrixXd tmp_mat(1,1);
  std::map<std::string, MatrixXd> datamap; 
 
  #ifdef EIGEN_VECTORIZE
  cout << "Eigen vectorized" << endl;
  #else
  cout << "Eigen NOT vectorized" << endl;
  #endif
 
  cout << "START" << endl;
  datamap["KEY"] = tmp_mat; 
  cout << "END" << endl;
 
  return 0;
}


If -msse2 is included in the compiler options then a bad_alloc will occur.

Using Eigen 3.0.0 on Windows XP using Cygwin (g++ 4.3.4).

I am building the cmake tests now to see if any failures occur. Should I submit this to the Dashboard (or do you only want latest source builds there)?

I don't see Xcode (gcc 4.2.1) or cygwin builds on the dashboard. I may be able to regularly run & submit these tests if you are interested (depending on build & run times). Please let me know.

Thanks.
kp0987
Registered Member
Posts
21
Karma
0
All tests pass with default ctest options.

Setting -DEIGEN_TEST_SSE2=ON results in 32 failures:
Code: Select all
The following tests FAILED:
        251 - lu_3 (Failed)
        252 - lu_4 (Failed)
        253 - lu_5 (Failed)
        254 - lu_6 (Failed)
        255 - lu_7 (Failed)
        263 - inverse_5 (Failed)
        264 - inverse_6 (Failed)
        270 - qr_1 (Failed)
        271 - qr_2 (Failed)
        272 - qr_3 (Failed)
        274 - qr_5 (Failed)
        276 - qr_6 (Failed)
        277 - qr_7 (Failed)
        282 - qr_colpivoting_1 (Failed)
        283 - qr_colpivoting_2 (Failed)
        284 - qr_colpivoting_3 (Failed)
        291 - qr_fullpivoting_1 (Failed)
        292 - qr_fullpivoting_2 (Failed)
        293 - qr_fullpivoting_3 (Failed)
        348 - jacobisvd_7 (Failed)
        349 - jacobisvd_8 (Failed)
        401 - stdvector_3 (Failed)
        406 - stdvector_overload_3 (Failed)
        411 - stdlist_3 (Failed)
        416 - stddeque_3 (Failed)
        440 - householder_2 (Failed)
        441 - householder_3 (Failed)
        442 - householder_4 (Failed)
        443 - householder_5 (Failed)
        444 - householder_6 (Failed)
        445 - householder_7 (Failed)
        482 - zerosized (Failed)
kp0987
Registered Member
Posts
21
Karma
0


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], q.ignora, watchstar