Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

A*c=b problem

dogval
Beginner
233 Views
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.
0 Kudos
7 Replies
Alexander_K_Intel2
233 Views
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
dogval
Beginner
233 Views

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 = 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 );
continue;
}

return false;
}

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

MKL_FreeBuffers();

return true;
}

Alexander_K_Intel2
233 Views
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
dogval
Beginner
233 Views
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!
Alexander_K_Intel2
233 Views
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 );
dogval
Beginner
233 Views
You can usejust 2 arrays.
One double [][] fileA = {...}
and second double [] fileB = {...}

Pls help !!!!
Ying_H_Intel
Employee
233 Views
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 "
andread the input sparse matrix,
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.

Please see MKL manuals.
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
Reply