You may use broadcasting directly via calc.(ret,Ref(dt_m),Ref(jacobian)) IMHO. A real minimal working example would be needed to go further.
More generally, in Julia, it is often better to avoid vectorized calls and use directly loops: they are easier on the compiler and therefore generally faster (they might avoid allocations of unnecesary arrays, etc.)
Ok thank you. I will try it out and get back to you if I run into problems with a real example.
As regards your second point, I could loop over the elements of the vector ‘ret’.
What is the most efficient way to save the results in each iteration? in an ever expanding matrix?
No, usually the efficient way is to pre-allocate the matrix, by creating it with, e.g., zeros((n,m)) or the generic version Array{T}(undef,n,m) if i remember correctly.
But the most efficient way is, when you merge this part of the code with the next part (wich is maybe you do something with the ret vector, this vector is not your output ?), just remove the allocated vector.
You can try something like this, with a generator:
reduce(vcat, calc_mc_w_r(x, dt_m, jacobian) for x in eachslice(ret; dims=1))
In terms of efficiency, it should be faster to concatenate horizontally, so this entire thing may be faster if calc_mc_w_r returns an 3xM matrix instead of an Mx3 matrix.