Sparse RHS not yet supported

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)
Post Reply
Posts: 9
Joined: Tue Jul 25, 2017 9:34 am

Sparse RHS not yet supported

Post by Ólafur » Mon Nov 06, 2017 7:25 am


I've been working on spectral analysis problem with a huge Hermitian matrix. But when I call the magma_z_solver I get an error saying that sparse RHS is not yet supported. If I try making it dense it returns an error saying it's expecting a magma_z_matrix format RHS. I thought that magma_z_matrix was a sparse format?
At any rate, I'm not too interested in a vector on the right hand side since I only want the spectrum of the matrix. Unless the routine needs it for the actual calculation it would be nice to save myself the memory of storing a relatively large complex matrix since memory is my main limitation.

Code: Select all

//Compiles with the corresponding makefile.
//Takes in the 3 vectors of CSR format, creates MAGMA format sparse matrix, returns its spectrum.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include "magma_v2.h"
#include "magmasparse.h"

int main()
   int n = 3;  //Dimension of the nxn matrix
   magmaDoubleComplex *sol;

   //Testing with matrix {{4,1-i,2+i},{1+i,-1,1},{2-i,1,3}} that has spectrum {6.08807,-1.61431,1.52624}

   int *col; //Column indices of NNZ in A
   col = (int*) calloc(n*n,   sizeof(int));
   col[0] = 0; col[1]=1; col[2] = 2;
   col[3] = 0; col[4]=1; col[5] = 2;
   col[6] = 0; col[7]=1; col[8] = 2;

   int *row; //Row pointer of NNZ in A
   row = (int*) calloc(n+1, sizeof(int));[code]//Compiles with the corresponding makefile.
   row[0] = 0;   row[1] = 3;   row[2] = 6;   row[3] = 9;

   //NNZ of the matrix A:
   magmaDoubleComplex *val;
   val = malloc(n*n*sizeof(magmaDoubleComplex)); //Allocates the struct on the stack
   if (val == NULL)
        fprintf( stderr, "malloc failed\n" );
        return 0;
       fprintf( stderr, "malloc succeeded\n" );

   val[0] = MAGMA_Z_MAKE(12,0);   val[1] = MAGMA_Z_MAKE(1,-1);   val[2] = MAGMA_Z_MAKE(2,1);
   val[3] = MAGMA_Z_MAKE(1,1);      val[4] = MAGMA_Z_MAKE(-1,0);   val[5] = MAGMA_Z_MAKE(1,0);
   val[6] = MAGMA_Z_MAKE(2,-1);   val[7] = MAGMA_Z_MAKE(1,0);      val[8] = MAGMA_Z_MAKE(3,0);

    printf("val created successfully\n");

   //Initialize MAGMA
   magma_zopts opts;
   magma_queue_t queue;
   magma_queue_create(0, &queue);

   magma_z_matrix A={Magma_CSR}, dA={Magma_CSR};
   magma_z_matrix b={Magma_CSR}, db={Magma_CSR};
   magma_z_matrix x={Magma_CSR}, dx={Magma_CSR};

   //Pass the system to MAGMA

   // Choose a solver, preconditioner, etc. - see documentation for options.
   opts.solver_par.solver = Magma_LOBPCG; // choose an LOBPCG solver
   opts.solver_par.num_eigenvalues = 3; // number of eigenvalues you want to compute
   opts.solver_par.maxiter = 1000; // max number of iterations
   opts.solver_par.rtol = 1e-10; // stopping criterion - relative accuracy of first eigenvalue
   opts.precond_par.solver = Magma_ILU; // preconditioner
   opts.precond_par.levels = 0; // ILU(0) - no fill-in
   opts.precond_par.trisolver = Magma_CUSOLVE; //exact triangular solves

   //Copy the system to device
   magma_zmtransfer(A, &dA, Magma_CPU, Magma_DEV, queue);

   //Generate the preconditioner
   magma_z_precondsetup(dA, db, &opts.solver_par, &opts.precond_par, queue);

   //Calling zlobpcg to find eigenvalues
   magma_z_solver(dA, db, &dx, &opts, queue);
   // magma_zlobpcg(A, &opts, &opts, queue);

   //Then copy the solution back to the host
   magma_zmfree( &x, queue );
   magma_zmtransfer( dx, &x, Magma_CPU, Magma_DEV, queue );

   //and back to the application code
   magma_zvget( x, &n, &n, &sol, queue );

   //Free the allocated memory...
   magma_zmfree( &dx, queue );
   magma_zmfree( &db, queue );
   magma_zmfree( &dA, queue );

   //and finalize MAGMA.
   magma_queue_destroy( queue );

   int i;
   for (i = 0; i < n; ++i) {
      printf("%.4f\n", sol[i]);
   }[code]//Compiles with the corresponding makefile.

   return 0;

Many thanks, Ólafur

Post Reply