/*
 *   -- micMAGMA (version 0.1) --
 *      Univ. of Tennessee, Knoxville
 *      Univ. of California, Berkeley
 *      Univ. of Colorado, Denver
 *      April 2012
 *
 *  @precisions mixed zc -> ds
 */

#include <mkl.h>

#include <mkl_trans.h>
#include <scif.h>
#include <fcntl.h>
#include <offload.h>

#include "magma.h"
#include "magma_zc_server.h"

#define PRECISION_z

void call_zlag2c(magma_mic_zlag2c_param zlag2c_param)
{
    magma_int_t m, n, lda, ldas, info;
    magmaDoubleComplex *da;
    magmaFloatComplex *das;
    
    m    = zlag2c_param.m;
    n    = zlag2c_param.n;
    da   = (magmaDoubleComplex *)zlag2c_param.dA;
    lda  = zlag2c_param.lda;
    das  = (magmaFloatComplex *)zlag2c_param.dAs;
    ldas = zlag2c_param.ldas;
    
    zlag2c( &m, &n, (MKL_Complex16 *)da, &lda, (MKL_Complex8 *)das, &ldas, &info);
    
    return;
}

void call_zcgesv(magma_mic_zcgesv_param zcgesv_param) {
    magma_int_t n, nrhs, ldda, lddb, lddx, *dipiv, iter, info;
    magmaDoubleComplex *da, *db, *dx, *dworkd;
    magmaFloatComplex *dworks;
    
    n      = zcgesv_param.n;
    nrhs   = zcgesv_param.nrhs;
    da     = (magmaDoubleComplex *)zcgesv_param.d_A;
    ldda   = zcgesv_param.lda;
    dipiv  = zcgesv_param.d_ipiv;
    db     = (magmaDoubleComplex *)zcgesv_param.d_B;
    lddb   = zcgesv_param.ldb;
    dx     = (magmaDoubleComplex *)zcgesv_param.d_X;
    lddx   = zcgesv_param.ldx;
    
    dworkd = (magmaDoubleComplex *)zcgesv_param.d_work;
    dworks = (magmaFloatComplex  *)zcgesv_param.d_swork;

#if defined(PRECISION_z)
    double *rwork = (double *)malloc(n*sizeof(double));
    
    zcgesv( &n, &nrhs, (MKL_Complex16 *)da, &ldda, dipiv,
            (MKL_Complex16 *)db, &lddb, (MKL_Complex16 *)dx, &lddx,
            (MKL_Complex16 *)dworkd, (MKL_Complex8 *)dworks,
            (double *)rwork, &iter, &info);
#else
    zcgesv( &n, &nrhs, (MKL_Complex16 *)da, &ldda, dipiv,
            (MKL_Complex16 *)db, &lddb, (MKL_Complex16 *)dx, &lddx,
            (MKL_Complex16 *)dworkd, (MKL_Complex8 *)dworks,
            &iter, &info);
#endif

    printf("\n");
    printf("Number of iterations : %3d, info = %2d\n", iter, info);
    
    return;
}


