Matlab crashes when Intel MKL’s function Pardiso is called
Hello everyone!
I am currently working with Matlab R2021b on Ubuntu 22.04. I am writing a program that will solve linear sparse system of equations, and I am trying to solve it with Pardiso function from Intel MKL library.
I have successfully compiled Mex file in C (that is calling Pardiso function); however when I call Mex file, Matlab crashes without any output or message.
I am using GCC to compile my Mex file. This is the code for compilation:
mex CFLAGS="$CFLAGS -m64" LDFLAGS="$LDFLAGS -m64" pardiso_sparse.c -I/opt/intel/oneapi/mkl/2024.2/include -L/opt/intel/oneapi/mkl/2024.2/lib -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
Here is the Mex file itself. It is quite short:
#include "mex.h"
#include "math.h"
#include "matrix.h"
#include "stdint.h"
#include "mkl.h"
/*#define PARDISO_MAX_SIZE 64*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *vals, *RG;
int32_t *rows, *cols;
int32_t n;
// input
vals = mxGetPr(prhs[0]);
rows = (int32_t*) mxGetData(prhs[1]);
cols = (int32_t*) mxGetData(prhs[2]);
RG = mxGetPr(prhs[3]);
n = (int32_t) mxGetScalar(prhs[4]);
// Create the output solution vector x (n x 1)
plhs[0] = mxCreateDoubleMatrix(n, 1, mxREAL);
double *sol = mxGetPr(plhs[0]);
// PARDISO control parameters
void *pt[64] = {0}; // Internal solver memory pointer
MKL_INT iparm[64] ; // Control parameters
MKL_INT maxfct = 1, mnum = 1, phase, error = 0, msglvl = 1;
MKL_INT mtype = 2; // Real symmetric matrix
MKL_INT n_mkl = (MKL_INT)n;
MKL_INT nrhs_mkl = 1; // Number of right-hand sides (for solving Ax=b)
MKL_INT idum; // Dummy integer used for PARDISO
double ddum;
// Initialize PARDISO control parameters to default
iparm[0] = 0; // Use default PARDISO parameters
// Step 1: Reordering and symbolic factorization
printf("Analysis is running!");
phase = 11;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, NULL, NULL, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during symbolic factorization: %d", error);
}
printf("First phase done!");
// Step 2: Numerical factorization
phase = 22;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during numerical factorization: %d", error);
}
printf("Second phase done!");
// Step 3: Solve and iterative refinement
phase = 33;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, RG, sol, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during solution: %d", error);
}
printf("Thrid phase done!");
// Step 4: Release internal memory
phase = -1;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, &ddum, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
}
Can anyone give me a solution to this? I’ve been trying to run this code for more than a week!
AnteHello everyone!
I am currently working with Matlab R2021b on Ubuntu 22.04. I am writing a program that will solve linear sparse system of equations, and I am trying to solve it with Pardiso function from Intel MKL library.
I have successfully compiled Mex file in C (that is calling Pardiso function); however when I call Mex file, Matlab crashes without any output or message.
I am using GCC to compile my Mex file. This is the code for compilation:
mex CFLAGS="$CFLAGS -m64" LDFLAGS="$LDFLAGS -m64" pardiso_sparse.c -I/opt/intel/oneapi/mkl/2024.2/include -L/opt/intel/oneapi/mkl/2024.2/lib -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
Here is the Mex file itself. It is quite short:
#include "mex.h"
#include "math.h"
#include "matrix.h"
#include "stdint.h"
#include "mkl.h"
/*#define PARDISO_MAX_SIZE 64*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *vals, *RG;
int32_t *rows, *cols;
int32_t n;
// input
vals = mxGetPr(prhs[0]);
rows = (int32_t*) mxGetData(prhs[1]);
cols = (int32_t*) mxGetData(prhs[2]);
RG = mxGetPr(prhs[3]);
n = (int32_t) mxGetScalar(prhs[4]);
// Create the output solution vector x (n x 1)
plhs[0] = mxCreateDoubleMatrix(n, 1, mxREAL);
double *sol = mxGetPr(plhs[0]);
// PARDISO control parameters
void *pt[64] = {0}; // Internal solver memory pointer
MKL_INT iparm[64] ; // Control parameters
MKL_INT maxfct = 1, mnum = 1, phase, error = 0, msglvl = 1;
MKL_INT mtype = 2; // Real symmetric matrix
MKL_INT n_mkl = (MKL_INT)n;
MKL_INT nrhs_mkl = 1; // Number of right-hand sides (for solving Ax=b)
MKL_INT idum; // Dummy integer used for PARDISO
double ddum;
// Initialize PARDISO control parameters to default
iparm[0] = 0; // Use default PARDISO parameters
// Step 1: Reordering and symbolic factorization
printf("Analysis is running!");
phase = 11;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, NULL, NULL, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during symbolic factorization: %d", error);
}
printf("First phase done!");
// Step 2: Numerical factorization
phase = 22;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during numerical factorization: %d", error);
}
printf("Second phase done!");
// Step 3: Solve and iterative refinement
phase = 33;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, RG, sol, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during solution: %d", error);
}
printf("Thrid phase done!");
// Step 4: Release internal memory
phase = -1;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, &ddum, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
}
Can anyone give me a solution to this? I’ve been trying to run this code for more than a week!
Ante Hello everyone!
I am currently working with Matlab R2021b on Ubuntu 22.04. I am writing a program that will solve linear sparse system of equations, and I am trying to solve it with Pardiso function from Intel MKL library.
I have successfully compiled Mex file in C (that is calling Pardiso function); however when I call Mex file, Matlab crashes without any output or message.
I am using GCC to compile my Mex file. This is the code for compilation:
mex CFLAGS="$CFLAGS -m64" LDFLAGS="$LDFLAGS -m64" pardiso_sparse.c -I/opt/intel/oneapi/mkl/2024.2/include -L/opt/intel/oneapi/mkl/2024.2/lib -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
Here is the Mex file itself. It is quite short:
#include "mex.h"
#include "math.h"
#include "matrix.h"
#include "stdint.h"
#include "mkl.h"
/*#define PARDISO_MAX_SIZE 64*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *vals, *RG;
int32_t *rows, *cols;
int32_t n;
// input
vals = mxGetPr(prhs[0]);
rows = (int32_t*) mxGetData(prhs[1]);
cols = (int32_t*) mxGetData(prhs[2]);
RG = mxGetPr(prhs[3]);
n = (int32_t) mxGetScalar(prhs[4]);
// Create the output solution vector x (n x 1)
plhs[0] = mxCreateDoubleMatrix(n, 1, mxREAL);
double *sol = mxGetPr(plhs[0]);
// PARDISO control parameters
void *pt[64] = {0}; // Internal solver memory pointer
MKL_INT iparm[64] ; // Control parameters
MKL_INT maxfct = 1, mnum = 1, phase, error = 0, msglvl = 1;
MKL_INT mtype = 2; // Real symmetric matrix
MKL_INT n_mkl = (MKL_INT)n;
MKL_INT nrhs_mkl = 1; // Number of right-hand sides (for solving Ax=b)
MKL_INT idum; // Dummy integer used for PARDISO
double ddum;
// Initialize PARDISO control parameters to default
iparm[0] = 0; // Use default PARDISO parameters
// Step 1: Reordering and symbolic factorization
printf("Analysis is running!");
phase = 11;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, NULL, NULL, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during symbolic factorization: %d", error);
}
printf("First phase done!");
// Step 2: Numerical factorization
phase = 22;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during numerical factorization: %d", error);
}
printf("Second phase done!");
// Step 3: Solve and iterative refinement
phase = 33;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, RG, sol, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during solution: %d", error);
}
printf("Thrid phase done!");
// Step 4: Release internal memory
phase = -1;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, &ddum, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
}
Can anyone give me a solution to this? I’ve been trying to run this code for more than a week!
Ante matlab, intel mkl, sparse, mex compiler, ubuntu MATLAB Answers — New Questions