Problems with eigen library on Teensy 3.6

Status
Not open for further replies.

Borja

Active member
Good morning,

I am carrying out a benchmark of a LU factorization using the Arduino library Eigen (https://github.com/bolderflight/Eigen). For random matrices up to 100x100 the Teensy runs and sends the information of the elapsed time correctly (around 410ms each). However, if the matrices are bigger (150x150 or 300x300) it sends nothing, could it be memory problems?

I attach a copy of this simple code.
View attachment eigen.ino

Thanks

Borja
 
The code is this big - easily posted in a # 'CODE ' block.

Code:
#include <Eigen.h>     // Calls main Eigen matrix class library
#include <Eigen/LU>    // Calls inverse, determinant, LU decomp., etc.
using namespace Eigen; // Eigen related statement; simplifies syntax for declaration of matrices

Eigen::MatrixXd A;
Eigen::VectorXd b;
Eigen::VectorXd x;

elapsedMillis sincePrint;

#define SIZE 100

void setup() {
  // put your setup code here, to run once:

  A.resize(SIZE, SIZE);
  b.resize(SIZE);
  x.resize(SIZE);

  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:

  sincePrint = 0;

  A.setRandom();
  b.setRandom();

  x = A.lu().solve(b);


  Serial.print("Total time: ");
  Serial.print(sincePrint);
  Serial.print("\n");
}

By 'sends nothing' - is that send nothing to SerMon - no printing at all?

First guess is it is exhausting memory and not returning from "A.resize(SIZE, SIZE);" when size is 22500 for 150*150 instead of a mere 10,000. I don't know how big an 'Eigen::MatrixXd ' element is - this should be known to you?

If they are int's then 10,000 is 40K bytes and runtime allocation of 22,500 int's would be 90,000 bytes for the A matrix plus whatever over head or added space if larger than a 4 byte int - which is likely 8 bytes.

Place a wait on Serial in setup and print before/after each .resize and see how far it gets:
Code:
void setup() {
  while ( !Serial );

  Serial.print("B.resize ...\n");
  b.resize(SIZE);
  Serial.print("x.resize ...\n");
  x.resize(SIZE);
  Serial.print("A.resize ...\n");
  A.resize(SIZE, SIZE);
  Serial.print("Done .resize ...\n");

  // ...
 
Thank for you the reply.

I've just changed MatrixXd for MatrixXf (doubles for floats) and I could run the program with a size of 150 instead of "only" 100. Also I've added some prints after the resizings of the matrices and both vectors, but it sends many "ovf" to the serial monitor when I try to check the stored values. It's pretty clear that the memory is not enough to store the matrices, even using only floats.

Thanks!
 
As you mentioned it probably won't fit. That is if you have 300x300 floats (4 bytes) that is 300*300*4 bytes minimum or 360000 bytes which probably does not fit well into the 256K RAM of T3.6.

The good news is it might work on the new T4 when it is released, which has 1 meg of ram. Although split into a couple of chunks...
 
Status
Not open for further replies.
Back
Top