extern "C" magma_int_t magma_z_precond( magma_z_sparse_matrix A, magma_z_vector b, magma_z_vector *x, magma_z_preconditioner *precond, magma_queue_t queue ) { // set up precond parameters as solver parameters magma_z_solver_par psolver_par; psolver_par.epsilon = precond->epsilon; psolver_par.maxiter = precond->maxiter; psolver_par.restart = precond->restart; psolver_par.verbose = 0; switch( precond->solver ) { case Magma_CG: magma_zcg_res( A, b, x, &psolver_par, queue );break; case Magma_BICGSTAB: magma_zbicgstab( A, b, x, &psolver_par, queue );break; case Magma_GMRES: magma_zgmres( A, b, x, &psolver_par, queue );break; case Magma_JACOBI: magma_zjacobi( A, b, x, &psolver_par, queue );break; case Magma_BAITER: magma_zbaiter( A, b, x, &psolver_par, queue );break; } return MAGMA_SUCCESS; }
extern "C" magma_int_t magma_z_solver( magma_z_matrix A, magma_z_matrix b, magma_z_matrix *x, magma_zopts *zopts, magma_queue_t queue ) { magma_int_t info = 0; // make sure RHS is a dense matrix if ( b.storage_type != Magma_DENSE ) { printf( "error: sparse RHS not yet supported.\n" ); return MAGMA_ERR_NOT_SUPPORTED; } if( b.num_cols == 1 ){ switch( zopts->solver_par.solver ) { case Magma_CG: CHECK( magma_zcg_res( A, b, x, &zopts->solver_par, queue )); break; case Magma_BICG: CHECK( magma_zbicg( A, b, x, &zopts->solver_par, queue )); break; case Magma_PBICG: CHECK( magma_zpbicg( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_CGMERGE: CHECK( magma_zcg_merge( A, b, x, &zopts->solver_par, queue )); break; case Magma_PCG: CHECK( magma_zpcg( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_PCGMERGE: CHECK( magma_zpcg_merge( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_BICGSTAB: CHECK( magma_zbicgstab( A, b, x, &zopts->solver_par, queue )); break; case Magma_BICGSTABMERGE: CHECK( magma_zbicgstab_merge( A, b, x, &zopts->solver_par, queue )); break; case Magma_PBICGSTABMERGE: CHECK( magma_zpbicgstab_merge( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_PBICGSTAB: CHECK( magma_zpbicgstab( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_GMRES: CHECK( magma_zfgmres( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_PGMRES: CHECK( magma_zfgmres( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_IDR: CHECK( magma_zidr( A, b, x, &zopts->solver_par, queue )); break; case Magma_IDRMERGE: CHECK( magma_zidr_merge( A, b, x, &zopts->solver_par, queue )); break; //CHECK( magma_zidr_strms( A, b, x, &zopts->solver_par, queue )); break; case Magma_PIDR: CHECK( magma_zpidr( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_PIDRMERGE: CHECK( magma_zpidr_merge( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; //CHECK( magma_zpidr_strms( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_LOBPCG: CHECK( magma_zlobpcg( A, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_ITERREF: CHECK( magma_ziterref( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_JACOBI: CHECK( magma_zftjacobi( A, b, x, &zopts->solver_par, queue )); break; case Magma_BAITER: CHECK( magma_zbaiter( A, b, x, &zopts->solver_par, &zopts->precond_par, queue ) ); break; case Magma_BAITERO: CHECK( magma_zbaiter_overlap( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_CGS: CHECK( magma_zcgs( A, b, x, &zopts->solver_par, queue ) ); break; case Magma_CGSMERGE: CHECK( magma_zcgs_merge( A, b, x, &zopts->solver_par, queue ) ); break; case Magma_PCGS: CHECK( magma_zpcgs( A, b, x, &zopts->solver_par, &zopts->precond_par, queue ) ); break; case Magma_PCGSMERGE: CHECK( magma_zpcgs_merge( A, b, x, &zopts->solver_par, &zopts->precond_par, queue ) ); break; case Magma_TFQMR: CHECK( magma_ztfqmr( A, b, x, &zopts->solver_par, queue ) ); break; case Magma_PTFQMR: CHECK( magma_zptfqmr( A, b, x, &zopts->solver_par, &zopts->precond_par, queue ) ); break; case Magma_TFQMRMERGE: CHECK( magma_ztfqmr_merge( A, b, x, &zopts->solver_par, queue ) ); break; case Magma_PTFQMRMERGE: CHECK( magma_zptfqmr_merge( A, b, x, &zopts->solver_par, &zopts->precond_par, queue ) ); break; case Magma_QMR: CHECK( magma_zqmr( A, b, x, &zopts->solver_par, queue ) ); break; case Magma_PQMR: CHECK( magma_zpqmr( A, b, x, &zopts->solver_par, &zopts->precond_par, queue ) ); break; case Magma_PQMRMERGE: CHECK( magma_zpqmr_merge( A, b, x, &zopts->solver_par, &zopts->precond_par, queue ) ); break; case Magma_QMRMERGE: CHECK( magma_zqmr_merge( A, b, x, &zopts->solver_par, queue ) ); break; case Magma_BOMBARD: CHECK( magma_zbombard( A, b, x, &zopts->solver_par, queue ) ); break; case Magma_BOMBARDMERGE: CHECK( magma_zbombard_merge( A, b, x, &zopts->solver_par, queue ) ); break; default: printf("error: solver class not supported.\n"); break; } } else { switch( zopts->solver_par.solver ) { case Magma_CG: CHECK( magma_zbpcg( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_PCG: CHECK( magma_zbpcg( A, b, x, &zopts->solver_par, &zopts->precond_par, queue )); break; case Magma_LOBPCG: CHECK( magma_zlobpcg( A, &zopts->solver_par, &zopts->precond_par, queue )); break; default: printf("error: only 1 RHS supported for this solver class.\n"); break; } } cleanup: return info; }
/* //////////////////////////////////////////////////////////////////////////// -- Debugging file */ int main( int argc, char** argv) { TESTING_INIT(); magma_z_solver_par solver_par; magma_z_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; magmaDoubleComplex one = MAGMA_Z_MAKE(1.0, 0.0); magmaDoubleComplex zero = MAGMA_Z_MAKE(0.0, 0.0); magma_z_sparse_matrix A, B, B_d; magma_z_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; magmaDoubleComplex *diag_vals; magma_zmalloc_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_Z_MAKE( 4.1, 0.0 ); diag_vals[1] = MAGMA_Z_MAKE( -1.0, 0.0 ); diag_vals[2] = MAGMA_Z_MAKE( -1.0, 0.0 ); magma_zmgenerator( 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_zmscale( &A, Magma_UNITDIAG ); magma_z_mconvert( A, &B, Magma_CSR, B.storage_type ); magma_z_mtransfer( B, &B_d, Magma_CPU, Magma_DEV ); // test CG #################################### // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // solver magma_zcg_res( B_d, b, &x, &solver_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); // test PCG Jacobi ############################ // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_JACOBI; magma_z_precondsetup( B_d, b, &precond_par ); // solver magma_zpcg( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); // test PCG IC ################################ // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ICC; magma_z_precondsetup( B_d, b, &precond_par ); // solver magma_zpcg( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); // test PCG IC ################################ // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ICC; magma_z_precondsetup( B_d, b, &precond_par ); // solver magma_zpcg( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); // test BICGSTAB #################################### // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // solver magma_zbicgstab( B_d, b, &x, &solver_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); // test PBICGSTAB Jacobi ############################ // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_JACOBI; magma_z_precondsetup( B_d, b, &precond_par ); // solver magma_zpbicgstab( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); /* // test PBICGSTAB ILU ############################### // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ILU; magma_z_precondsetup( B_d, b, &precond_par ); // solver magma_zpbicgstab( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); // test PBICGSTAB ILU ############################### // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x);printf("here\n"); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ILU; magma_z_precondsetup( B_d, b, &precond_par ); // solver magma_zpbicgstab( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); // test GMRES #################################### // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // solver magma_zgmres( B_d, b, &x, &solver_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); // test PGMRES Jacobi ############################ // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_JACOBI; magma_z_precondsetup( B_d, b, &precond_par ); // solver magma_zpgmres( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b);*/ // test PGMRES ILU ############################### // vectors and initial guess magma_z_vinit( &b, Magma_DEV, A.num_cols, one ); magma_z_vinit( &x, Magma_DEV, A.num_cols, one ); magma_z_spmv( one, B_d, x, zero, b ); // b = A x magma_z_vfree(&x); magma_z_vinit( &x, Magma_DEV, A.num_cols, zero ); magma_zsolverinfo_init( &solver_par, &precond_par ); // Preconditioner precond_par.solver = Magma_ILU; magma_z_precondsetup( B_d, b, &precond_par ); // solver magma_zpgmres( B_d, b, &x, &solver_par, &precond_par ); // solverinfo magma_zsolverinfo( &solver_par, &precond_par ); if( solver_par.numiter > 150 ){ printf("error: test not passed!\n"); exit(-1); } magma_zsolverinfo_free( &solver_par, &precond_par ); magma_z_vfree(&x); magma_z_vfree(&b); printf("all tests passed.\n"); magma_z_mfree(&B_d); magma_z_mfree(&B); magma_z_mfree(&A); TESTING_FINALIZE(); return 0; }