Closed Farbfetzen closed 4 years ago
Drop 1 million grains in the middle and wait for an eternity for it to finish. Looks like the time it takes grows quadratically. Therefore using symmetry and only iterating over a quarter of the matrix may help.
Ok, I implemented the improvement of iterating over the top right quarter of the matrix. The function is now much faster. But is still takes very long for a million grains. Maybe I'm missing something and have to think of a better way. I could iterate over only an eight of the matrix. And also better handle the edges.
New idea: Instead of only distributing 4 grains to neighbouring cells, maybe divide the stack into quarters and move those around. But first add a regression test for large sandpiles. See comment in sandpile test file. Measure the performance before and after.
Maybe it would be good to instead of using indices just copy parts of the matrix around like a stamp?
Maybe it would be good to instead of using indices just copy parts of the matrix around like a stamp?
Nope, using vector indices is much faster than copying matrices around.
Reduce the time it takes to generate big sandpiles. Use the symmetry.