Hi all. I'm following a course with coursera (algorithm 1) and my program for the assignment crashes inexorably (many are experimenting the same thing there, the assignment asks for a recursive program for solving a big graph of 500000 nodes). I'm using a version of g++ from MinGW with the editor Geany and windows7. The current setup is:
Having a program crash is about as generic as an error can get. What makes you suspect that the stack size is the issue? Do you get a run time error code? What does event viewer tell you about the crash?
There technically are ways of making an arbitrarily large stack, if you're willing to mess around with Assembly. It's a really ugly solution, though, and I don't recommend it ever.
IMO, if you have to process an arbitrarily large data structure recursively, you should put the recursion somewhere that isn't the call stack. Hell, even making a dynamically allocated pseudo-stack+switch is better.
Thank you all. I guess Computergeek01 is right. The fact is I'm not able (for now) to make my implementation of Kosaraju's algorithm work. I have read on the forum of coursera that some have solved their problems by enlarging the stack on their computers, so I was trying this way "blindly", so to say, but I have changed my mind now; after all I'm there to learn. It's a really hard assignment - compared to my current skills. For some days now I have been trying to write a iterative version of that algorithm, I hope to succeed. Thank you all again.
well, just a little update for those who may need the same piece of information in the future. I succeeded in doing the program work; it was correct and simply needed more memory, as many suggested in the coursera forum, because the graph had 500000 nodes and 5 million edges. In windows7 the default stack size is 1MB. As "long double main" wrote, the command is -Wl,--stack,<size>
In the GCC Options for Linking (http://gcc.gnu.org/onlinedocs/gcc-3.0/gcc_3.html#SEC16) I read that -Wl\,option Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas.
In the Geany editor I found by trials that the instruction may be: g++ -std=c++11 -Wall -Wl,--stack -Wl,<size> -o "%e""%f"
I set <size> to a very large number, just to solve my problem; then I set again the default: g++ -std=c++11 -Wall -o "%e""%f"