1. 22
  1.  

  2. 1

    My very first Rust project was a raytracer, and my second one a path-tracer. I do tend to agree with the OP that the borrow checker might feel like more of a hindrance on this kind of code, compared to simply using Asan.

    However, I really liked using rayon instead of having to write my own thread pool as I did in C99. Going from iter to par_iter on my vector and having everything just work was great .

    1. 1

      You could likely use OpenMP to do something similar without too much effort in C or C++.

      1. 2

        Yup! This requires one parallel, schedule(guided) pragma.

        It does come with trade offs though. I find asm output with OpenMP in the mix more difficult to follow, and it’s compiler dependent. Generally I’d favor writing the basic thread pool or parallel for myself.

        1. 1

          I have two things to say about that : first OpenMP is not portable, being a compiler extension, whereas rayon would work on any Rust target and with any Rust compiler.

          Secondly, I got way better results (pretty much a x8 on my 8 core system) using rayon, whereas OpenMP only tripled the performance or so. I had to write my threading using pthread to actually make use of my cores correctly.

          1. 1

            That’s quite a drop in performance! Did you get a sense of where the bottlenecks were in your OpenMP version?

            Anecdotally, I’ve always needed to tweak job sizing/assignment and fix a few instances of false sharing when applying the pragmas to previously single threaded code.

            1. 1

              Yeah, I would have had to fix a few things, which happened when I refactored to use pthread. My point was mostly to explain that rayon really has that magical feeling of modifying one line and having it just work.

              And that comes from Rust imposing the architectural decisions that lead to good threading support, compared to C where you’re free to do whatever.

              1. 2

                And that comes from Rust imposing the architectural decisions that lead to good threading support, compared to C where you’re free to do whatever.

                I can’t say I agree with this. The architecture rayon guides you towards is about equivalent to the architecture OpenMP’s parallel-for pragma guides you towards. I think rayon has some better defaults, and I’ve found its codebase easier to dig through than OpenMPs, but don’t really see any large narrative there.

                1. 1

                  Yeah, but OpenMP isn’t C. C by itself doesn’t guide you to any architecture. I’m not talking about OpenMP.