I just finished coding a (basic) ray tracer in C# for fun and for the learning experience. Now I want to further that learning experience. It seems to me that ray tracing is a prime candidate for parallel processing, which is something I have very little experience in. My question is this: how do I know the optimum number of concurrent processes to run?My first instinct tells me: it depends on how many cores my processor has, but like I said I'm new to this and I may be neglecting something.
Optimum Number of Parallel Processes
parallelism
The .NET framework has a built-in setting that optimizes the number of concurrent threads if you use the ThreadPool directly or the more convenient Task Parallel Library API. I believe it is something like 20 per logical core (but I don't see that in the documentation anymore). If you want to control your threads directly, you can still call the ThreadPool's GetMaxThreads function to see what the framework recommends. For a really neat demo of leveraging the features of C#, check out this raytracer implemented using LINQ