         rhstraits.flags &= (ghost_densemat_flags)(~GHOST_DENSEMAT_VIEW);
         GHOST_CALL_GOTO(ghost_densemat_create(&rhs,rhs_in->map,rhstraits),err,ret);
         GHOST_CALL_GOTO(ghost_densemat_init_densemat(rhs,rhs_in,0,0),err,ret);
-        GHOST_CALL_GOTO(ghost_cu_memtranspose(rhs->map->nhalo,rhs->traits.ncols,&rhs->cu_val[rhs->map->dimpad*rhs->elSize],rhs->stride,&rhs_in->cu_val[rhs_in->map->dimpad*rhs_in->stride*rhs_in->elSize],rhs_in->stride,rhs->traits.datatype),err,ret);
+        GHOST_CALL_GOTO(ghost_cu_memtranspose(rhs->map->nhalo,rhs->traits.ncols,
+                    &rhs->cu_val[(rhs->map->dimhalo-rhs->map->nhalo)*rhs->elSize],rhs->stride,
+                    &rhs_in->cu_val[(rhs_in->map->dimhalo-rhs_in->map->nhalo)*rhs_in->stride*rhs_in->elSize],rhs_in->stride,
+                    rhs->traits.datatype),err,ret);
     } else {
         rhs = rhs_in;
     }

    } else {
        lhs = lhs_in;
    }
    if ((rhs_in->traits.flags & GHOST_DENSEMAT_SCATTERED) || ((rhs_in->traits.ncols == 1) && (rhs_in->traits.storage == GHOST_DENSEMAT_ROWMAJOR))) {
        PERFWARNING_LOG("Cloning rhs");
        if (rhs_in->traits.flags & GHOST_DENSEMAT_SCATTERED) {
            PERFWARNING_LOG("Cloning and compressing rhs before operation because it is scattered");
        }
        if ((rhs_in->traits.ncols == 1) && (rhs_in->traits.storage == GHOST_DENSEMAT_ROWMAJOR)) {
            PERFWARNING_LOG("Cloning and transposing rhs before operation because it is row-major");
        }
        ghost_densemat_traits rhstraits = rhs_in->traits;

#include "ghost/util.h"
#include "ghost/sparsemat.h"
#include "ghost/math.h"
#include "ghost/locality.h"

#include <complex>
#include <cuda_runtime.h>
