# From a triangular matrix to a symmetric square matrix

I am a computational physics postgrad student, working with libraries like ATLAS and MAGMA. I have a matrix which is upper-triangular, and is the result of a Cholesky decomposition. I need to convert the upper-triangular matrix in to a symmetric, square matrix where the elements of the lower triangle are

mat(j,i) = mat(i,j)

I have a naive routine in C++ that simply does the above in a loop, but it's incredibly slow. I believe it's so slow because the CPU cache is poorly utilised - element i,j is quite far from element j,i.

Is there a clever mathematical trick that I can use to optimise this loop? Or alternatively, does anyone know of any fuctions in BLAS/similar libraries that can do this kind of operation?

If the libraries have efficient routines for matrix transposition, maybe you could just try $S=U+U^T$? (Provided that $U$ is strictly upper triangular of course, otherwise you have to divide the diagonal by 2 afterwards.) –  Hans Lundmark Jan 29 '11 at 15:36