3 ms·
From the article at https://medium.com/@s.nawaz/optimizing-ray-tracing-in-haskell-3dc412fff20a https://medium.com/@s.nawaz/optimizing-ray-tracing-in-haskel...:
by WJW 6y ago
From the article at https://medium.com/@s.nawaz/optimizing-ray-tracing-in-haskell-3dc412fff20a https://medium.com/@s.nawaz/optimizing-ray-tracing-in-haskel...:
> let colors = fmap computeColor coordinates
to
> let colors = fmap computeColor coordinates `using` parListChunk 32 rseq
So half a line added to parallelize the mapping a pure computation including using a sensible threadpool implementation. How impressive you find this depends on how you define "easy in another language". Rayon comes pretty close but you can encode some properties about your computation in the Haskell type system that Rust does not yet support and so the safety of some computations can be statically proven in Haskell but not in Rust.
- CJefferson 6y agoI think this reasoning goes the other way (as I understand), Rust can express threadsafe mutability, as you can only have one mutable reference to any object, so if I can mutate, I know I have the only reference.
- twic 6y agoMeh. var colours = coordinates.stream().map(this::computeColour).collect(toList()); var colours = coordinates.stream().parallel().map(this::computeColour).collect(toList()); Java doesn't do as much (well, anything) to help you make sure the implementation of computeColour is suitable for parallelisation, but that comes with the territory. On the other hand, it will automatically split the stream up appropriately for the number of cores you have.
- przemo_li 6y agoYou have just started that Java isn't as good but since it isn't, it shouldn't be judged so hardly and thus concluded that Java is as good as any (when using softer requirements just for Java) I also think that explicit threadpool isn't the same thing as implicit one. But that's very minor issue here easily solvable by different api for parallel method
- AnimalMuppet 6y agoJava's type safety in general is less than Haskell's. That's a separate topic from ease of parallelization in Java and Haskell.
- adwn 6y agoRay-tracing is absolutely trivial to parallelize, because every pixel is computed independently of all others. That would even be trivial to parallelize in C, and that's saying a lot!