Example #1
0
magma_int_t
magma_cbaiter( magma_c_sparse_matrix A, magma_c_vector b, magma_c_vector *x,  
           magma_c_solver_par *solver_par )
{
    // prepare solver feedback
    solver_par->solver = Magma_BAITER;
    solver_par->info = 0;

    magma_c_sparse_matrix A_d, D, R, D_d, R_d;
    magma_c_mtransfer( A, &A_d, Magma_CPU, Magma_DEV );

    // initial residual
    real_Double_t tempo1, tempo2;
    float residual;
    magma_cresidual( A_d, b, *x, &residual );
    solver_par->init_res = residual;
    solver_par->res_vec = NULL;
    solver_par->timing = NULL;

    // setup
    magma_ccsrsplit( 256, A, &D, &R );
    magma_c_mtransfer( D, &D_d, Magma_CPU, Magma_DEV );
    magma_c_mtransfer( R, &R_d, Magma_CPU, Magma_DEV );

    magma_int_t localiter = 1;

    magma_device_sync(); tempo1=magma_wtime();

    // block-asynchronous iteration iterator
    for( int iter=0; iter<solver_par->maxiter; iter++)
        magma_cbajac_csr( localiter, D_d, R_d, b, x );

    magma_device_sync(); tempo2=magma_wtime();
    solver_par->runtime = (real_Double_t) tempo2-tempo1;
    magma_cresidual( A_d, b, *x, &residual );
    solver_par->final_res = residual;
    solver_par->numiter = solver_par->maxiter;

    if( solver_par->init_res > solver_par->final_res )
        solver_par->info = 0;
    else
        solver_par->info = -1;

    magma_c_mfree(&D);
    magma_c_mfree(&R);
    magma_c_mfree(&D_d);
    magma_c_mfree(&R_d);
    magma_c_mfree(&A_d);

    return MAGMA_SUCCESS;
}   /* magma_cbaiter */
Example #2
0
extern "C" magma_int_t
magma_cbaiter(
    magma_c_sparse_matrix A, 
    magma_c_vector b, 
    magma_c_vector *x,  
    magma_c_solver_par *solver_par,
    magma_queue_t queue )
{
    // prepare solver feedback
    solver_par->solver = Magma_BAITER;
    solver_par->info = MAGMA_SUCCESS;



    magma_c_sparse_matrix Ah, ACSR, A_d, D, R, D_d, R_d;

    magma_c_mtransfer( A, &Ah, A.memory_location, Magma_CPU, queue );
    magma_c_mconvert( Ah, &ACSR, Ah.storage_type, Magma_CSR, queue );

    magma_c_mtransfer( ACSR, &A_d, Magma_CPU, Magma_DEV, queue );

    // initial residual
    real_Double_t tempo1, tempo2;
    float residual;
    magma_cresidual( A_d, b, *x, &residual, queue );
    solver_par->init_res = residual;
    solver_par->res_vec = NULL;
    solver_par->timing = NULL;


    // setup
    magma_ccsrsplit( 256, ACSR, &D, &R, queue );
    magma_c_mtransfer( D, &D_d, Magma_CPU, Magma_DEV, queue );
    magma_c_mtransfer( R, &R_d, Magma_CPU, Magma_DEV, queue );

    magma_int_t localiter = 1;

    tempo1 = magma_sync_wtime( queue );

    // block-asynchronous iteration iterator
    for( int iter=0; iter<solver_par->maxiter; iter++)
        magma_cbajac_csr( localiter, D_d, R_d, b, x, queue );

    tempo2 = magma_sync_wtime( queue );
    solver_par->runtime = (real_Double_t) tempo2-tempo1;
    magma_cresidual( A_d, b, *x, &residual, queue );
    solver_par->final_res = residual;
    solver_par->numiter = solver_par->maxiter;

    if ( solver_par->init_res > solver_par->final_res )
        solver_par->info = MAGMA_SUCCESS;
    else
        solver_par->info = MAGMA_DIVERGENCE;

    magma_c_mfree(&D, queue );
    magma_c_mfree(&R, queue );
    magma_c_mfree(&D_d, queue );
    magma_c_mfree(&R_d, queue );
    magma_c_mfree(&A_d, queue );
    magma_c_mfree(&ACSR, queue );
    magma_c_mfree(&Ah, queue );

    return MAGMA_SUCCESS;
}   /* magma_cbaiter */