1

I am implementing a random forest algorithm. Each tree is trained in a recursive fashion (increasing the size of the call stack as the tree gets deeper) and I can train one tree without any problem (or several trees in a sequential loop).

Training all the trees in a Parallel.For loop, however, leads to a stack overflow. I am aware that the stack size can be configured when using new Thread(), as stated in : How to change stack size for a .NET program?

However, is it possible to do it with Parallel.For ? Or do I have to write all my threads, specifying the size of their stack ?

3
  • 3
    Consider using a Stack<T> and rewriting the method as iterative. Commented Jul 31, 2015 at 15:13
  • @Bas, could you be a little bit more specific (or send a link) please ? Commented Jul 31, 2015 at 15:46
  • 1
    stackoverflow.com/questions/531668/… Commented Jul 31, 2015 at 22:18

1 Answer 1

0

From social.msdn:

By default, TPL uses threads from the CLR ThreadPool. The stack size for a ThreadPool thread is the process' default stack size, which is determined by the executable file containing the process entry point.

You can change the default stack size for the process by editing this setting in the executable. One way to do this is with "editbin.exe," which comes with Vistual Studio. If your executable is "myprogram.exe" and you want a 2MB stack, you might run:

editbin /stack:2097152 myprogram.exe

Hope that helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.