#include "../include/lass.h"

/**
 *
 * 	@file dsss_dspmv.c
 *
 * 	@brief LASs-DSSs dsss_dspmv routine.
 *
 * 	LASs-DSSs is a software package provided by:
 * 	Barcelona Supercomputing Center - Centro Nacional de Supercomputacion
 *
 * 	@author Sandra Catalán sandra.catalan@bsc.es 
 * 	@author Pedro Valero-Lara pedro.valero@bsc.es 
 * 	@date 2019-05-30
 * 	@reviewer
 * 	@modified 
 *
 **/

/**
 *  
 *	@ingroup DSSs
 *   
 *	Performs the sparse matrix-vector operation with the CSR format:
 *
 *		Y = ALPHA * A * X + BETA * Y
 *
 *	where ALPHA and BETA are scalars, X and Y are vectors, and 
 *  A is a sparse matrix stored in the next three vectors 
 *  CSR_VAL_A, CSR_COL_IND_A and CSR_ROW_PTR_A according to CSR format.
 *
 **/

/**
 *    
 *	@param[in]
 *  M   			int.
 *	    			M specifies the number of rows of A.
 *
 *	@param[in]
 *  N   			int.
 *	    			N specifies the number of columns of A.
 *
 *	@param[in]
 *  ALPHA   		double.
 *
 *	@param[in]
 *  CSR_VAL_A		double *.
 *	       			VAL_A is a pointer to a vector which specifies the non-zero 
 *          		values of the original matrix A. 
 *   
 *	@param[in]
 *  CSR_ROW_PTR_A   unsigned int *.
 * 			    	ROW_PTR_A is a pointer to a vector which specifies 
 *					the number of values that A contains in each row of 
 *					the original matrix.
 *
 *	@param[in]
 *  CSR_COL_IND_A  	unsigned int *.
 * 			    	COL_IND_A is a pointer to a vector which specifies 
 *					the column index of each value of A in the original matrix. 
 *
 *  @param[in]
 *  X       		double *.
 *          		X is a pointer to a vector of dimension N. 
 *
 *  @param[in]
 *  BETA       		double.
 *
 *	@param[in, out]
 *  Y  				double *.
 *          		Y is a pointer to a vector of dimension M. On exit, 
 *					Y is overwritten by the sparse matrix-vector result. 
 *   
 *
 **/

/**
 *
 *	@retval Success sucessful exit
 *	@retval NoSuccess unsucessful exit
 *
 **/

/**
 * 
 * @sa kdspmv
 *
 **/

int dsss_dspmv ( int M, int N, 
		double ALPHA, 
        const double *CSR_VAL_A, const int *CSR_ROW_PTR_A,
		const int *CSR_COL_IND_A, 
		const double *X, 
        double BETA, 
		double *Y ) 
{
	if ( ALPHA == 0 && BETA == 1 )
		return Success;

    if ( M < 0 )
    {
        fprintf( stderr, "Illegal value of M, in dsss_dspmv code\n" );
        return NoSuccess;
    }

    if ( N < 0 )
    {
        fprintf( stderr, "Illegal value of N, in dsss_dspmv code\n" );
        return NoSuccess;
    }


    return kdspmv( M, N, 
		ALPHA, 
        CSR_VAL_A, CSR_ROW_PTR_A,
        CSR_COL_IND_A, 
		X, 
        BETA, 
		Y );

} 
