Lockstep iteration in parallel: Error: cannot have parameter of type `void`

kdevel kdevel at vogtner.de
Tue May 23 19:29:08 UTC 2023


On Saturday, 20 May 2023 at 18:27:47 UTC, Ali Çehreli wrote:
> [...]
> And I've just discovered something.

Me2! The serial version using array indexing

    void vec_op_naive0 (double [] outp, const double [] inp,
       double function (double) fp)
    {
       enforce (inp.length == outp.length);
       auto i = inp.length;
       while (i--)
          outp [i] = fp (inp [i]);
    }

is nearly thrice as fast as the one using lockstep

    void vec_op (double [] outp, const double [] inp,
       double function (double) fp)
    {
       foreach (ref a, b; lockstep (outp, inp))
          a = fp (b);
    }

I wonder if under this circumstances (lack of speed, lack of 
parallelism out-of-the-box) it makes any sense to prefer lockstep 
over
the indexed array access.


More information about the Digitalmars-d-learn mailing list