extern "C" magma_int_t magma_d_solver( magma_d_sparse_matrix A, magma_d_vector b, magma_d_vector *x, magma_dopts *zopts, magma_queue_t queue ) { // preconditioner if ( zopts->solver_par.solver != Magma_ITERREF ) { magma_d_precondsetup( A, b, &zopts->precond_par, queue ); } switch( zopts->solver_par.solver ) { case Magma_CG: magma_dcg_res( A, b, x, &zopts->solver_par, queue );break; case Magma_CGMERGE: magma_dcg_merge( A, b, x, &zopts->solver_par, queue );break; case Magma_PCG: magma_dpcg( A, b, x, &zopts->solver_par, &zopts->precond_par, queue );break; case Magma_BICGSTAB: magma_dbicgstab( A, b, x, &zopts->solver_par, queue );break; case Magma_BICGSTABMERGE: magma_dbicgstab_merge( A, b, x, &zopts->solver_par, queue );break; case Magma_PBICGSTAB: magma_dpbicgstab( A, b, x, &zopts->solver_par, &zopts->precond_par, queue );break; case Magma_GMRES: magma_dfgmres( A, b, x, &zopts->solver_par, &zopts->precond_par, queue );break; case Magma_PGMRES: magma_dfgmres( A, b, x, &zopts->solver_par, &zopts->precond_par, queue );break; case Magma_LOBPCG: magma_dlobpcg( A, &zopts->solver_par, queue );break; case Magma_ITERREF: magma_diterref( A, b, x, &zopts->solver_par, &zopts->precond_par, queue );break; case Magma_JACOBI: magma_djacobi( A, b, x, &zopts->solver_par, queue );break; case Magma_BAITER: magma_dbaiter( A, b, x, &zopts->solver_par, queue );break; } 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; }