Hi guys. I have a very strange problem. In my program, I enter a number of particles for the program to work on, and a number of steps for it to go through. The more particles, the longer it will have to work. The main core of my program is essentially:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
//User selected int nstep up here.
for(int istep=1;istep<nstep;istep++){
cout << "We're at the top of the loop! << endl;
someFn();
anotherFn();
etcFun();
//and so on.
cout << "We have done " << istep << " out of " << nstep << endl;
}
|
The functions called repeatedly from inside the for loop are pretty resource heavy. However, they've always worked in the past. I recently made a few changes to them, and now I'm getting the most bizarre bug: It will run for some number of iterations (the number seems to depend on the number of particles, but not directly in any way. Not proportionally, not inversely proportional), then just stop. It doesn't crash, just pauses indefinitely until I hit Ctrl+C to kill it.
Now here's the weird thing: It is stalling between the "We have done x out of y" print statement, and the print statement at the top of the loop! There is
nothing in between those.
Now, as a last ditch effort I tried commenting out the functions one by one and letting the program run. For most of them, it didn't make a difference, it still stalled. But for the usual troublemaker, let's say it was someFn() in this case, when I commented it out, things work fine (minus it not doing its job). The loop works correctly. But this doesn't make sense! It's stalling in between the print statements! Furthermore, I have at the VERY beginning and VERY end of someFn() two similar print statements (cout << "Entering someFn()" << endl; and cout << "Leaving someFn()" << endl;), and there's no case of it entering and not leaving.
There is no multithreading or anything fancy going on. What could it be?
Thanks!