static int RunTest(int *iparam, float *dparam, real_Double_t *t_) { float *A, *Acpy = NULL, *L, *b, *x; real_Double_t t; int *piv; int n = iparam[TIMING_N]; int nrhs = iparam[TIMING_NRHS]; int check = iparam[TIMING_CHECK]; int lda = n; int ldb = n; /* Allocate Data */ A = (float *)malloc(lda*n*sizeof(float)); /* Check if unable to allocate memory */ if ( !A ){ printf("Out of Memory \n "); exit(0); } /* Initialize Plasma */ PLASMA_Init( iparam[TIMING_THRDNBR] ); if ( iparam[TIMING_SCHEDULER] ) PLASMA_Set(PLASMA_SCHEDULING_MODE, PLASMA_DYNAMIC_SCHEDULING ); else PLASMA_Set(PLASMA_SCHEDULING_MODE, PLASMA_STATIC_SCHEDULING ); /*if ( !iparam[TIMING_AUTOTUNING] ) {*/ PLASMA_Disable(PLASMA_AUTOTUNING); PLASMA_Set(PLASMA_TILE_SIZE, iparam[TIMING_NB] ); PLASMA_Set(PLASMA_INNER_BLOCK_SIZE, iparam[TIMING_IB] ); /* } else { */ /* PLASMA_Get(PLASMA_TILE_SIZE, &iparam[TIMING_NB] ); */ /* PLASMA_Get(PLASMA_INNER_BLOCK_SIZE, &iparam[TIMING_IB] ); */ /* } */ /* Initialiaze Data */ LAPACKE_slarnv_work(1, ISEED, n*lda, A); /* Allocate Workspace */ PLASMA_Alloc_Workspace_sgesv_incpiv(n, &L, &piv); /* Save AT in lapack layout for check */ if ( check ) { Acpy = (float *)malloc(lda*n*sizeof(float)); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,' ', n, n, A, lda, Acpy, lda); } t = -cWtime(); PLASMA_sgetrf_incpiv( n, n, A, lda, L, piv ); t += cWtime(); *t_ = t; /* Check the solution */ if ( check ) { b = (float *)malloc(ldb*nrhs *sizeof(float)); x = (float *)malloc(ldb*nrhs *sizeof(float)); LAPACKE_slarnv_work(1, ISEED, ldb*nrhs, x); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,' ', n, nrhs, x, ldb, b, ldb); PLASMA_sgetrs_incpiv( PlasmaNoTrans, n, nrhs, A, lda, L, piv, x, ldb ); dparam[TIMING_RES] = s_check_solution(n, n, nrhs, Acpy, lda, b, x, ldb, &(dparam[TIMING_ANORM]), &(dparam[TIMING_BNORM]), &(dparam[TIMING_XNORM])); free( Acpy ); free( b ); free( x ); } free( A ); free( L ); free( piv ); PLASMA_Finalize(); return 0; }
int main () { int cores = 2; int N = 10; int LDA = 10; int NRHS = 5; int LDB = 10; int info; int info_solution; int i,j; int LDAxN = LDA*N; int LDBxNRHS = LDB*NRHS; float *A1 = (float *)malloc(LDA*N*(sizeof*A1)); float *A2 = (float *)malloc(LDA*N*(sizeof*A2)); float *B1 = (float *)malloc(LDB*NRHS*(sizeof*B1)); float *B2 = (float *)malloc(LDB*NRHS*(sizeof*B2)); float *L; int *IPIV; /* Check if unable to allocate memory */ if ((!A1)||(!A2)||(!B1)||(!B2)){ printf("Out of Memory \n "); exit(0); } /*Plasma Initialize*/ PLASMA_Init(cores); printf("-- PLASMA is initialized to run on %d cores. \n",cores); /* Initialize A1 and A2 Matrix */ LAPACKE_slarnv_work(IONE, ISEED, LDAxN, A1); for ( i = 0; i < N; i++) for ( j = 0; j < N; j++) A2[LDA*j+i] = A1[LDA*j+i]; /* Initialize B1 and B2 */ LAPACKE_slarnv_work(IONE, ISEED, LDBxNRHS, B1); for ( i = 0; i < N; i++) for ( j = 0; j < NRHS; j++) B2[LDB*j+i] = B1[LDB*j+i]; /* Allocate L and IPIV */ info = PLASMA_Alloc_Workspace_sgetrf_incpiv(N, N, &L, &IPIV); /* LU factorization of the matrix A */ info = PLASMA_sgetrf_incpiv(N, N, A2, LDA, L, IPIV); /* Solve the problem */ info = PLASMA_sgetrs_incpiv(PlasmaNoTrans, N, NRHS, A2, LDA, L, IPIV, B2, LDB); /* Check the solution */ info_solution = check_solution(N, NRHS, A1, LDA, B1, B2, LDB); if ((info_solution != 0)|(info != 0)) printf("-- Error in SGETRS example ! \n"); else printf("-- Run of SGETRS example successful ! \n"); free(A1); free(A2); free(B1); free(B2); free(IPIV); free(L); PLASMA_Finalize(); exit(0); }