<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Segmentation fault in LAPACKE_dgesv for large matrices in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Segmentation-fault-in-LAPACKE-dgesv-for-large-matrices/m-p/1587993#M36011</link>
    <description>&lt;P&gt;Very thanks! The problem is solved after I link my program to libmkl_intel_lp64.so.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2024 07:51:44 GMT</pubDate>
    <dc:creator>szp</dc:creator>
    <dc:date>2024-04-10T07:51:44Z</dc:date>
    <item>
      <title>Segmentation fault in LAPACKE_dgesv for large matrices</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Segmentation-fault-in-LAPACKE-dgesv-for-large-matrices/m-p/1586891#M35994</link>
      <description>&lt;P&gt;Hello! I'm learning usage of MKL these days. When I tried to use LAPACKE_dgesv to solve linear equations, I find that it works for small matrices but fails for large matrices (segmentation fault (core dumped)). My CPU is AMD, operating system is Rockylinux 9, and OneMKL version is 2023.2.0. I have also tried 2024.1, but it has the same problem. I have also set ulimit to unlimit. Here is&amp;nbsp; my code.&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;iomanip&amp;gt;
#include &amp;lt;random&amp;gt;
#include &amp;lt;mkl.h&amp;gt;

using std::cout;
using std::endl;
using std::string;
using std::setw;
using std::setprecision;
using std::fixed;

double generateRandomDouble(double min, double max) {
    static std::random_device rd;
    static std::mt19937 gen(rd());
    std::uniform_real_distribution&amp;lt;double&amp;gt; dis(min, max);
    return dis(gen);
}

int linsol(double *A,double *B, int lda, int ldb, int i) {
    lapack_int *ipiv = new lapack_int[lda];
    int info = 100;
    if (i == 0)
        info = LAPACKE_dgesv(LAPACK_ROW_MAJOR, lda, ldb, A, lda, ipiv, B, ldb);
    else {
        info = LAPACKE_dgesv(LAPACK_COL_MAJOR, lda, ldb, A, lda, ipiv, B, lda);
    }
    delete[] ipiv;
    return info;
}

void print(double *A, int row, int col) {
    for(int i = 0; i &amp;lt; row; ++i) {
        for(int j = 0; j &amp;lt; col; ++j)
            cout &amp;lt;&amp;lt; setw(8) &amp;lt;&amp;lt; fixed &amp;lt;&amp;lt; setprecision(4) &amp;lt;&amp;lt; A[i*col+j] &amp;lt;&amp;lt; " ";
        cout &amp;lt;&amp;lt; endl;
    }
            
}

int main(int argc, char *argv[])
{
    int n = std::stoi(argv[1]);
    double *matrix_a = (double*)mkl_malloc(n * n * sizeof(double), 64);
    double *matrix_b = (double*)mkl_malloc(n * n * sizeof(double), 64);
    for (int i = 0; i &amp;lt; n; ++i) {
        for (int j = 0; j &amp;lt; n; ++j)
            matrix_a[i * n + j] = generateRandomDouble(0.0,1.0);
    }
    for (int i = 0; i &amp;lt; n; ++i) {
        for (int j = 0; j &amp;lt; n; ++j)
            matrix_b[i * n + j] = generateRandomDouble(0.0, 1.0);
    }

    print(matrix_a, n, n);
    cout &amp;lt;&amp;lt; endl;
    print(matrix_b, n, n);
   
    cout &amp;lt;&amp;lt; linsol(matrix_a, matrix_b, n, n, 1) &amp;lt;&amp;lt; endl;
        
    print(matrix_b, n, n);

    mkl_free(matrix_a);
    mkl_free(matrix_b);
    return 0;    
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And my CMakelists.txt is as follows (MKLROOT has been set as environment variable).&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;cmake_minimum_required(VERSION 3.10)
project(mkl LANGUAGES CXX)
file(GLOB SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
set(CMAKE_CXX_STANDARD 17)
list(APPEND CMAKE_CXX_FLAGS -O3)
find_package(MKL REQUIRED)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(1 ${SRC})
target_link_libraries(1 iomp5 ${MKL_LIBRARIES})&lt;/LI-CODE&gt;&lt;P&gt;The configuration is as follows.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;-- The CXX compiler identification is GNU 11.4.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- MKL_ARCH: None, set to ` intel64` by default
-- MKL_LINK: None, set to ` dynamic` by default
-- MKL_INTERFACE_FULL: None, set to ` intel_ilp64` by default
-- MKL_THREADING: None, set to ` intel_thread` by default
-- Found MKL: /opt/intel/oneapi/mkl/2023.2.0
-- Found MKL: /opt/intel/oneapi/mkl/2023.2.0/lib/intel64/libmkl_intel_ilp64.so
-- Found MKL: /opt/intel/oneapi/mkl/2023.2.0/lib/intel64/libmkl_intel_thread.so
-- Found MKL: /opt/intel/oneapi/mkl/2023.2.0/lib/intel64/libmkl_core.so
-- Found MKL: /opt/intel/oneapi/compiler/latest/linux/compiler/lib/intel64_lin/libiomp5.so
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /path/to/my/dir&lt;/LI-CODE&gt;&lt;P&gt;On my computer, when n &amp;gt;=25, it appears "Segmentation fault (core dumped)", and the returned value of LAPACKE_dgesv is not printed on the screen, so I think the error occurs in the function. So what is the problem? How to solve it? Very thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 06 Apr 2024 03:19:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Segmentation-fault-in-LAPACKE-dgesv-for-large-matrices/m-p/1586891#M35994</guid>
      <dc:creator>szp</dc:creator>
      <dc:date>2024-04-06T03:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Segmentation fault in LAPACKE_dgesv for large matrices</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Segmentation-fault-in-LAPACKE-dgesv-for-large-matrices/m-p/1587977#M36010</link>
      <description>&lt;P&gt;At the first glance the problem is that you link against ilp64 libraries (&lt;SPAN&gt;libmkl_intel_&lt;/SPAN&gt;&lt;STRONG style="font-size: 14px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;"&gt;ilp64&lt;/STRONG&gt;&lt;SPAN&gt;.so )&lt;/SPAN&gt; without using compiler option -DMKL_ILP64. Please check the MKL Linker adviser recommendation.&lt;/P&gt;
&lt;P&gt;You might try to relink against &lt;SPAN&gt;libmkl_intel_&lt;/SPAN&gt;&lt;STRONG style="font-size: 14px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;"&gt;lp64.so &lt;/STRONG&gt;without modification you code and check how is will go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 07:14:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Segmentation-fault-in-LAPACKE-dgesv-for-large-matrices/m-p/1587977#M36010</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2024-04-10T07:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Segmentation fault in LAPACKE_dgesv for large matrices</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Segmentation-fault-in-LAPACKE-dgesv-for-large-matrices/m-p/1587993#M36011</link>
      <description>&lt;P&gt;Very thanks! The problem is solved after I link my program to libmkl_intel_lp64.so.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 07:51:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Segmentation-fault-in-LAPACKE-dgesv-for-large-matrices/m-p/1587993#M36011</guid>
      <dc:creator>szp</dc:creator>
      <dc:date>2024-04-10T07:51:44Z</dc:date>
    </item>
  </channel>
</rss>

