Matrix.traceManyThroughInParallel
- raytracing.Matrix.traceManyThroughInParallel(self, inputRays, progress=True, processes=None)
This is an advanced technique to gain from parallel computation: it is the same as traceManyThrough(), but splits this call in several other parallel processes using the multiprocessing module, which is os-independent.
Everything hinges on a simple pool.map() command that will apply the provided function to every element of the array, but across several processors. It is trivial to implement and the benefits are simple: if you create 8 processes on 8 CPU cores, you gain a factor of approximately 8 in speed. We are not talking GPU acceleration, but still: 1 minute is shorter than 8 minutes.
- Parameters:
inputRays (object of Ray class) – A group of rays
progress (bool) – If True, the progress in percentage of the traceTrough is shown (default=True)
- Returns:
outputRays – List of Ray() (i,e. a raytrace), one for each input ray.
- Return type:
object of Ray class
Notes
One important technical issue: Pool accesses the array in multiple processes and cannot be dynamically generated (because it is not thread-safe). We explicitly generate the list before the computation, then we split the array in #processes different lists.