Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

mkl_cspblas_dcsrgemv gives wrong results

$
0
0

I was trying to compute the sparse matrix-vector multiplication using mkl_cspblas_dcsrgemv() in the MKL.

The c compiler comes from composer_xe_2013.0.079 in the parallelstudio_2013 version with all the environment variables set up. (by sourcing the iccvars.sh)

The strange thing is that if I compile the code with the switch:

icc test1.c -g -DMKL_ILP64 -openmp -mkl=parallel -lpthread -lm

mkl_cspblas_dcsrgemv() gives the wrong answer.

However, if I compile the code with:

icc test1.c -g -DMKL_ILP64 -openmp -I${MKLROOT}/include -L${MKLROOT}/lib/intel64 -lmkl_intel_ilp64 -lmkl_core -lmkl_intel_thread -lpthread -lm

the answer is correct.

The source file of test1.c is:

// test1.c
#include <mkl.h>
#include <stdio.h>

int main(int argc, char **argv)
{
MKL_INT n = 5 ;
MKL_INT Ap [ ] = {0, 2, 5, 9, 10, 12} ;
MKL_INT Ai [ ] = { 0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4} ;
double Ax [ ] = {2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.} ;
double b [ ] = {8., 45., -3., 3., 19.} ;
double x [5] ;

printf("sizeof long: %lu\n",sizeof(long));
printf("sizeof MKL_INT: %lu\n",sizeof(MKL_INT));

mkl_cspblas_dcsrgemv("T",&n,Ax,Ap,Ai,b,x);

printf("%f  %f  %f  %f  %f\n",x[0],x[1],x[2],x[3],x[4]);

return 0;
}

More strange thing is that if I compile the whole program with the latter set of switches, the umfpack does not work. To test it, the code test2.c gives an example from the manual of umfpack.

// test2.c
#include <stdio.h>
#include "umfpack.h"

int n = 5 ;
int Ap [ ] = {0, 2, 5, 9, 10, 12} ;
int Ai [ ] = { 0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4} ;
double Ax [ ] = {2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.} ;
double b [ ] = {8., 45., -3., 3., 19.} ;
double x [5] ;

int main (void)
{
double *null = (double *) NULL ;
int i ;
void *Symbolic, *Numeric ;
(void) umfpack_di_symbolic (n, n, Ap, Ai, Ax, &Symbolic, null, null) ;
(void) umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, null, null) ;
umfpack_di_free_symbolic (&Symbolic) ;
(void) umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, x, b, Numeric, null, null) ;
umfpack_di_free_numeric (&Numeric) ;
for (i = 0 ; i < n ; i++) printf ("x [%d] = %g\n", i, x [i]) ;
return (0) ;
}

If I compile test2.c using (same as the latter set of switches above that can make mkl_cspblas_dcsrgemv work):

icc test14.c -I/mnt/home/software/SuiteSparse/include -I${MKLROOT}/include -Wall -g -openmp -DMKL_ILP64 -L./lib -L/mnt/home/software/SuiteSparse/lib -L${MKLROOT}/lib/intel64 -Wl,-Bstatic -lumfpack -lamd -lsuitesparseconfig -lcholmod -lcolamd -Wl,-Bdynamic -lm -lrt  -ldl -lmkl_intel_ilp64 -lmkl_core -lmkl_intel_thread

The umfpack will get SIGSEGV when it calls mkl_blas_xdgemv().

However, with the set of MKL switch that makes mkl_cspblas_dcsrgemv() give wrong answer:

icc test14.c -I/mnt/home/software/SuiteSparse/include -L/mnt/home/software/SuiteSparse/lib -Wl,-Bstatic -lumfpack -lamd -lsuitesparseconfig -lcholmod -lcolamd -Wl,-Bdynamic -lm -lrt -lpthread -ldl

The umfpack works well.

Same problem also happens on Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 12.1.0.233 Build 20110811.

Since my program needs to have both umfpack and sparse matrix-vector multiplication work together, I am stuck at this point. Could you help locate where the problem is and how to solve it? Is it a bug of umfpack or MKL?

Thank you very much for your help!


Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>