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 ?

Community
  • 1
  • 1
RUser4512
  • 1,050
  • 9
  • 23

1 Answers1

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!

Sors
  • 494
  • 1
  • 4
  • 12