Magma Sparse Example

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)
Post Reply
Posts: 1
Joined: Thu Nov 19, 2015 4:13 pm

Magma Sparse Example

Post by costat » Mon Feb 22, 2016 3:16 pm

I'm having trouble inserting magma sparse into my existing code -- it seems to me that the example documentation is outdated. At the point that I would like to use Magma I have a sparse CSR representation of a system stemming from discretization of a porous media flow problem. With other linear algebra software I have had the best success with GMRES + ILU preconditioning, so that is what I am trying to get working, first. I'm including my code below.

Code: Select all

magma_int_t info = 0;
magma_dopts opts;
magma_queue_t queue = NULL;
magma_queue_create( &queue );

magma_d_matrix A={Magma_CSR}, d_A={Magma_CSR};
magma_d_vector b, d_b, d_x;

// Set A and b from CSR vectors
magma_dcsrset( Mesh.dofTotal, Mesh.dofTotal, &rowPTR[0], &matJs[0], &matVals[0], &A, queue );
magma_dvset( Mesh.dofTotal, 1, &force[0], &b, queue );

printf( "\n%% matrix info: %d-by-%d with %d nonzeros\n\n",
          (int) A.num_rows,(int) A.num_cols,(int) A.nnz );

// magma setup
magma_dsolverinfo_init( &opts.solver_par, &opts.precond_par, queue );
opts.solver_par.solver = Magma_GMRES;
opts.precond_par.solver = Magma_ILU;
magma_dmtransfer( A, &d_A, Magma_CPU, Magma_DEV, queue );
magma_dmtransfer( b, &d_b, Magma_CPU, Magma_DEV, queue );
magma_dvinit( &d_x, Magma_DEV, Solution.size(), 1, Solution[0], queue );
magma_d_precondsetup( d_A, d_b, &opts.solver_par, &opts.precond_par, queue );

// solve the system
magma_d_solver( d_A, d_b, &d_x, &opts, queue );
magma_dsolverinfo( &opts.solver_par, &opts.precond_par, queue );

magma_int_t mout, nout;
double * valout;
// bring the solution back to host, fill std::vector solution
magma_dvget( d_x, &mout, &nout, &valout, queue );
The result from this run (on a very, very small problem) is

Code: Select all

error: linear algebra objects are not located in same memory!
memory locations are: 32728   572   0
%   iter   ||   residual-nrm2    ||   runtime    ||   SpMV-count   ||   info
        1       1.286840e-316          4.292634              532            0

% PGMRES(32728) solver summary:
%    initial residual: 1.732051e+00
%    preconditioner setup: 0.0001 sec
%    iterations:    1
%    SpMV-count:  532
%    exact final residual: 1.653523e-13
%    runtime: 4.2926 sec
%    preconditioner runtime: 0.0000 sec
As I run bigger problems (still very, very small), the SpMV-count climbs quickly, I continue to get memory location errors, and it sticks with 1 iteration. For very small problems the time spent on a very high # of SpMVs becomes intractable. Any help will be greatly appreciated.

hartwig anzt
Posts: 90
Joined: Tue Sep 02, 2014 5:44 pm

Re: Magma Sparse Example

Post by hartwig anzt » Mon Feb 22, 2016 4:43 pm

Dear Costa,

I can not exactly reproduce your problem, but have some comments. You use opts.solver_par without initializing most of the fields.

E.g. you should set:
opts.solver_par.maxiter = 1000;
opts.solver_par.rtol = 1e-10;
opts.solver_par.rtol = 1e-10;
opts.solver_par.restart = 50;

An elegant workaround that sets all options to some default values is:

magma_dparse_opts( argc, argv, &zopts, &i, queue );

Please let me know whether this solves the problem for you.

Thanks, Hartwig

Post Reply