# A*c=b problem

## A*c=b problem

Hello,

I am trying to use MKL and have some problems.
If sparse matrix has only one diagonal,everything isOK, but if not I can't find a solution.

This sample was tested on Matlab and passed succefully.

Solvers SG andPARDISO

Can you help me please with this problem.

Pavel.

AttachmentSize
15.26 MB
17.58 KB
17.58 KB
8 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,It's seem that your matrix is dense but all non-diagonal elements are equal to zero. So it's not clear how you translate it CSR format: as diagonal matrix or as dense with many zero elements. Could your provide example that you used to check correctness of PARDISO on this matrix?With best regards,Alexander Kalinkin

vector iaV;
vector jaV;
vector aV;

iaV.push_back(1);

for( int y = 0; y < fileA.Rows(); y++ )
{
int numValues = 0;
bool isData = false;
for( int x = 0; x < fileA.Cols(); x++ )
{
double value = fileA.Get( y, x );

if( value != 0 )
{
numValues++;
jaV.push_back( x + 1 );
aV.push_back( value );
}
}

if( numValues != 0 )
{
iaV.push_back( iaV[ iaV.size() - 1 ] + numValues );
}
}

vector rhsV;

for( int y = 0; y < fileB.Rows(); y++ )
{
double value = fileB.Get( y, 0 );
rhsV.push_back( value );
}

Solve( fileA.GetNumLines(), iaV, jaV, aV, rhsV );

bool Solve( int matrixSize, vector& iaV, vector& jaV, vector& aV, vector& rhsV )
{
int n = matrixSize, rci_request, itercount;

double* rhs = &rhsV[0];
int* ia = &iaV[0];
int* ja = &jaV[0];
double* a = &aV[0];

double* solution = new double[matrixSize];
int ipar[128];
double dpar[128];
double* tmp = new double[4 * matrixSize];
char tr = 'u';

for( int i = 0; i < n; i++ )
solution[i] = 1;

dcg_init( &n, solution, rhs, &rci_request, ipar, dpar, tmp );
if( rci_request != 0 )
return false;

ipar[8] = 1;
ipar[9] = 0;
dpar[0] = 1.E-5;

dcg_check( &n, solution, rhs, &rci_request, ipar, dpar, tmp );

if (rci_request != 0)
return false;

while(true)
{
dcg( &n, solution, rhs, &rci_request, ipar, dpar, tmp );

if (rci_request == 0)
break;

if(rci_request == 1)
{
mkl_dcsrsymv( &tr, &n, a, ia, ja, tmp, &tmp[n] );
continue;
}

return false;
}

dcg_get( &n, solution, rhs, &rci_request, ipar, dpar, tmp, &itercount );

MKL_FreeBuffers();

return true;
}

Hi,In topic below you wrote about problem with PARDISO but as I can see this example use CG routines from MKL. So problem appeared when you use CG or PARDISO?With best regards,Alexander Kalinkin

Hi Alexander!

I tried to solve this matrix with CG and PARDISO, but most of the work was done on CG. I used PARDISO only to check if it passes or not. If you can help me with CG, I would be very glad, but if you think I should work with PARDISO, i will write here a PARDISO sample - it is twice as big.

Thank you for the swift reply!

Hi,I've try to reproduce your problem. You forgot to describe some classes, for example, could you describe fileA & fileB ?With best regards,Alexander Kalinkin./source/test.c(20): error: identifier "fileA" is undefined for( int y = 0; y < fileA.Rows(); y++ ) ^./source/test.c(44): error: identifier "fileB" is undefined for( int y = 0; y < fileB.Rows(); y++ ) ^./source/test.c(50): error: identifier "fileA" is undefined Solve( fileA.GetNumLines(), iaV, jaV, aV, rhsV );

You can usejust 2 arrays.
One double [][] fileA = {...}
and second double [] fileB = {...}

Pls help !!!!

Hi Dogval,

As withoutyour definition of the fileA, file B class, I haven'ttried to the exact code.

But according to your discription :
"If sparse matrix has only one diagonal,everything isOK, but if not I can't find a solution "
I thought, your problem should be in the CSR format of the matA, which issymmetric positive definite system and read by as full CSR format in your code, right?

But the function mkl_dcsrsymv() actually ask the upper or lower trianglein CSR format.

The mkl_?csrsymv routine performs a matrix-vector operation defined as y := A*x

where:

x and y are vectors,

A is an upper or lower triangle of the symmetrical sparse matrix in the CSR format (3-array variation).

So you may need to change the way of read matA,
for example, upper triangle format,

for( int y = 0; y < fileA.Rows(); y++ )
{
int numValues = 0;
bool isData = false;
for( int x = y; x < fileA.Cols(); x++ )

BestRegards,
Ying