?swap: Swap values of two arrays. As fast as you can, dear

LAPACK has a function called ?swap to swap the values stored in two arrays

      subroutine  dswap (n,dx,incx,dy,incy)
#
#     interchanges two vectors.
#     uses unrolled loops for increments equal one.
#     jack dongarra, linpack, 3/11/78.
#     modified 12/3/93, array(1) declarations changed to array(*)

This does not seem to be implemented in LinearAlgebra. (Maybe I have just looked in the wrong places.)

But the question is, how would this be done with the highest performance in Julia? I really do need to swap the values, not just the identifiers, by the way, because this will typically be done on slices.

LoopVectoriztion should give optimal assembly for the trivial implementation.

2 Likes