コード例 #1
0
magma_int_t
magma_s_solver( magma_s_sparse_matrix A, magma_s_vector b, 
                 magma_s_vector *x, magma_sopts *zopts ){


        // preconditioner
        if( zopts->solver_par.solver != Magma_ITERREF )
            magma_s_precondsetup( A, b, &zopts->precond_par );

        switch( zopts->solver_par.solver ) {
            case  Magma_CG:
                    magma_scg_res( A, b, x, &zopts->solver_par );break;
            case  Magma_CGMERGE:
                    magma_scg_merge( A, b, x, &zopts->solver_par );break;
            case  Magma_PCG:
                    magma_spcg( A, b, x, &zopts->solver_par, &zopts->precond_par );break;
            case  Magma_BICGSTAB:
                    magma_sbicgstab( A, b, x, &zopts->solver_par );break;
            case  Magma_BICGSTABMERGE: 
                    magma_sbicgstab_merge( A, b, x, &zopts->solver_par );break;
            case  Magma_PBICGSTAB: 
                    magma_spbicgstab( A, b, x, &zopts->solver_par, &zopts->precond_par );break;
            case  Magma_GMRES: 
                    magma_sgmres( A, b, x, &zopts->solver_par );break;
            case  Magma_PGMRES: 
                    magma_spgmres( A, b, x, &zopts->solver_par, &zopts->precond_par );break;
            case  Magma_LOBPCG: 
                    magma_slobpcg( A, &zopts->solver_par );break;
            case  Magma_ITERREF: 
                    magma_siterref( A, b, x, &zopts->solver_par, &zopts->precond_par );break;
            case  Magma_JACOBI: 
                    magma_sjacobi( A, b, x, &zopts->solver_par );break;
            case  Magma_BAITER: 
                    magma_sbaiter( A, b, x, &zopts->solver_par );break;
        }
    return MAGMA_SUCCESS;
}
コード例 #2
0
ファイル: run_spcg.cpp プロジェクト: EmergentOrder/magma
/* ////////////////////////////////////////////////////////////////////////////
   -- running magma_scg magma_scg_merge 
*/
int main( int argc, char** argv)
{
    TESTING_INIT();

    magma_s_solver_par solver_par;
    solver_par.epsilon = 10e-16;
    solver_par.maxiter = 1000;
    solver_par.verbose = 0;
    solver_par.num_eigenvalues = 0;
    magma_s_preconditioner precond_par;
    precond_par.solver = Magma_JACOBI;
    precond_par.levels = 0;
    precond_par.sweeps = 10;
    int precond = 0;
    int format = 0;
    int version = 0;
    int scale = 0;
    magma_scale_t scaling = Magma_NOSCALE;
    
    magma_s_sparse_matrix A, B, B_d;
    magma_s_vector x, b;
    B.blocksize = 8;
    B.alignment = 8;
    
    float one = MAGMA_S_MAKE(1.0, 0.0);
    float zero = MAGMA_S_MAKE(0.0, 0.0);

    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 ) {
            precond = atoi( argv[++i] );
            switch( precond ) {
                case 0: precond_par.solver = Magma_JACOBI; break;
                case 1: precond_par.solver = Magma_ICC; break;
                case 2: precond_par.solver = Magma_AICC; break;
            }

        }else if ( strcmp("--version", argv[i]) == 0 ) {
            version = atoi( argv[++i] );
        }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], "%f", &solver_par.epsilon );
        } else if ( strcmp("--levels", argv[i]) == 0 ) {
            precond_par.levels = atoi( argv[++i] );
        }else if ( strcmp("--sweeps", argv[i]) == 0 ) {
            precond_par.sweeps = atoi( argv[++i] );
        } else
            break;
    }
    printf( "\n#    usage: ./run_spcg"
        " [ --format %d (0=CSR, 1=ELL 2=ELLRT, 3=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"
        " --precond %d (0=Jacobi, 1=IC, 2=AIC [ --levels %d --sweeps %d]) ]"
        " matrices \n\n", format, (int)B.blocksize, (int)B.alignment,
        scale,
        (int)solver_par.verbose,
        (int)solver_par.maxiter, solver_par.epsilon, 
        precond, (int) precond_par.levels, (int) precond_par.sweeps );

    magma_ssolverinfo_init( &solver_par, &precond_par );

    while(  i < argc ){

        magma_s_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 matrix
        magma_smscale( &A, scaling );

        magma_s_mconvert( A, &B, Magma_CSR, B.storage_type );
        magma_s_mtransfer( B, &B_d, Magma_CPU, Magma_DEV );

        // vectors and initial guess
        magma_s_vinit( &b, Magma_DEV, A.num_cols, one );
        magma_s_vinit( &x, Magma_DEV, A.num_cols, one );
        magma_s_spmv( one, B_d, x, zero, b );                 //  b = A x
        magma_s_vfree(&x);
        magma_s_vinit( &x, Magma_DEV, A.num_cols, zero );

        magma_s_precondsetup( B_d, b, &precond_par );

        magma_spcg( B_d, b, &x, &solver_par, &precond_par );

        magma_ssolverinfo( &solver_par, &precond_par );

        magma_s_mfree(&B_d);
        magma_s_mfree(&B);
        magma_s_mfree(&A); 
        magma_s_vfree(&x);
        magma_s_vfree(&b);

        i++;
    }

    magma_ssolverinfo_free( &solver_par, &precond_par );

    TESTING_FINALIZE();
    return 0;
}