I am having some memory performance issues with my Eigen code. For example, using task manager to monitor memory usage I notice that the code uses a lot of memory (more than 10 GBs) which gets worse when increasing the size of Eigen tensors obviously.
I have tried few things to enhance the performance of my code in general, such as the following:
1. Use optimization flags. This ultimately gives me speed up but does not solve the memory performance issues:
|
-ffast-math -fno-math-errno -DNDEBUG -march=native -Ofast
|
2. Avoid passing "large arguments" by value instead by reference, for example:
|
void TensorProduct(Eigen::Tensor<std::complex<double>, 3>& Tensor1, Eigen::Tensor<double, 3>& Tensor2, Eigen::Tensor<std::complex<double>, 3>& Product){
|
3. Avoid creation of temporary objects since I am using dynamic size matrices. This was achieved by setting up a break point in
check_that_malloc_is_allowed() in Eigen/src/Core/util/Memory.h
that's triggered when a temporary is created.
I also read somewhere here that maybe I can manage memory through use of
Eigen::Map
instead. However, I have used this with Eigen matrix and not Tensor before, so I am wondering if there's a way to implement this so that it would help with my memory performance issues. For example, this is how my Eigen tensors are being initialized in my code:
1 2 3 4 5 6 7 8 9 10
|
static const int nx = 64;
static const int ny = 64;
static const int nz = 64;
Eigen::Tensor<std::complex<double>, 3> Product(nx,ny,nz);
Product.setZero();
Eigen::Tensor<std::complex<double>, 3> Tensor1(nx,ny,nz);
Tensor1.setZero();
Eigen::Tensor<double, 3> Tensor2(nx,ny,nz);
Tensor2.setZero();
|
Obviously, this is a small part of my code. The full code is much larger and more complex.
NOTE: A realistic working example of my code can be found on my GitHub:
https://github.com/JamieAlM/Eigen_Optimization
Is this an issue in particular with Eigen library? Is there no way to manage or enhance the memory performance in my ''Eigen'' code? Usually, this may indicate a memory leak when using c++ arrays however, this is not a possibility here so I am not sure how to fix this. Any tips would be much appreciated. Thanks.