On Sun, Aug 24, 2008 at 18:58, Michel Lestrade
I am considering rewriting part of our ray tracing code to use the Boost thread library. As many of you might know, ray tracing is a task that lends itself well to a parallel approach since each ray is independent from the other. However, the code right now is in Fortran which doesn't support task level parallelism easily ... The thread_group class seems ideally suited to my needs (one thread == one ray) but there is at least one problem I envision that I would like to solve before embarking on this fairly time-consuming rewrite.
It's worth pointing out that, as I recall, you don't really want more continually-active threads than, say, twice your number of cores. It would be nice to run one thread per ray, but the switching and OS management overhead will kill you if you attempt to run thousands of threads at once, which I assume you'd need with 1:1. (Erlang, for example, which is conceptually based on many, many communicating processes, uses its own implementation, rather than OS threads of processes.) I think you'd be much better off creating a "ray queue" of some sort, then using a thread_group with cores+1 threads that all continually poll the ray queue for which one to work on. So that's not exactly an answer to the question you asked, but I think that's the usual wisdom with regards to threads. HTH, ~ Scott