Speed up code - deletion of rows/columns

2 visualizaciones (últimos 30 días)
Matthias Heindl
Matthias Heindl el 25 de Ag. de 2020
Respondida: Mir Amid Hashemi el 28 de Sept. de 2020
In my code I have a lot of big sized variables. In order for the code to run on my computer, I decided on deleting already assigned (and further processed, thus not anymore needed) rows / columns.
velocity_air(:,:,2) = [];
transformation_matrix(:,:,:,:,2) = [];
It seems to me, that by doing this, I succeed in reducing the required RAM, however those deleting assignments take a lot of time. In fact, the time increases exponentially when I increase the number of iterations.
Is there another way to delete used rows / columns?
What else can I do to have the code run faster?
  2 comentarios
KSSV
KSSV el 25 de Ag. de 2020
Check squeeze once. First you need to think why those many dimensions in matrix?
Matthias Heindl
Matthias Heindl el 25 de Ag. de 2020
The 5 dimensions in the matrix are the exception, but I believe them to be necessary.
I animate a system of particles (balls) colliding with each other elastically. In order for balls to make elastic collisions in 3D, it is necessary to turn your reference system in such a way, that you remain with an elastic collision in 1D. This is achieved by a 3 by 3 transformation matrix, transforming from one system to another.
This matrix has to be created for between each particle of type 1 (first index) and each particle of type 2 (second index). The 3 by 3 matrix itself is resembled by the third and fourth index and the last index is time.

Iniciar sesión para comentar.

Respuestas (2)

Steven Lord
Steven Lord el 25 de Ag. de 2020
I'm guessing you're doing this in a loop. In that case consider the old song 99 Bottles of Beer, slightly modified.
99 bottles of beer on the wall, 99 bottles of beer
Take one down, pass it around, slide all the other bottles forward to fill the slot, 98 bottles of beer on the wall
Doesn't quite have the same ring to it, does it? And you're going to be sliding all the bottles forward a lot. How often does that 99th bottle move? That's kind of what you're doing when you delete a page from the middle of the array.
How big are these "big sized variables"? How much memory does the system on which you're running your code have?
  1 comentario
Matthias Heindl
Matthias Heindl el 26 de Ag. de 2020
I'm doing it in a loop, yes.
The problem with simply executing the code was, that the variables would take up too much RAM, so I figured, it might be good, if I deleted parts of the variables on every iteration.
The illustration of yours is great. However I struggle to find a way to adapt it to my code. I use the velocity and position of particles in the last column for t = 2 to calculate those values for t = 3. Then I delete all values of position t = 2. Position t = 3 becomes t = 2 and on the next iteration I can again calculate the values for t = 3.

Iniciar sesión para comentar.


Mir Amid Hashemi
Mir Amid Hashemi el 28 de Sept. de 2020
I had a similar problem, however I don't know if it can be applied to your code. I created a fifo of constant length in the gpu. Whenever I considered one element of the fifo to have processed, I gather it to CPU ram and use that index to put a new element. What you might be doing is changing the dimension of your matrix dynamically and it slows performance.

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by