Hello,
I am trying to utilize the PARDISO sparse matrix solver to test out a solution with my sparse matrix. The goal of this experiment was to see if I can replicate the same solution that I had while using MATLAB's backslash operator. The results of PARDISO and the solution using the backslash operator were no where near the same.
In order to do this, I exported the sparse matrix arrays from MATLAB into binary files in COO format. I re-imported the sparse matrix arrays into my C program in which I then converted it into CSR format for use with PARDISO using mkl_?csrcoo. I then set up PARDISO to solve it but ended up with inaccurate results. Attached is my code, the matrix bin files, a makefile (just to see what my linking and compiling parameters were) and the original MATLAB sparse matrix in .mat format
My sparse matrix is set up as a nonsymmetric real matrix. I wonder if it's possible to achieve matching results if I set up the right iparm parameters or if the problem lies else where in my program. Either way, I wish to gain insight into my mistake.
The matrix is of size 122860x122860.
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <stdint.h> #include "mkl.h" #include "mkl_pardiso.h" #include "mkl_types.h" #include <time.h> int main() { #define N 122860 #define NNZ_G 491063 #define INFO 0 #define P 64 //*************************************************************************************************** //* Import sparse G matrix data in COO sparse matrix format //*************************************************************************************************** FILE *ptr; char pathG1[] = "./Gmat122860x122860/Gvalues122860x122860.bin"; char pathG2[] = "./Gmat122860x122860/Grows122860x122860.bin"; char pathG3[] = "./Gmat122860x122860/Gcols122860x122860.bin"; double *gval = (double*) calloc(NNZ_G, sizeof(double)); MKL_INT *grow = (MKL_INT*) calloc(NNZ_G, sizeof(MKL_INT)); MKL_INT *gcol = (MKL_INT*) calloc(NNZ_G, sizeof(MKL_INT)); double *gcsr = (double*) calloc(NNZ_G, sizeof(double)); MKL_INT *jg = (MKL_INT*) calloc(NNZ_G, sizeof(MKL_INT)); MKL_INT *ig = (MKL_INT*) calloc(N + 1, sizeof(MKL_INT)); ptr = fopen(pathG1, "rb"); fread(gval, sizeof(double), NNZ_G, ptr); fclose(ptr); ptr = fopen(pathG2, "rb"); fread(grow, sizeof(MKL_INT), NNZ_G, ptr); fclose(ptr); ptr = fopen(pathG3, "rb"); fread(gcol, sizeof(MKL_INT), NNZ_G, ptr); fclose(ptr); //*************************************************************************************************** //* Convert sparse matrix format of G from COO to CSR - base 1 indexing //*************************************************************************************************** MKL_INT job[6]; MKL_INT n = N, nnz_g = NNZ_G; job[0] = 2; job[1] = 1; job[2] = 1; job[3] = 0; job[4] = 0; job[5] = 0; MKL_INT info = INFO; mkl_dcsrcoo(job, &n, gcsr, jg, ig, &nnz_g, gval, grow, gcol, &info); //*************************************************************************************************** // Set up for PARDISO and loop //*************************************************************************************************** void *pt[P]; MKL_INT iparm[P]; MKL_INT i, maxfct, mnum, mtype, idum; MKL_INT msglvl, error, phase; MKL_INT nrhs = 1; mtype = 11; maxfct = 1; // Maximum number of numerical factorizations. mnum = 1; // Which factorization to use. msglvl = 0; // Print statistical information in file error = 0; // Initialize error flag pardisoinit(pt, &mtype, iparm); iparm[34] = 0; // One based indexing char transa = 'n'; double *b0 = (double*) calloc(N, sizeof(double)); b0[N-1] = -0.8; double *x0 = (double*) calloc(N, sizeof(double)); phase = 13; PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &n, gcsr, ig, jg, &idum, &nrhs, iparm, &msglvl, b0, x0, &error); return 0; }