/*
 *   -- micMAGMA (version 0.1) --
 *      Univ. of Tennessee, Knoxville
 *      Univ. of California, Berkeley
 *      Univ. of Colorado, Denver
 *      April 2012
 *
 *  @generated ds Fri Nov 22 14:21:24 2013
 */

#include <mkl.h>

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

#include "magma.h"
#include "magma_ds_server.h"

#define PRECISION_d

void call_dlag2s(magma_mic_dlag2s_param dlag2s_param)
{
    magma_int_t m, n, lda, ldas, info;
    double *da;
    float *das;
    
    m    = dlag2s_param.m;
    n    = dlag2s_param.n;
    da   = (double *)dlag2s_param.dA;
    lda  = dlag2s_param.lda;
    das  = (float *)dlag2s_param.dAs;
    ldas = dlag2s_param.ldas;
    
    dlag2s( &m, &n, (double *)da, &lda, (float *)das, &ldas, &info);
    
    return;
}

void call_dsgesv(magma_mic_dsgesv_param dsgesv_param) {
    magma_int_t n, nrhs, ldda, lddb, lddx, *dipiv, iter, info;
    double *da, *db, *dx, *dworkd;
    float *dworks;
    
    n      = dsgesv_param.n;
    nrhs   = dsgesv_param.nrhs;
    da     = (double *)dsgesv_param.d_A;
    ldda   = dsgesv_param.lda;
    dipiv  = dsgesv_param.d_ipiv;
    db     = (double *)dsgesv_param.d_B;
    lddb   = dsgesv_param.ldb;
    dx     = (double *)dsgesv_param.d_X;
    lddx   = dsgesv_param.ldx;
    
    dworkd = (double *)dsgesv_param.d_work;
    dworks = (float  *)dsgesv_param.d_swork;

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

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


