-2

I have C++ code which solves a partial differential equation numerically. Everything works fine, but after the first 10 or so iterations, the code starts to run about 3 times as slow.

Some possibly relevant information:

  • I am using the package Eigen for a lot of calculations
  • I am storing a large amount of data in an array (about 100000 double precision values every iteration)

I don't know very much about how computers work or about coding in c++, and was wondering if anybody might be able to point me in the right direction so I can possibly fix this problem.

I can also post the code if it would be helpful, but it's very long.

Bart
  • 19,692
  • 7
  • 68
  • 77

1 Answers1

2

Like Oli said, it could be anything.

It could be the algorithm. Do you know if that code is not supposed to slow down after certain amount of iteration? Maybe the nature of your problem is such that the program has to slow down.

It could be the computer running out of memory. Try running the same program on a computer with more memory, does it do better? Then you have to do memory profiling and identify any objects (like large arrays) in memory that are lying around but are not being used. And fix the code so that it doesn't happen. Look up "memory leak" and understand how to fix it.

It could be that there is no memory leak, but as the iterations pile up, the process takes more memory to the point that it needs to constantly swap memory pages back and forth from the hard drive, this behavior is common and is consistent with a sudden dip in speed. Try to rewrite the program so that the memory footprint is not expanding like that. Try to manage the data so that unused data is either deleted or written to a file.

Or something else...

Hope this helps.

Spundun
  • 3,936
  • 2
  • 23
  • 36