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

Mkl produce "segmentation fault" in ubuntu

cibin_W_
Beginner
813 Views

Hi,

code:

#include "iostream"
        #include "stdio.h"
#include <vector>

#include "mkl_service.h"
#include "mkl_pardiso.h"
#include "mkl_types.h"
#include "mkl_dss.h"
#include "mkl_types.h"
#include "mkl_spblas.h"

using namespace std;
using std::vector;

//-----------------------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------------------
void solveSparse_MKL()
{
    _DOUBLE_PRECISION_t rhs[9] = { 0,0.333333,0.666667,0.111111,0.444444,0.777778,0.222222,0.555556,0.888889 };

    MKL_INT nnz = 23;
    MKL_INT nRows = 9;
    MKL_INT nCols = 9;
    MKL_INT nRhs = 1;
    MKL_INT rhs_len = 9;

    double acoo[] = { -0.0537308, -0.0512116, 1.10494, -4.17055, -1.73111, 6.95287, -7.78207, 0, 10.5132, -1.73111, -0.865586, 3.65043, -5.3765, -2.14414, 13.5568, -8.98329, 0, 19.9095, -1.30956, 4.04067, -2.5529, 10.239, 12.5362 };
    MKL_INT rowind[] = { 1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,8,8,9 };
    MKL_INT colind[] = { 4, 2, 1, 5, 3, 2, 6, 4, 3, 7, 5, 4, 8, 6, 5, 9, 7, 6, 8, 7, 9, 8, 9 };

    MKL_INT info;
    MKL_INT job[8] = { 2, // COO to CSR
        1, // 1 based indexing in CSR rows
        1, // 1 based indexing in CSR cols
        0, //
        nnz, // number of the non-zero elements
        0, // job indicator
        0,
        0
    };

    MKL_INT* i_csr = new MKL_INT[nCols + 1]; // m+1
    MKL_INT* j_csr = new MKL_INT[nnz];
    double* a_csr = new double[nnz];

    mkl_dcsrcoo(job, &nCols, a_csr, j_csr, i_csr, &nnz, acoo, rowind, colind, &info);

    _DOUBLE_PRECISION_t* solValues = new _DOUBLE_PRECISION_t[rhs_len];

    // Allocate storage for the solver handle and the right-hand side.
    _MKL_DSS_HANDLE_t handle = 0;
    _INTEGER_t error;
    MKL_INT opt = MKL_DSS_DEFAULTS;
    MKL_INT sym = MKL_DSS_SYMMETRIC;
    MKL_INT type = MKL_DSS_POSITIVE_DEFINITE;
    // ---------------------
    // Initialize the solver
    // ---------------------
    error = dss_create(handle, opt);
    if (error != MKL_DSS_SUCCESS)
        printf("Solver returned error code %d\n", error);
    // -------------------------------------------
    // Define the non-zero structure of the matrix
    // -------------------------------------------
    error = dss_define_structure(handle, sym, i_csr, nRows, nCols, j_csr, nnz);
    if (error != MKL_DSS_SUCCESS)
        printf("Solver returned error code %d\n", error);
    // ------------------
    // Reorder the matrix
    // ------------------
    error = dss_reorder(handle, opt, 0);
    if (error != MKL_DSS_SUCCESS)
        printf("Solver returned error code %d\n", error);
    // ------------------
    // Factor the matrix
    // ------------------
    error = dss_factor_real(handle, type, a_csr);
    if (error != MKL_DSS_SUCCESS)
        printf("Solver returned error code %d\n", error);
    // ------------------------
    // Get the solution vector  
    // ------------------------
    error = dss_solve_real(handle, opt, rhs, nRhs, solValues);
    if (error != MKL_DSS_SUCCESS)
        printf("Solver returned error code %d\n", error);

    cout << "------------------------------" << endl;
    cout << "solution " << endl;
    cout << "------------------------------" << endl;
    for (int j = 0; j < rhs_len; ++j)
    {
        cout << solValues << endl;
    }
    // --------------------------
    // Deallocate solver storage  
    // --------------------------
    error = dss_delete(handle, opt);
    if (error != MKL_DSS_SUCCESS)
        printf("Solver returned error code %d\n", error);

    delete[] a_csr;
    delete[] i_csr;
    delete[] j_csr;
    delete[] solValues;
}

//-----------------------------------------------------------------------------------------------------
// https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor
//-----------------------------------------------------------------------------------------------------
int main(void)
{

MKLVersion Version;

mkl_get_version(&Version);

    solveSparse_MKL();
    getchar();
    return 0;
}
// c:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\examples\examples_core_c.zip\

 

Results while run:

Major version: 2017
Minor version: 0
Update version: 2
Product status: Product
Build: 20170126
Platform: Intel(R) 64 architecture
Processor optimization: Intel(R) Streaming SIMD Extensions 2 (Intel(R) SSE2) enabled processors
================================================================

Segmentation fault

Os Details:

Screenshot from 2017-05-03 15:32:08.png

 

I have also posted this question before in

https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/731522

 

 

Regards

CIBIN

0 Kudos
4 Replies
Ying_H_Intel
Employee
813 Views

Hi,
I read the thread, it seems you are using ILP64 and tbb threads, get segment fault on SSE2 machine.

Could you please try general LP64 + OpenMP thread and see if it works?

1-->g++ -std=c++11 -m64 -I/include -c -O2 -Iinclude -Iinclude/opencv -Iinclude/opencv2 -Iboost -Iboost/boost -Idlib/include -Itbb/include -I/opt/intel/compilers_and_libraries/linux/mkl/include -I. -MMD -MP -MF "build/Release/GNU-Linux/main.o.d" -c main.cpp
2-->g++ -o test main.o -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lstdc++ -lpthread -lm -ldl

Best Regards,

Ying

0 Kudos
cibin_W_
Beginner
813 Views

Hi Ying,

Thanks for the reply

I tried the above steps,and its working fine .The result

Major version: 2017
Minor version: 0
Update version: 2
Product status: Product
Build: 20170126
Platform: Intel(R) 64 architecture
Processor optimization: Intel(R) Advanced Vector Extensions (Intel(R) AVX) enabled processors
================================================================

------------------------------
solution
------------------------------
0.0384921
0.494602
0.582386
0.320155
0.502434
0.591085
0.358512
0.513289
0.598997


Thanks

 

 

Regards

CIBIN

0 Kudos
Ying_H_Intel
Employee
813 Views

Hi CIBIN,

Nice to know the result. If no special requirement about TBB threads, you may use the build command on your case.

I did further investigation on SandyBridge machine. It seems work fine with ILP64 and TBB as below.   So there are some issue about the cpu type: Processor optimization: Intel(R) Streaming SIMD Extensions 2 (Intel(R) SSE2) enabled processors. As i recalled, the latest support instruction is SSSE3 and later.  Which may be the root cause of the segment.  But  your machine is Core i3 .  which is supposed already AVX instruction.  So the SSE2 should be wrong.

Best Regard,

Ying

[yhu5@snb04 mklTest]$ g++ dss.cpp  -DMKL_ILP64 -m64 -I/include -O2 -Iinclude  -Itbb/include -I/opt/intel/compilers_and_libraries/linux/mkl/include -I. -MMD -MP  -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -lstdc++ -lpthread -lm -ldl  -o test_dss_io
[yhu5@snb04 mklTest]$ ./test_dss_io
Major version: 2018
Minor version: 0
Update version: 0
Product status: Beta
Build: 20170316
Platform: Intel(R) 64 architecture
Processor optimization: Intel(R) Advanced Vector Extensions (Intel(R) AVX) enabled processors
================================================================

------------------------------
solution
------------------------------
0.0384921
0.494602
0.582386
0.320155
0.502434
0.591085
0.358512
0.513289
0.598997
s

 

0 Kudos
cibin_W_
Beginner
813 Views

Hi Ying,

         Thanks for the reply," LP64 + OpenMP" works fine for my project ,will try this too.

  Thank you soo much......

 

Regards

CIBIN

0 Kudos
Reply