/* //////////////////////////////////////////////////////////////////////////// -- Debugging file */ int main( int argc, char** argv) { TESTING_INIT(); magma_d_solver_par solver_par; magma_d_preconditioner precond_par; solver_par.epsilon = 10e-16; solver_par.maxiter = 1000; solver_par.verbose = 0; precond_par.solver = Magma_JACOBI; magma_dsolverinfo_init( &solver_par, &precond_par ); double one = MAGMA_D_MAKE(1.0, 0.0); double zero = MAGMA_D_MAKE(0.0, 0.0); magma_d_sparse_matrix A, B, B_d; magma_d_vector x, b; // generate matrix of desired structure and size magma_int_t n=10; // size is n*n magma_int_t nn = n*n; magma_int_t offdiags = 2; magma_index_t *diag_offset; double *diag_vals; magma_dmalloc_cpu( &diag_vals, offdiags+1 ); magma_index_malloc_cpu( &diag_offset, offdiags+1 ); diag_offset[0] = 0; diag_offset[1] = 1; diag_offset[2] = n; diag_vals[0] = MAGMA_D_MAKE( 4.0, 0.0 ); diag_vals[1] = MAGMA_D_MAKE( -1.0, 0.0 ); diag_vals[2] = MAGMA_D_MAKE( -1.0, 0.0 ); magma_dmgenerator( nn, offdiags, diag_offset, diag_vals, &A ); // convert marix into desired format B.storage_type = Magma_SELLC; B.blocksize = 8; B.alignment = 8; // scale matrix magma_dmscale( &A, Magma_UNITDIAG ); magma_d_mconvert( A, &B, Magma_CSR, B.storage_type ); magma_d_mtransfer( B, &B_d, Magma_CPU, Magma_DEV ); // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); // solver magma_dpcg( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_mfree(&B_d); magma_d_mfree(&B); magma_d_mfree(&A); magma_d_vfree(&x); magma_d_vfree(&b); TESTING_FINALIZE(); return 0; }
/* //////////////////////////////////////////////////////////////////////////// -- testing any solver */ int main( int argc, char** argv ) { TESTING_INIT(); magma_dopts zopts; magma_queue_t queue; magma_queue_create( /*devices[ opts->device ],*/ &queue ); int i=1; magma_dparse_opts( argc, argv, &zopts, &i, queue ); real_Double_t res; magma_d_sparse_matrix Z, A, AT, A2, B, B_d; B.blocksize = zopts.blocksize; B.alignment = zopts.alignment; while( i < argc ) { if ( strcmp("LAPLACE2D", argv[i]) == 0 && i+1 < argc ) { // Laplace test i++; magma_int_t laplace_size = atoi( argv[i] ); magma_dm_5stencil( laplace_size, &Z, queue ); } else { // file-matrix test magma_d_csr_mtx( &Z, argv[i], queue ); } printf( "# matrix info: %d-by-%d with %d nonzeros\n", (int) Z.num_rows,(int) Z.num_cols,(int) Z.nnz ); // scale matrix magma_dmscale( &Z, zopts.scaling, queue ); // remove nonzeros in matrix magma_dmcsrcompressor( &Z, queue ); // convert to be non-symmetric magma_d_mconvert( Z, &A, Magma_CSR, Magma_CSRL, queue ); // transpose magma_d_mtranspose( A, &AT, queue ); // convert, copy back and forth to check everything works magma_d_mconvert( AT, &B, Magma_CSR, zopts.output_format, queue ); magma_d_mfree(&AT, queue ); magma_d_mtransfer( B, &B_d, Magma_CPU, Magma_DEV, queue ); magma_d_mfree(&B, queue ); magma_dmcsrcompressor_gpu( &B_d, queue ); magma_d_mtransfer( B_d, &B, Magma_DEV, Magma_CPU, queue ); magma_d_mfree(&B_d, queue ); magma_d_mconvert( B, &AT, zopts.output_format,Magma_CSR, queue ); magma_d_mfree(&B, queue ); // transpose back magma_d_mtranspose( AT, &A2, queue ); magma_d_mfree(&AT, queue ); magma_dmdiff( A, A2, &res, queue); printf("# ||A-B||_F = %8.2e\n", res); if ( res < .000001 ) printf("# tester: ok\n"); else printf("# tester: failed\n"); magma_d_mfree(&A, queue ); magma_d_mfree(&A2, queue ); magma_d_mfree(&Z, queue ); i++; } magma_queue_destroy( queue ); TESTING_FINALIZE(); return 0; }
/* //////////////////////////////////////////////////////////////////////////// -- testing sparse matrix vector product */ int main( int argc, char** argv ) { TESTING_INIT(); magma_queue_t queue; magma_queue_create( /*devices[ opts->device ],*/ &queue ); magma_d_sparse_matrix hA, hA_SELLP, hA_ELL, dA, dA_SELLP, dA_ELL; hA_SELLP.blocksize = 8; hA_SELLP.alignment = 8; real_Double_t start, end, res; magma_int_t *pntre; double c_one = MAGMA_D_MAKE(1.0, 0.0); double c_zero = MAGMA_D_MAKE(0.0, 0.0); magma_int_t i, j; for( i = 1; i < argc; ++i ) { if ( strcmp("--blocksize", argv[i]) == 0 ) { hA_SELLP.blocksize = atoi( argv[++i] ); } else if ( strcmp("--alignment", argv[i]) == 0 ) { hA_SELLP.alignment = atoi( argv[++i] ); } else break; } printf( "\n# usage: ./run_dspmv" " [ --blocksize %d --alignment %d (for SELLP) ]" " matrices \n\n", (int) hA_SELLP.blocksize, (int) hA_SELLP.alignment ); while( i < argc ) { if ( strcmp("LAPLACE2D", argv[i]) == 0 && i+1 < argc ) { // Laplace test i++; magma_int_t laplace_size = atoi( argv[i] ); magma_dm_5stencil( laplace_size, &hA, queue ); } else { // file-matrix test magma_d_csr_mtx( &hA, argv[i], queue ); } printf( "\n# matrix info: %d-by-%d with %d nonzeros\n\n", (int) hA.num_rows,(int) hA.num_cols,(int) hA.nnz ); real_Double_t FLOPS = 2.0*hA.nnz/1e9; magma_d_vector hx, hy, dx, dy, hrefvec, hcheck; // init CPU vectors magma_d_vinit( &hx, Magma_CPU, hA.num_rows, c_zero, queue ); magma_d_vinit( &hy, Magma_CPU, hA.num_rows, c_zero, queue ); // init DEV vectors magma_d_vinit( &dx, Magma_DEV, hA.num_rows, c_one, queue ); magma_d_vinit( &dy, Magma_DEV, hA.num_rows, c_zero, queue ); #ifdef MAGMA_WITH_MKL // calling MKL with CSR pntre = (magma_int_t*)malloc( (hA.num_rows+1)*sizeof(magma_int_t) ); pntre[0] = 0; for (j=0; j<hA.num_rows; j++ ) { pntre[j] = hA.row[j+1]; } MKL_INT num_rows = hA.num_rows; MKL_INT num_cols = hA.num_cols; MKL_INT nnz = hA.nnz; MKL_INT *col; TESTING_MALLOC_CPU( col, MKL_INT, nnz ); for( magma_int_t t=0; t < hA.nnz; ++t ) { col[ t ] = hA.col[ t ]; } MKL_INT *row; TESTING_MALLOC_CPU( row, MKL_INT, num_rows ); for( magma_int_t t=0; t < hA.num_rows; ++t ) { row[ t ] = hA.col[ t ]; } start = magma_wtime(); for (j=0; j<10; j++ ) { mkl_dcsrmv( "N", &num_rows, &num_cols, MKL_ADDR(&c_one), "GFNC", MKL_ADDR(hA.val), col, row, pntre, MKL_ADDR(hx.val), MKL_ADDR(&c_zero), MKL_ADDR(hy.val) ); } end = magma_wtime(); printf( "\n > MKL : %.2e seconds %.2e GFLOP/s (CSR).\n", (end-start)/10, FLOPS*10/(end-start) ); TESTING_FREE_CPU( row ); TESTING_FREE_CPU( col ); free(pntre); #endif // MAGMA_WITH_MKL // copy matrix to GPU magma_d_mtransfer( hA, &dA, Magma_CPU, Magma_DEV, queue ); // SpMV on GPU (CSR) -- this is the reference! start = magma_sync_wtime( queue ); for (j=0; j<10; j++) magma_d_spmv( c_one, dA, dx, c_zero, dy, queue ); end = magma_sync_wtime( queue ); printf( " > MAGMA: %.2e seconds %.2e GFLOP/s (standard CSR).\n", (end-start)/10, FLOPS*10/(end-start) ); magma_d_mfree(&dA, queue ); magma_d_vtransfer( dy, &hrefvec , Magma_DEV, Magma_CPU, queue ); // convert to ELL and copy to GPU magma_d_mconvert( hA, &hA_ELL, Magma_CSR, Magma_ELL, queue ); magma_d_mtransfer( hA_ELL, &dA_ELL, Magma_CPU, Magma_DEV, queue ); magma_d_mfree(&hA_ELL, queue ); magma_d_vfree( &dy, queue ); magma_d_vinit( &dy, Magma_DEV, hA.num_rows, c_zero, queue ); // SpMV on GPU (ELL) start = magma_sync_wtime( queue ); for (j=0; j<10; j++) magma_d_spmv( c_one, dA_ELL, dx, c_zero, dy, queue ); end = magma_sync_wtime( queue ); printf( " > MAGMA: %.2e seconds %.2e GFLOP/s (standard ELL).\n", (end-start)/10, FLOPS*10/(end-start) ); magma_d_mfree(&dA_ELL, queue ); magma_d_vtransfer( dy, &hcheck , Magma_DEV, Magma_CPU, queue ); res = 0.0; for(magma_int_t k=0; k<hA.num_rows; k++ ) res=res + MAGMA_D_REAL(hcheck.val[k]) - MAGMA_D_REAL(hrefvec.val[k]); if ( res < .000001 ) printf("# tester spmv ELL: ok\n"); else printf("# tester spmv ELL: failed\n"); magma_d_vfree( &hcheck, queue ); // convert to SELLP and copy to GPU magma_d_mconvert( hA, &hA_SELLP, Magma_CSR, Magma_SELLP, queue ); magma_d_mtransfer( hA_SELLP, &dA_SELLP, Magma_CPU, Magma_DEV, queue ); magma_d_mfree(&hA_SELLP, queue ); magma_d_vfree( &dy, queue ); magma_d_vinit( &dy, Magma_DEV, hA.num_rows, c_zero, queue ); // SpMV on GPU (SELLP) start = magma_sync_wtime( queue ); for (j=0; j<10; j++) magma_d_spmv( c_one, dA_SELLP, dx, c_zero, dy, queue ); end = magma_sync_wtime( queue ); printf( " > MAGMA: %.2e seconds %.2e GFLOP/s (SELLP).\n", (end-start)/10, FLOPS*10/(end-start) ); magma_d_vtransfer( dy, &hcheck , Magma_DEV, Magma_CPU, queue ); res = 0.0; for(magma_int_t k=0; k<hA.num_rows; k++ ) res=res + MAGMA_D_REAL(hcheck.val[k]) - MAGMA_D_REAL(hrefvec.val[k]); printf("# |x-y|_F = %8.2e\n", res); if ( res < .000001 ) printf("# tester spmv SELL-P: ok\n"); else printf("# tester spmv SELL-P: failed\n"); magma_d_vfree( &hcheck, queue ); magma_d_mfree(&dA_SELLP, queue ); // SpMV on GPU (CUSPARSE - CSR) // CUSPARSE context // cusparseHandle_t cusparseHandle = 0; cusparseStatus_t cusparseStatus; cusparseStatus = cusparseCreate(&cusparseHandle); cusparseSetStream( cusparseHandle, queue ); cusparseMatDescr_t descr = 0; cusparseStatus = cusparseCreateMatDescr(&descr); cusparseSetMatType(descr,CUSPARSE_MATRIX_TYPE_GENERAL); cusparseSetMatIndexBase(descr,CUSPARSE_INDEX_BASE_ZERO); double alpha = c_one; double beta = c_zero; magma_d_vfree( &dy, queue ); magma_d_vinit( &dy, Magma_DEV, hA.num_rows, c_zero, queue ); // copy matrix to GPU magma_d_mtransfer( hA, &dA, Magma_CPU, Magma_DEV, queue ); start = magma_sync_wtime( queue ); for (j=0; j<10; j++) cusparseStatus = cusparseDcsrmv(cusparseHandle,CUSPARSE_OPERATION_NON_TRANSPOSE, hA.num_rows, hA.num_cols, hA.nnz, &alpha, descr, dA.dval, dA.drow, dA.dcol, dx.dval, &beta, dy.dval); end = magma_sync_wtime( queue ); if (cusparseStatus != 0) printf("error in cuSPARSE CSR\n"); printf( " > CUSPARSE: %.2e seconds %.2e GFLOP/s (CSR).\n", (end-start)/10, FLOPS*10/(end-start) ); cusparseMatDescr_t descrA; cusparseStatus = cusparseCreateMatDescr(&descrA); if (cusparseStatus != 0) printf("error\n"); cusparseHybMat_t hybA; cusparseStatus = cusparseCreateHybMat( &hybA ); if (cusparseStatus != 0) printf("error\n"); magma_d_vtransfer( dy, &hcheck , Magma_DEV, Magma_CPU, queue ); res = 0.0; for(magma_int_t k=0; k<hA.num_rows; k++ ) res=res + MAGMA_D_REAL(hcheck.val[k]) - MAGMA_D_REAL(hrefvec.val[k]); printf("# |x-y|_F = %8.2e\n", res); if ( res < .000001 ) printf("# tester spmv cuSPARSE CSR: ok\n"); else printf("# tester spmv cuSPARSE CSR: failed\n"); magma_d_vfree( &hcheck, queue ); magma_d_vfree( &dy, queue ); magma_d_vinit( &dy, Magma_DEV, hA.num_rows, c_zero, queue ); cusparseDcsr2hyb(cusparseHandle, hA.num_rows, hA.num_cols, descrA, dA.dval, dA.drow, dA.dcol, hybA, 0, CUSPARSE_HYB_PARTITION_AUTO); start = magma_sync_wtime( queue ); for (j=0; j<10; j++) cusparseStatus = cusparseDhybmv( cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &alpha, descrA, hybA, dx.dval, &beta, dy.dval); end = magma_sync_wtime( queue ); if (cusparseStatus != 0) printf("error in cuSPARSE HYB\n"); printf( " > CUSPARSE: %.2e seconds %.2e GFLOP/s (HYB).\n", (end-start)/10, FLOPS*10/(end-start) ); magma_d_vtransfer( dy, &hcheck , Magma_DEV, Magma_CPU, queue ); res = 0.0; for(magma_int_t k=0; k<hA.num_rows; k++ ) res=res + MAGMA_D_REAL(hcheck.val[k]) - MAGMA_D_REAL(hrefvec.val[k]); printf("# |x-y|_F = %8.2e\n", res); if ( res < .000001 ) printf("# tester spmv cuSPARSE HYB: ok\n"); else printf("# tester spmv cuSPARSE HYB: failed\n"); magma_d_vfree( &hcheck, queue ); cusparseDestroyMatDescr( descrA ); cusparseDestroyHybMat( hybA ); cusparseDestroy( cusparseHandle ); magma_d_mfree(&dA, queue ); printf("\n\n"); // free CPU memory magma_d_mfree(&hA, queue ); magma_d_vfree(&hx, queue ); magma_d_vfree(&hy, queue ); magma_d_vfree(&hrefvec, queue ); // free GPU memory magma_d_vfree(&dx, queue ); magma_d_vfree(&dy, queue ); i++; } magma_queue_destroy( queue ); TESTING_FINALIZE(); return 0; }
/* //////////////////////////////////////////////////////////////////////////// -- testing any solver */ int main( int argc, char** argv ) { TESTING_INIT(); magma_dopts zopts; magma_queue_t queue; magma_queue_create( /*devices[ opts->device ],*/ &queue ); int i=1; magma_dparse_opts( argc, argv, &zopts, &i, queue ); real_Double_t res; magma_d_sparse_matrix A, A2, A3, A4, A5; while( i < argc ) { if ( strcmp("LAPLACE2D", argv[i]) == 0 && i+1 < argc ) { // Laplace test i++; magma_int_t laplace_size = atoi( argv[i] ); magma_dm_5stencil( laplace_size, &A, queue ); } else { // file-matrix test magma_d_csr_mtx( &A, argv[i], queue ); } printf( "# matrix info: %d-by-%d with %d nonzeros\n", (int) A.num_rows,(int) A.num_cols,(int) A.nnz ); // filename for temporary matrix storage const char *filename = "testmatrix.mtx"; // write to file write_d_csrtomtx( A, filename, queue ); // read from file magma_d_csr_mtx( &A2, filename, queue ); // delete temporary matrix unlink( filename ); //visualize printf("A2:\n"); magma_d_mvisu( A2, queue ); //visualize magma_d_mconvert(A2, &A4, Magma_CSR, Magma_CSRL, queue ); printf("A4:\n"); magma_d_mvisu( A4, queue ); magma_d_mconvert(A4, &A5, Magma_CSR, Magma_ELL, queue ); printf("A5:\n"); magma_d_mvisu( A5, queue ); // pass it to another application and back magma_int_t m, n; magma_index_t *row, *col; double *val; magma_dcsrget( A2, &m, &n, &row, &col, &val, queue ); magma_dcsrset( m, n, row, col, val, &A3, queue ); magma_dmdiff( A, A2, &res, queue ); printf("# ||A-B||_F = %8.2e\n", res); if ( res < .000001 ) printf("# tester IO: ok\n"); else printf("# tester IO: failed\n"); magma_dmdiff( A, A3, &res, queue ); printf("# ||A-B||_F = %8.2e\n", res); if ( res < .000001 ) printf("# tester matrix interface: ok\n"); else printf("# tester matrix interface: failed\n"); magma_d_mfree(&A, queue ); magma_d_mfree(&A2, queue ); magma_d_mfree(&A4, queue ); magma_d_mfree(&A5, queue ); i++; } magma_queue_destroy( queue ); TESTING_FINALIZE(); return 0; }
extern "C" magma_int_t magma_dcumilusetup( magma_d_sparse_matrix A, magma_d_preconditioner *precond, magma_queue_t queue ) { //magma_d_mvisu(A, queue ); // copy matrix into preconditioner parameter magma_d_sparse_matrix hA, hACSR; magma_d_mtransfer( A, &hA, A.memory_location, Magma_CPU, queue ); magma_d_mconvert( hA, &hACSR, hA.storage_type, Magma_CSR, queue ); magma_d_mtransfer(hACSR, &(precond->M), Magma_CPU, Magma_DEV, queue ); magma_d_mfree( &hA, queue ); magma_d_mfree( &hACSR, queue ); // CUSPARSE context // cusparseHandle_t cusparseHandle; cusparseStatus_t cusparseStatus; cusparseStatus = cusparseCreate(&cusparseHandle); cusparseSetStream( cusparseHandle, queue ); if (cusparseStatus != 0) printf("error in Handle.\n"); cusparseMatDescr_t descrA; cusparseStatus = cusparseCreateMatDescr(&descrA); if (cusparseStatus != 0) printf("error in MatrDescr.\n"); cusparseStatus = cusparseSetMatType(descrA,CUSPARSE_MATRIX_TYPE_GENERAL); if (cusparseStatus != 0) printf("error in MatrType.\n"); cusparseStatus = cusparseSetMatDiagType (descrA, CUSPARSE_DIAG_TYPE_NON_UNIT); if (cusparseStatus != 0) printf("error in DiagType.\n"); cusparseStatus = cusparseSetMatIndexBase(descrA,CUSPARSE_INDEX_BASE_ZERO); if (cusparseStatus != 0) printf("error in IndexBase.\n"); cusparseStatus = cusparseCreateSolveAnalysisInfo( &(precond->cuinfo) ); if (cusparseStatus != 0) printf("error in info.\n"); // end CUSPARSE context // cusparseStatus = cusparseDcsrsm_analysis( cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, precond->M.num_rows, precond->M.nnz, descrA, precond->M.dval, precond->M.drow, precond->M.dcol, precond->cuinfo); if (cusparseStatus != 0) printf("error in analysis:%d\n", cusparseStatus); cusparseStatus = cusparseDcsrilu0( cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, precond->M.num_rows, descrA, precond->M.dval, precond->M.drow, precond->M.dcol, precond->cuinfo); if (cusparseStatus != 0) printf("error in ILU:%d\n", cusparseStatus); cusparseStatus = cusparseDestroySolveAnalysisInfo( precond->cuinfo ); if (cusparseStatus != 0) printf("error in info-free.\n"); cusparseDestroyMatDescr( descrA ); magma_d_sparse_matrix hL, hU; magma_d_mtransfer( precond->M, &hA, Magma_DEV, Magma_CPU, queue ); hL.diagorder_type = Magma_UNITY; magma_d_mconvert( hA, &hL , Magma_CSR, Magma_CSRL, queue ); hU.diagorder_type = Magma_VALUE; magma_d_mconvert( hA, &hU , Magma_CSR, Magma_CSRU, queue ); magma_d_mtransfer( hL, &(precond->L), Magma_CPU, Magma_DEV, queue ); magma_d_mtransfer( hU, &(precond->U), Magma_CPU, Magma_DEV, queue ); cusparseMatDescr_t descrL; cusparseStatus = cusparseCreateMatDescr(&descrL); if (cusparseStatus != 0) printf("error in MatrDescr.\n"); cusparseStatus = cusparseSetMatType(descrL,CUSPARSE_MATRIX_TYPE_TRIANGULAR); if (cusparseStatus != 0) printf("error in MatrType.\n"); cusparseStatus = cusparseSetMatDiagType (descrL, CUSPARSE_DIAG_TYPE_UNIT); if (cusparseStatus != 0) printf("error in DiagType.\n"); cusparseStatus = cusparseSetMatIndexBase(descrL,CUSPARSE_INDEX_BASE_ZERO); if (cusparseStatus != 0) printf("error in IndexBase.\n"); cusparseStatus = cusparseSetMatFillMode(descrL,CUSPARSE_FILL_MODE_LOWER); if (cusparseStatus != 0) printf("error in fillmode.\n"); cusparseStatus = cusparseCreateSolveAnalysisInfo(&precond->cuinfoL); if (cusparseStatus != 0) printf("error in info.\n"); cusparseStatus = cusparseDcsrsm_analysis(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, precond->L.num_rows, precond->L.nnz, descrL, precond->L.dval, precond->L.drow, precond->L.dcol, precond->cuinfoL ); if (cusparseStatus != 0) printf("error in analysis.\n"); cusparseDestroyMatDescr( descrL ); cusparseMatDescr_t descrU; cusparseStatus = cusparseCreateMatDescr(&descrU); if (cusparseStatus != 0) printf("error in MatrDescr.\n"); cusparseStatus = cusparseSetMatType(descrU,CUSPARSE_MATRIX_TYPE_TRIANGULAR); if (cusparseStatus != 0) printf("error in MatrType.\n"); cusparseStatus = cusparseSetMatDiagType (descrU, CUSPARSE_DIAG_TYPE_NON_UNIT); if (cusparseStatus != 0) printf("error in DiagType.\n"); cusparseStatus = cusparseSetMatIndexBase(descrU,CUSPARSE_INDEX_BASE_ZERO); if (cusparseStatus != 0) printf("error in IndexBase.\n"); cusparseStatus = cusparseSetMatFillMode(descrU,CUSPARSE_FILL_MODE_UPPER); if (cusparseStatus != 0) printf("error in fillmode.\n"); cusparseStatus = cusparseCreateSolveAnalysisInfo(&precond->cuinfoU); if (cusparseStatus != 0) printf("error in info.\n"); cusparseStatus = cusparseDcsrsm_analysis(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, precond->U.num_rows, precond->U.nnz, descrU, precond->U.dval, precond->U.drow, precond->U.dcol, precond->cuinfoU ); if (cusparseStatus != 0) printf("error in analysis.\n"); cusparseDestroyMatDescr( descrU ); magma_d_mfree(&hA, queue ); magma_d_mfree(&hL, queue ); magma_d_mfree(&hU, queue ); cusparseDestroy( cusparseHandle ); return MAGMA_SUCCESS; }
extern "C" magma_int_t magma_dpastixsetup( magma_d_sparse_matrix A, magma_d_vector b, magma_d_preconditioner *precond, magma_queue_t queue ) { #if defined(HAVE_PASTIX) #if defined(PRECISION_d) pastix_data_t *pastix_data = NULL; /* Pointer to a storage structure needed by pastix */ pastix_int_t ncol; /* Size of the matrix */ pastix_int_t *colptr = NULL; /* Indexes of first element of each column in row and values */ pastix_int_t *rows = NULL; /* Row of each element of the matrix */ pastix_float_t *values = NULL; /* Value of each element of the matrix */ pastix_float_t *rhs = NULL; /* right hand side */ pastix_int_t *iparm = NULL; /* integer parameters for pastix */ double *dparm = NULL; /* floating parameters for pastix */ pastix_int_t *perm = NULL; /* Permutation tabular */ pastix_int_t *invp = NULL; /* Reverse permutation tabular */ pastix_int_t mat_type; magma_d_sparse_matrix A_h1, B; magma_d_vector diag, c_t, b_h; magma_d_vinit( &c_t, Magma_CPU, A.num_rows, MAGMA_D_ZERO, queue ); magma_d_vinit( &diag, Magma_CPU, A.num_rows, MAGMA_D_ZERO, queue ); magma_d_vtransfer( b, &b_h, A.memory_location, Magma_CPU, queue ); if ( A.storage_type != Magma_CSR ) { magma_d_mtransfer( A, &A_h1, A.memory_location, Magma_CPU, queue ); magma_d_mconvert( A_h1, &B, A_h1.storage_type, Magma_CSR, queue ); } else { magma_d_mtransfer( A, &B, A.memory_location, Magma_CPU, queue ); } rhs = (pastix_float_t*) b_h.dval; ncol = B.num_rows; colptr = B.drow; rows = B.dcol; values = (pastix_float_t*) B.dval; mat_type = API_SYM_NO; iparm = (pastix_int_t*)malloc(IPARM_SIZE*sizeof(pastix_int_t)); dparm = (pastix_float_t*)malloc(DPARM_SIZE*sizeof(pastix_float_t)); /*******************************************/ /* Initialize parameters to default values */ /*******************************************/ iparm[IPARM_MODIFY_PARAMETER] = API_NO; pastix(&pastix_data, MPI_COMM_WORLD, ncol, colptr, rows, values, perm, invp, rhs, 1, iparm, dparm); iparm[IPARM_THREAD_NBR] = 16; iparm[IPARM_SYM] = mat_type; iparm[IPARM_FACTORIZATION] = API_FACT_LU; iparm[IPARM_VERBOSE] = API_VERBOSE_YES; iparm[IPARM_ORDERING] = API_ORDER_SCOTCH; iparm[IPARM_INCOMPLETE] = API_NO; iparm[IPARM_RHS_MAKING] = API_RHS_B; //iparm[IPARM_AMALGAMATION] = 5; iparm[IPARM_LEVEL_OF_FILL] = 0; /* if (incomplete == 1) { dparm[DPARM_EPSILON_REFINEMENT] = 1e-7; } */ /* * Matrix needs : * - to be in fortran numbering * - to have only the lower triangular part in symmetric case * - to have a graph with a symmetric structure in unsymmetric case * If those criteria are not matched, the csc will be reallocated and changed. */ iparm[IPARM_MATRIX_VERIFICATION] = API_YES; perm = (pastix_int_t*)malloc(ncol*sizeof(pastix_int_t)); invp = (pastix_int_t*)malloc(ncol*sizeof(pastix_int_t)); /*******************************************/ /* Step 1 - Ordering / Scotch */ /* Perform it only when the pattern of */ /* matrix change. */ /* eg: mesh refinement */ /* In many cases users can simply go from */ /* API_TASK_ORDERING to API_TASK_ANALYSE */ /* in one call. */ /*******************************************/ /*******************************************/ /* Step 2 - Symbolic factorization */ /* Perform it only when the pattern of */ /* matrix change. */ /*******************************************/ /*******************************************/ /* Step 3 - Mapping and Compute scheduling */ /* Perform it only when the pattern of */ /* matrix change. */ /*******************************************/ /*******************************************/ /* Step 4 - Numerical Factorisation */ /* Perform it each time the values of the */ /* matrix changed. */ /*******************************************/ iparm[IPARM_START_TASK] = API_TASK_ORDERING; iparm[IPARM_END_TASK] = API_TASK_NUMFACT; pastix(&pastix_data, MPI_COMM_WORLD, ncol, colptr, rows, values, perm, invp, NULL, 1, iparm, dparm); precond->int_array_1 = (magma_int_t*) perm; precond->int_array_2 = (magma_int_t*) invp; precond->M.dval = (double*) values; precond->M.dcol = (magma_int_t*) colptr; precond->M.drow = (magma_int_t*) rows; precond->M.num_rows = A.num_rows; precond->M.num_cols = A.num_cols; precond->M.memory_location = Magma_CPU; precond->pastix_data = pastix_data; precond->iparm = iparm; precond->dparm = dparm; if ( A.storage_type != Magma_CSR) { magma_d_mfree( &A_h1, queue ); } magma_d_vfree( &b_h, queue ); magma_d_mfree( &B, queue ); #else printf( "error: only double precision supported yet.\n"); #endif #else printf( "error: pastix not available.\n"); #endif return MAGMA_SUCCESS; }
extern "C" magma_int_t magma_dcumiccsetup( magma_d_sparse_matrix A, magma_d_preconditioner *precond, magma_queue_t queue ) { magma_d_sparse_matrix hA, hACSR, U, hD, hR, hAt; magma_d_mtransfer( A, &hA, A.memory_location, Magma_CPU, queue ); U.diagorder_type = Magma_VALUE; magma_d_mconvert( hA, &hACSR, hA.storage_type, Magma_CSR, queue ); magma_d_mconvert( hACSR, &U, Magma_CSR, Magma_CSRL, queue ); magma_d_mfree( &hACSR, queue ); magma_d_mtransfer(U, &(precond->M), Magma_CPU, Magma_DEV, queue ); // CUSPARSE context // cusparseHandle_t cusparseHandle; cusparseStatus_t cusparseStatus; cusparseStatus = cusparseCreate(&cusparseHandle); cusparseSetStream( cusparseHandle, queue ); if (cusparseStatus != 0) printf("error in Handle.\n"); cusparseMatDescr_t descrA; cusparseStatus = cusparseCreateMatDescr(&descrA); if (cusparseStatus != 0) printf("error in MatrDescr.\n"); cusparseStatus = cusparseSetMatType(descrA,CUSPARSE_MATRIX_TYPE_SYMMETRIC); if (cusparseStatus != 0) printf("error in MatrType.\n"); cusparseStatus = cusparseSetMatDiagType (descrA, CUSPARSE_DIAG_TYPE_NON_UNIT); if (cusparseStatus != 0) printf("error in DiagType.\n"); cusparseStatus = cusparseSetMatIndexBase(descrA,CUSPARSE_INDEX_BASE_ZERO); if (cusparseStatus != 0) printf("error in IndexBase.\n"); cusparseStatus = cusparseSetMatFillMode(descrA,CUSPARSE_FILL_MODE_LOWER); if (cusparseStatus != 0) printf("error in fillmode.\n"); cusparseStatus = cusparseCreateSolveAnalysisInfo( &(precond->cuinfo) ); if (cusparseStatus != 0) printf("error in info.\n"); // end CUSPARSE context // cusparseStatus = cusparseDcsrsm_analysis( cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, precond->M.num_rows, precond->M.nnz, descrA, precond->M.dval, precond->M.drow, precond->M.dcol, precond->cuinfo); if (cusparseStatus != 0) printf("error in analysis IC.\n"); cusparseStatus = cusparseDcsric0( cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, precond->M.num_rows, descrA, precond->M.dval, precond->M.drow, precond->M.dcol, precond->cuinfo); cusparseStatus = cusparseDestroySolveAnalysisInfo( precond->cuinfo ); if (cusparseStatus != 0) printf("error in info-free.\n"); if (cusparseStatus != 0) printf("error in ICC.\n"); cusparseMatDescr_t descrL; cusparseStatus = cusparseCreateMatDescr(&descrL); if (cusparseStatus != 0) printf("error in MatrDescr.\n"); cusparseStatus = cusparseSetMatType(descrL,CUSPARSE_MATRIX_TYPE_TRIANGULAR); if (cusparseStatus != 0) printf("error in MatrType.\n"); cusparseStatus = cusparseSetMatDiagType (descrL, CUSPARSE_DIAG_TYPE_NON_UNIT); if (cusparseStatus != 0) printf("error in DiagType.\n"); cusparseStatus = cusparseSetMatIndexBase(descrL,CUSPARSE_INDEX_BASE_ZERO); if (cusparseStatus != 0) printf("error in IndexBase.\n"); cusparseStatus = cusparseSetMatFillMode(descrL,CUSPARSE_FILL_MODE_LOWER); if (cusparseStatus != 0) printf("error in fillmode.\n"); cusparseStatus = cusparseCreateSolveAnalysisInfo(&precond->cuinfoL); if (cusparseStatus != 0) printf("error in info.\n"); cusparseStatus = cusparseDcsrsm_analysis(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, precond->M.num_rows, precond->M.nnz, descrL, precond->M.dval, precond->M.drow, precond->M.dcol, precond->cuinfoL ); if (cusparseStatus != 0) printf("error in analysis L.\n"); cusparseDestroyMatDescr( descrL ); cusparseMatDescr_t descrU; cusparseStatus = cusparseCreateMatDescr(&descrU); if (cusparseStatus != 0) printf("error in MatrDescr.\n"); cusparseStatus = cusparseSetMatType(descrU,CUSPARSE_MATRIX_TYPE_TRIANGULAR); if (cusparseStatus != 0) printf("error in MatrType.\n"); cusparseStatus = cusparseSetMatDiagType (descrU, CUSPARSE_DIAG_TYPE_NON_UNIT); if (cusparseStatus != 0) printf("error in DiagType.\n"); cusparseStatus = cusparseSetMatIndexBase(descrU,CUSPARSE_INDEX_BASE_ZERO); if (cusparseStatus != 0) printf("error in IndexBase.\n"); cusparseStatus = cusparseSetMatFillMode(descrU,CUSPARSE_FILL_MODE_LOWER); if (cusparseStatus != 0) printf("error in fillmode.\n"); cusparseStatus = cusparseCreateSolveAnalysisInfo(&precond->cuinfoU); if (cusparseStatus != 0) printf("error in info.\n"); cusparseStatus = cusparseDcsrsm_analysis(cusparseHandle, CUSPARSE_OPERATION_TRANSPOSE, precond->M.num_rows, precond->M.nnz, descrU, precond->M.dval, precond->M.drow, precond->M.dcol, precond->cuinfoU ); if (cusparseStatus != 0) printf("error in analysis U.\n"); cusparseDestroyMatDescr( descrU ); cusparseDestroyMatDescr( descrA ); cusparseDestroy( cusparseHandle ); magma_d_mfree(&U, queue ); magma_d_mfree(&hA, queue ); /* // to enable also the block-asynchronous iteration for the triangular solves magma_d_mtransfer( precond->M, &hA, Magma_DEV, Magma_CPU, queue ); hA.storage_type = Magma_CSR; magma_dcsrsplit( 256, hA, &hD, &hR, queue ); magma_d_mtransfer( hD, &precond->LD, Magma_CPU, Magma_DEV, queue ); magma_d_mtransfer( hR, &precond->L, Magma_CPU, Magma_DEV, queue ); magma_d_mfree(&hD, queue ); magma_d_mfree(&hR, queue ); magma_d_cucsrtranspose( hA, &hAt, queue ); magma_dcsrsplit( 256, hAt, &hD, &hR, queue ); magma_d_mtransfer( hD, &precond->UD, Magma_CPU, Magma_DEV, queue ); magma_d_mtransfer( hR, &precond->U, Magma_CPU, Magma_DEV, queue ); magma_d_mfree(&hD, queue ); magma_d_mfree(&hR, queue ); magma_d_mfree(&hA, queue ); magma_d_mfree(&hAt, queue ); */ return MAGMA_SUCCESS; }
/* //////////////////////////////////////////////////////////////////////////// -- testing any solver */ int main( int argc, char** argv ) { TESTING_INIT(); magma_dopts zopts; magma_queue_t queue; magma_queue_create( /*devices[ opts->device ],*/ &queue ); int i=1; magma_dparse_opts( argc, argv, &zopts, &i, queue ); real_Double_t res; magma_d_sparse_matrix Z, Z2, A, A2, AT, AT2, B; B.blocksize = zopts.blocksize; B.alignment = zopts.alignment; while( i < argc ) { if ( strcmp("LAPLACE2D", argv[i]) == 0 && i+1 < argc ) { // Laplace test i++; magma_int_t laplace_size = atoi( argv[i] ); magma_dm_5stencil( laplace_size, &Z, queue ); } else { // file-matrix test magma_d_csr_mtx( &Z, argv[i], queue ); } printf( "# matrix info: %d-by-%d with %d nonzeros\n", (int) Z.num_rows,(int) Z.num_cols,(int) Z.nnz ); // convert to be non-symmetric magma_d_mconvert( Z, &A, Magma_CSR, Magma_CSRL, queue ); magma_d_mconvert( Z, &B, Magma_CSR, Magma_CSRU, queue ); // transpose magma_d_mtranspose( A, &AT, queue ); // quite some conversions //ELL magma_d_mconvert( AT, &AT2, Magma_CSR, Magma_ELL, queue ); magma_d_mfree(&AT, queue ); magma_d_mconvert( AT2, &AT, Magma_ELL, Magma_CSR, queue ); magma_d_mfree(&AT2, queue ); //ELLPACKT magma_d_mconvert( AT, &AT2, Magma_CSR, Magma_ELLPACKT, queue ); magma_d_mfree(&AT, queue ); magma_d_mconvert( AT2, &AT, Magma_ELLPACKT, Magma_CSR, queue ); magma_d_mfree(&AT2, queue ); //ELLRT AT2.blocksize = 8; AT2.alignment = 8; magma_d_mconvert( AT, &AT2, Magma_CSR, Magma_ELLRT, queue ); magma_d_mfree(&AT, queue ); magma_d_mconvert( AT2, &AT, Magma_ELLRT, Magma_CSR, queue ); magma_d_mfree(&AT2, queue ); //SELLP AT2.blocksize = 8; AT2.alignment = 8; magma_d_mconvert( AT, &AT2, Magma_CSR, Magma_SELLP, queue ); magma_d_mfree(&AT, queue ); magma_d_mconvert( AT2, &AT, Magma_SELLP, Magma_CSR, queue ); magma_d_mfree(&AT2, queue ); //ELLD magma_d_mconvert( AT, &AT2, Magma_CSR, Magma_ELLD, queue ); magma_d_mfree(&AT, queue ); magma_d_mconvert( AT2, &AT, Magma_ELLD, Magma_CSR, queue ); magma_d_mfree(&AT2, queue ); //CSRCOO magma_d_mconvert( AT, &AT2, Magma_CSR, Magma_CSRCOO, queue ); magma_d_mfree(&AT, queue ); magma_d_mconvert( AT2, &AT, Magma_CSRCOO, Magma_CSR, queue ); magma_d_mfree(&AT2, queue ); //CSRD magma_d_mconvert( AT, &AT2, Magma_CSR, Magma_CSRD, queue ); magma_d_mfree(&AT, queue ); magma_d_mconvert( AT2, &AT, Magma_CSRD, Magma_CSR, queue ); magma_d_mfree(&AT2, queue ); //BCSR magma_d_mconvert( AT, &AT2, Magma_CSR, Magma_BCSR, queue ); magma_d_mfree(&AT, queue ); magma_d_mconvert( AT2, &AT, Magma_BCSR, Magma_CSR, queue ); magma_d_mfree(&AT2, queue ); // transpose magma_d_mtranspose( AT, &A2, queue ); magma_dmdiff( A, A2, &res, queue); printf("# ||A-A2||_F = %8.2e\n", res); if ( res < .000001 ) printf("# conversion tester: ok\n"); else printf("# conversion tester: failed\n"); magma_dmlumerge( A2, B, &Z2, queue ); magma_dmdiff( Z, Z2, &res, queue); printf("# ||Z-Z2||_F = %8.2e\n", res); if ( res < .000001 ) printf("# LUmerge tester: ok\n"); else printf("# LUmerge tester: failed\n"); magma_d_mfree(&A, queue ); magma_d_mfree(&A2, queue ); magma_d_mfree(&AT, queue ); magma_d_mfree(&AT2, queue ); magma_d_mfree(&B, queue ); magma_d_mfree(&Z2, queue ); magma_d_mfree(&Z, queue ); i++; } magma_queue_destroy( queue ); TESTING_FINALIZE(); return 0; }
/* //////////////////////////////////////////////////////////////////////////// -- running magma_dlobpcg */ int main( int argc, char** argv) { TESTING_INIT(); magma_d_solver_par solver_par; solver_par.epsilon = 1e-5; solver_par.maxiter = 1000; solver_par.verbose = 0; solver_par.num_eigenvalues = 32; solver_par.solver = Magma_LOBPCG; magma_d_preconditioner precond_par; precond_par.solver = Magma_JACOBI; int precond = 0; int format = 0; int scale = 0; magma_scale_t scaling = Magma_NOSCALE; magma_d_sparse_matrix A, B, dA; B.blocksize = 8; B.alignment = 8; B.storage_type = Magma_CSR; int i; for( i = 1; i < argc; ++i ) { if ( strcmp("--format", argv[i]) == 0 ) { format = atoi( argv[++i] ); switch( format ) { case 0: B.storage_type = Magma_CSR; break; case 1: B.storage_type = Magma_ELL; break; case 2: B.storage_type = Magma_ELLRT; break; case 3: B.storage_type = Magma_SELLP; break; } }else if ( strcmp("--mscale", argv[i]) == 0 ) { scale = atoi( argv[++i] ); switch( scale ) { case 0: scaling = Magma_NOSCALE; break; case 1: scaling = Magma_UNITDIAG; break; case 2: scaling = Magma_UNITROW; break; } }else if ( strcmp("--precond", argv[i]) == 0 ) { format = atoi( argv[++i] ); switch( precond ) { case 0: precond_par.solver = Magma_JACOBI; break; } }else if ( strcmp("--blocksize", argv[i]) == 0 ) { B.blocksize = atoi( argv[++i] ); }else if ( strcmp("--alignment", argv[i]) == 0 ) { B.alignment = atoi( argv[++i] ); }else if ( strcmp("--verbose", argv[i]) == 0 ) { solver_par.verbose = atoi( argv[++i] ); } else if ( strcmp("--maxiter", argv[i]) == 0 ) { solver_par.maxiter = atoi( argv[++i] ); } else if ( strcmp("--tol", argv[i]) == 0 ) { sscanf( argv[++i], "%lf", &solver_par.epsilon ); } else if ( strcmp("--eigenvalues", argv[i]) == 0 ) { solver_par.num_eigenvalues = atoi( argv[++i] ); } else break; } printf( "\n# usage: ./run_dlobpcg" " [ --format %d (0=CSR, 1=ELL, 2=ELLRT, 4=SELLP)" " [ --blocksize %d --alignment %d ]" " --mscale %d (0=no, 1=unitdiag, 2=unitrownrm)" " --verbose %d (0=summary, k=details every k iterations)" " --maxiter %d --tol %.2e" " --preconditioner %d (0=Jacobi) " " --eigenvalues %d ]" " matrices \n\n", format, (int) B.blocksize, (int) B.alignment, (int) scale, (int) solver_par.verbose, (int) solver_par.maxiter, solver_par.epsilon, precond, (int) solver_par.num_eigenvalues); while( i < argc ){ magma_d_csr_mtx( &A, argv[i] ); printf( "\n# matrix info: %d-by-%d with %d nonzeros\n\n", (int) A.num_rows,(int) A.num_cols,(int) A.nnz ); // scale initial guess magma_dmscale( &A, scaling ); solver_par.ev_length = A.num_cols; magma_d_sparse_matrix A2; A2.storage_type = Magma_SELLC; A2.blocksize = 8; A2.alignment = 4; magma_d_mconvert( A, &A2, Magma_CSR, A2.storage_type ); // copy matrix to GPU magma_d_mtransfer( A2, &dA, Magma_CPU, Magma_DEV); magma_dsolverinfo_init( &solver_par, &precond_par ); // inside the loop! // as the matrix size has influence on the EV-length real_Double_t gpu_time; // Find the blockSize smallest eigenvalues and corresponding eigen-vectors gpu_time = magma_wtime(); magma_dlobpcg( dA, &solver_par ); gpu_time = magma_wtime() - gpu_time; printf("Time (sec) = %7.2f\n", gpu_time); printf("solver runtime (sec) = %7.2f\n", solver_par.runtime ); magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_mfree( &dA ); magma_d_mfree( &A2 ); magma_d_mfree( &A ); i++; } TESTING_FINALIZE(); return 0; }
extern "C" magma_int_t magma_d_cucsrtranspose( magma_d_sparse_matrix A, magma_d_sparse_matrix *B, magma_queue_t queue ) { // for symmetric matrices: convert to csc using cusparse if( A.storage_type == Magma_CSR && A.memory_location == Magma_DEV ) { magma_d_sparse_matrix C; magma_d_mtransfer( A, &C, Magma_DEV, Magma_DEV, queue ); // CUSPARSE context // cusparseHandle_t handle; cusparseStatus_t cusparseStatus; cusparseStatus = cusparseCreate(&handle); cusparseSetStream( handle, queue ); if (cusparseStatus != 0) printf("error in Handle.\n"); cusparseMatDescr_t descrA; cusparseMatDescr_t descrB; cusparseStatus = cusparseCreateMatDescr(&descrA); cusparseStatus = cusparseCreateMatDescr(&descrB); if (cusparseStatus != 0) printf("error in MatrDescr.\n"); cusparseStatus = cusparseSetMatType(descrA,CUSPARSE_MATRIX_TYPE_GENERAL); cusparseSetMatType(descrB,CUSPARSE_MATRIX_TYPE_GENERAL); if (cusparseStatus != 0) printf("error in MatrType.\n"); cusparseStatus = cusparseSetMatIndexBase(descrA,CUSPARSE_INDEX_BASE_ZERO); cusparseSetMatIndexBase(descrB,CUSPARSE_INDEX_BASE_ZERO); if (cusparseStatus != 0) printf("error in IndexBase.\n"); cusparseStatus = cusparseDcsr2csc( handle, A.num_rows, A.num_rows, A.nnz, A.dval, A.drow, A.dcol, C.dval, C.dcol, C.drow, CUSPARSE_ACTION_NUMERIC, CUSPARSE_INDEX_BASE_ZERO); if (cusparseStatus != 0) printf("error in transpose: %d.\n", cusparseStatus); cusparseDestroyMatDescr( descrA ); cusparseDestroyMatDescr( descrB ); cusparseDestroy( handle ); magma_d_mtransfer( C, B, Magma_DEV, Magma_DEV, queue ); if( A.fill_mode == Magma_FULL ){ B->fill_mode = Magma_FULL; } else if( A.fill_mode == Magma_LOWER ){ B->fill_mode = Magma_UPPER; } else if ( A.fill_mode == Magma_UPPER ){ B->fill_mode = Magma_LOWER; } // end CUSPARSE context // return MAGMA_SUCCESS; }else if( A.storage_type == Magma_CSR && A.memory_location == Magma_CPU ){ magma_d_sparse_matrix A_d, B_d; magma_d_mtransfer( A, &A_d, A.memory_location, Magma_DEV, queue ); magma_d_cucsrtranspose( A_d, &B_d, queue ); magma_d_mtransfer( B_d, B, Magma_DEV, A.memory_location, queue ); magma_d_mfree( &A_d, queue ); magma_d_mfree( &B_d, queue ); return MAGMA_SUCCESS; }else { magma_d_sparse_matrix ACSR, BCSR; magma_d_mconvert( A, &ACSR, A.storage_type, Magma_CSR, queue ); magma_d_cucsrtranspose( ACSR, &BCSR, queue ); magma_d_mconvert( BCSR, B, Magma_CSR, A.storage_type, queue ); magma_d_mfree( &ACSR, queue ); magma_d_mfree( &BCSR, queue ); return MAGMA_SUCCESS; } }
/* //////////////////////////////////////////////////////////////////////////// -- Debugging file */ int main( int argc, char** argv) { TESTING_INIT(); magma_d_solver_par solver_par; magma_d_preconditioner precond_par; solver_par.epsilon = 10e-16; solver_par.maxiter = 1000; solver_par.verbose = 0; solver_par.restart = 30; solver_par.num_eigenvalues = 0; solver_par.ortho = Magma_CGS; double one = MAGMA_D_MAKE(1.0, 0.0); double zero = MAGMA_D_MAKE(0.0, 0.0); magma_d_sparse_matrix A, B, B_d; magma_d_vector x, b; // generate matrix of desired structure and size magma_int_t n=100; // size is n*n magma_int_t nn = n*n; magma_int_t offdiags = 2; magma_index_t *diag_offset; double *diag_vals; magma_dmalloc_cpu( &diag_vals, offdiags+1 ); magma_index_malloc_cpu( &diag_offset, offdiags+1 ); diag_offset[0] = 0; diag_offset[1] = 1; diag_offset[2] = n; diag_vals[0] = MAGMA_D_MAKE( 4.1, 0.0 ); diag_vals[1] = MAGMA_D_MAKE( -1.0, 0.0 ); diag_vals[2] = MAGMA_D_MAKE( -1.0, 0.0 ); magma_dmgenerator( nn, offdiags, diag_offset, diag_vals, &A ); // convert marix into desired format B.storage_type = Magma_SELLC; B.blocksize = 8; B.alignment = 8; // scale matrix magma_dmscale( &A, Magma_UNITDIAG ); magma_d_mconvert( A, &B, Magma_CSR, B.storage_type ); magma_d_mtransfer( B, &B_d, Magma_CPU, Magma_DEV ); // test CG #################################### // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // solver magma_dcg_res( B_d, b, &x, &solver_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); // test PCG Jacobi ############################ // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_JACOBI; magma_d_precondsetup( B_d, b, &precond_par ); // solver magma_dpcg( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); // test PCG IC ################################ // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ICC; magma_d_precondsetup( B_d, b, &precond_par ); // solver magma_dpcg( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); // test PCG IC ################################ // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ICC; magma_d_precondsetup( B_d, b, &precond_par ); // solver magma_dpcg( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); // test BICGSTAB #################################### // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // solver magma_dbicgstab( B_d, b, &x, &solver_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); // test PBICGSTAB Jacobi ############################ // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_JACOBI; magma_d_precondsetup( B_d, b, &precond_par ); // solver magma_dpbicgstab( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); /* // test PBICGSTAB ILU ############################### // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ILU; magma_d_precondsetup( B_d, b, &precond_par ); // solver magma_dpbicgstab( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); // test PBICGSTAB ILU ############################### // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x);printf("here\n"); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ILU; magma_d_precondsetup( B_d, b, &precond_par ); // solver magma_dpbicgstab( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); // test GMRES #################################### // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // solver magma_dgmres( B_d, b, &x, &solver_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); // test PGMRES Jacobi ############################ // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_JACOBI; magma_d_precondsetup( B_d, b, &precond_par ); // solver magma_dpgmres( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b);*/ // test PGMRES ILU ############################### // vectors and initial guess magma_d_vinit( &b, Magma_DEV, A.num_cols, one ); magma_d_vinit( &x, Magma_DEV, A.num_cols, one ); magma_d_spmv( one, B_d, x, zero, b ); // b = A x magma_d_vfree(&x); magma_d_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_dsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ILU; magma_d_precondsetup( B_d, b, &precond_par ); // solver magma_dpgmres( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_dsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_dsolverinfo_free( &solver_par, &precond_par ); magma_d_vfree(&x); magma_d_vfree(&b); printf("all tests passed.\n"); magma_d_mfree(&B_d); magma_d_mfree(&B); magma_d_mfree(&A); TESTING_FINALIZE(); return 0; }