|
Boost Users : |
From: Michel Lestrade (michel.lestrade_at_[hidden])
Date: 2008-08-24 18:58:44
Hi,
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.
Just to give you some background, what we are doing is not ray tracing
in the visualization/render sense: rather, it is a scientific
application used to determine the light emission pattern of certain
devices without waveguides (such as LEDs). So keep in mind that not all
the conventional ray tracing approaches will work for me. I also come
from a physics/engineering background so I am not up to date on all the
newer object-oriented techniques and concepts.
Now to the heart of the matter: in our approach, each of the initial
rays is split into a reflected/refracted ray every time a material
interface is reached which generates a secondary ray. Each secondary ray
can generate other secondary rays when they hit an interface and so on
... This goes on until the power in each ray has decayed sufficiently
(the material is usually absorbing), all rays exit the device or a
maximum number of rays has been reached. That means that I do not know
ahead of time how many rays (or threads) that I will have.
This brings me to my question: can I add new threads to thread group
while it is running ? All of the code samples for thread_group seem to
call add_thread() on a fixed number of objects before calling
join_all(). So it seems that the execution of the thread does not start
at the moment it is added to the group but at the moment join_all() is
called.
In my case, I would have a join_all() first and then periodically add
new threads: so this is basically a dynamic queue with new rays being
pushed at the end. How can I start these threads automatically if
add_thread does not start the execution ? Should I call join() on the
new threads before adding them to the thread group instead of using
join_all() ?
Should I give up on thread_group and store my thread objects in some
other container ?
Any alternative solutions or a code sample with a dynamically changing
thread_group would be appreciated. I am hoping someone has faced a
similar problem in another context ...
Regards,
Michel Lestrade
Crosslight Software
P.S. Since I am a new user of Boost, I will go ahead and use the latest
version (1.36.0). I already built the binaries for my tool set (VS 2008).
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net