3 ms·
Some months ago, I used my lockdown time to make a repository containing implementations of a (bad) ray tracer in various parallel functional programming langua
by Athas 6y ago
Some months ago, I used my lockdown time to make a repository containing implementations of a (bad) ray tracer in various parallel functional programming languages[0]. I was quite happy that someone contributed a multicore OCaml implementation[1]. I think the most interesting part was the series of pull requests where an expert (I think even a multicore OCaml contributor) significantly improved the performance of the ray tracer [2,3,4]. I think being able to see the individual steps is valuable, because functional programming has long promised "effortless parallelism", and hence it is enlightening to see how different well-optimised parallel functional code is from an original more or less idiomatic sequential implementation. In OCaml's case, I don't think the difference is all that great. Most of the improvements came from using a library that provides a proper task pool, since "multicore OCaml" on its own seems to just provide relatively low-level (but very well implemented) primitives. It's a little bothersome that the programmer has to manually provide a chunk size, rather than letting the runtime figure such things out on its down, but it's not terrible. It was far more annoying that multicore OCaml is (or was) missing functions for measuring wall clock time...
Although there was a later PR that improved performance 40% just by moving code around to minimise allocations... [5] Unfortunate that such minor changes can have such dramatic impact.
[0]: https://github.com/athas/raytracers https://github.com/athas/raytracers
[1]: https://github.com/athas/raytracers/tree/master/ocaml https://github.com/athas/raytracers/tree/master/ocaml
[2]: https://github.com/athas/raytracers/pull/4 https://github.com/athas/raytracers/pull/4
[3]: https://github.com/athas/raytracers/pull/5 https://github.com/athas/raytracers/pull/5
[4]: https://github.com/athas/raytracers/pull/6 https://github.com/athas/raytracers/pull/6
[5]: https://github.com/athas/raytracers/pull/7 https://github.com/athas/raytracers/pull/7