<?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 MKL 2021 and MKL 2018 call cluster_sparse_solver() and the calculation results are different？ in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1311429#M31959</link>
    <description>&lt;H5&gt;When calling cluster_sparse_solver() to solve the complex matrix equation, I found that the calculation results of MKL-2018 and MKL-2021 are different?&lt;/H5&gt;
&lt;H5&gt;&lt;STRONG&gt;&lt;EM&gt;my link is:&lt;/EM&gt;&lt;/STRONG&gt;&lt;/H5&gt;
&lt;P&gt;lmkl_scalapack_lp64 -Wl,--no-as-needed -lmkl_cdft_core -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lmkl_blacs_intelmpi_lp64 -liomp5 -lpthread -lm -ldl&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;My run command is：&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;mpiexec -np 2 ./mpi_test&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Attach my code and data.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;A0.txt b0.txt is the data of rank0,A1.txt b1.txt is the data of rank1.&lt;/P&gt;
&lt;P&gt;x2018*txt is the calculation result of MKL2018,x2021* is the calculation result of MKL2021.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;mycode:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;fstream&amp;gt;
#include &amp;lt;complex&amp;gt;
#include &amp;lt;vector&amp;gt;

#include "Eigen/Sparse"
#include "Eigen/SparseCore"

#include "mpi.h"
#include "mkl_pardiso.h"
#include "mkl_cluster_sparse_solver.h"

int main() {
    MPI_Init(nullptr, nullptr);

    std::string file_A("A");
    std::string file_b("b");
    std::string file_x("x2021");

    using Complex = std::complex&amp;lt;double&amp;gt;;

    std::vector&amp;lt;Complex&amp;gt; b;

    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &amp;amp;rank);

    file_A = file_A+std::to_string(rank)+".txt";
    file_b = file_b+std::to_string(rank)+".txt";
    file_x = file_x+std::to_string(rank)+".txt";

    std::vector&amp;lt;Eigen::Triplet&amp;lt;Complex&amp;gt;&amp;gt; tripletList;
    std::FILE *file = std::fopen(file_A.c_str(), "r");
    if (!file)
    {
        printf("can't open file %s\n", file_A.c_str());
        exit(1);
    }
    int glbRows, glbCols, lclRows, rowstart, rowEnd, nonzero;
    std::fscanf(file, " %d, %d , %d , %d , %d , %d\n", &amp;amp;glbRows, &amp;amp;glbCols, &amp;amp;lclRows, &amp;amp;rowstart, &amp;amp;rowEnd, &amp;amp;nonzero);

    Eigen::SparseMatrix&amp;lt;Complex, Eigen::RowMajor&amp;gt; matrix;
    matrix.resize(lclRows, glbCols);
    tripletList.reserve(nonzero);
    int row, col;
    double real, imag;
    int num = 0;
    while (std::fscanf(file, "[ %d ] , [ %d ] = (%lf, %lf)\n", &amp;amp;row, &amp;amp;col, &amp;amp;real, &amp;amp;imag) != EOF)
    {
        tripletList.push_back(Eigen::Triplet&amp;lt;Complex&amp;gt;(row, col, Complex(real, imag)));
    }
    matrix.setFromTriplets(tripletList.begin(), tripletList.end());
    matrix.makeCompressed();
    std::fclose(file);

    file = std::fopen(file_b.c_str(), "r");
    if (!file)
    {
        printf("can't open file %s\n", file_b.c_str());
        exit(1);
    }
    std::fscanf(file, " %d , %d , %d , %d\n", &amp;amp;glbRows, &amp;amp;lclRows, &amp;amp;rowstart, &amp;amp;rowEnd);
    b.reserve(lclRows);


    while (std::fscanf(file, "[%d] (%lf, %lf)\n", &amp;amp;row, &amp;amp;real, &amp;amp;imag) != EOF)
    {
        b.push_back(Complex(real, imag));
    }

    void *pt_[64] = {nullptr};  // Internal solver memory pointer
    MKL_INT iparm_[64] = {0};   // Pardiso control parameters
    int mtype = 6;
    pardisoinit(pt_, &amp;amp;mtype, iparm_);

    iparm_[ 1] =  3;
    iparm_[ 7] =  3; // Max number of iterative refinement steps
    iparm_[ 9] =  8; // Perturb the pivot elements with 1E-13
    iparm_[34] =  1; // PARDISO use C-style indexing for ia and ja arrays
    iparm_[39] =  2; // Input: matrix/rhs/solution are distributed between MPI processes
    iparm_[40] = rowstart;
    iparm_[41] = rowEnd;

    Eigen::VectorXcd x(lclRows);

    int one = 1;
    int phase = 13;
    int error;
    int comm = MPI_COMM_WORLD;
    cluster_sparse_solver(pt_, &amp;amp;one, &amp;amp;one, &amp;amp;mtype, &amp;amp;phase, &amp;amp;glbRows, matrix.valuePtr(), matrix.outerIndexPtr(), matrix.innerIndexPtr(),
                          nullptr, &amp;amp;one, iparm_, &amp;amp;one, b.data(), x.data(), &amp;amp;comm, &amp;amp;error);

    if (rank == 0) {
        std::cout &amp;lt;&amp;lt; "# of iterative refinement steps: " &amp;lt;&amp;lt; iparm_[6] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "# of perturbed pivots: " &amp;lt;&amp;lt; iparm_[13] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "peak memory on symbolic factorization: " &amp;lt;&amp;lt; iparm_[14] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "permanent memory on symbolic factorization: " &amp;lt;&amp;lt; iparm_[15] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "size of memory on numerical factorization and solution: " &amp;lt;&amp;lt; iparm_[16] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "# of non-zeros elements in the factors: " &amp;lt;&amp;lt; iparm_[17] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "# of floating point operations: " &amp;lt;&amp;lt; iparm_[18] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "error = " &amp;lt;&amp;lt; error &amp;lt;&amp;lt; std::endl;
    }

    std::ofstream xout(file_x);
    xout &amp;lt;&amp;lt; x;

    MPI_Finalize();
}&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 01 Sep 2021 12:37:04 GMT</pubDate>
    <dc:creator>miao0109</dc:creator>
    <dc:date>2021-09-01T12:37:04Z</dc:date>
    <item>
      <title>MKL 2021 and MKL 2018 call cluster_sparse_solver() and the calculation results are different？</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1311429#M31959</link>
      <description>&lt;H5&gt;When calling cluster_sparse_solver() to solve the complex matrix equation, I found that the calculation results of MKL-2018 and MKL-2021 are different?&lt;/H5&gt;
&lt;H5&gt;&lt;STRONG&gt;&lt;EM&gt;my link is:&lt;/EM&gt;&lt;/STRONG&gt;&lt;/H5&gt;
&lt;P&gt;lmkl_scalapack_lp64 -Wl,--no-as-needed -lmkl_cdft_core -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lmkl_blacs_intelmpi_lp64 -liomp5 -lpthread -lm -ldl&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;My run command is：&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;mpiexec -np 2 ./mpi_test&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Attach my code and data.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;A0.txt b0.txt is the data of rank0,A1.txt b1.txt is the data of rank1.&lt;/P&gt;
&lt;P&gt;x2018*txt is the calculation result of MKL2018,x2021* is the calculation result of MKL2021.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;mycode:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;fstream&amp;gt;
#include &amp;lt;complex&amp;gt;
#include &amp;lt;vector&amp;gt;

#include "Eigen/Sparse"
#include "Eigen/SparseCore"

#include "mpi.h"
#include "mkl_pardiso.h"
#include "mkl_cluster_sparse_solver.h"

int main() {
    MPI_Init(nullptr, nullptr);

    std::string file_A("A");
    std::string file_b("b");
    std::string file_x("x2021");

    using Complex = std::complex&amp;lt;double&amp;gt;;

    std::vector&amp;lt;Complex&amp;gt; b;

    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &amp;amp;rank);

    file_A = file_A+std::to_string(rank)+".txt";
    file_b = file_b+std::to_string(rank)+".txt";
    file_x = file_x+std::to_string(rank)+".txt";

    std::vector&amp;lt;Eigen::Triplet&amp;lt;Complex&amp;gt;&amp;gt; tripletList;
    std::FILE *file = std::fopen(file_A.c_str(), "r");
    if (!file)
    {
        printf("can't open file %s\n", file_A.c_str());
        exit(1);
    }
    int glbRows, glbCols, lclRows, rowstart, rowEnd, nonzero;
    std::fscanf(file, " %d, %d , %d , %d , %d , %d\n", &amp;amp;glbRows, &amp;amp;glbCols, &amp;amp;lclRows, &amp;amp;rowstart, &amp;amp;rowEnd, &amp;amp;nonzero);

    Eigen::SparseMatrix&amp;lt;Complex, Eigen::RowMajor&amp;gt; matrix;
    matrix.resize(lclRows, glbCols);
    tripletList.reserve(nonzero);
    int row, col;
    double real, imag;
    int num = 0;
    while (std::fscanf(file, "[ %d ] , [ %d ] = (%lf, %lf)\n", &amp;amp;row, &amp;amp;col, &amp;amp;real, &amp;amp;imag) != EOF)
    {
        tripletList.push_back(Eigen::Triplet&amp;lt;Complex&amp;gt;(row, col, Complex(real, imag)));
    }
    matrix.setFromTriplets(tripletList.begin(), tripletList.end());
    matrix.makeCompressed();
    std::fclose(file);

    file = std::fopen(file_b.c_str(), "r");
    if (!file)
    {
        printf("can't open file %s\n", file_b.c_str());
        exit(1);
    }
    std::fscanf(file, " %d , %d , %d , %d\n", &amp;amp;glbRows, &amp;amp;lclRows, &amp;amp;rowstart, &amp;amp;rowEnd);
    b.reserve(lclRows);


    while (std::fscanf(file, "[%d] (%lf, %lf)\n", &amp;amp;row, &amp;amp;real, &amp;amp;imag) != EOF)
    {
        b.push_back(Complex(real, imag));
    }

    void *pt_[64] = {nullptr};  // Internal solver memory pointer
    MKL_INT iparm_[64] = {0};   // Pardiso control parameters
    int mtype = 6;
    pardisoinit(pt_, &amp;amp;mtype, iparm_);

    iparm_[ 1] =  3;
    iparm_[ 7] =  3; // Max number of iterative refinement steps
    iparm_[ 9] =  8; // Perturb the pivot elements with 1E-13
    iparm_[34] =  1; // PARDISO use C-style indexing for ia and ja arrays
    iparm_[39] =  2; // Input: matrix/rhs/solution are distributed between MPI processes
    iparm_[40] = rowstart;
    iparm_[41] = rowEnd;

    Eigen::VectorXcd x(lclRows);

    int one = 1;
    int phase = 13;
    int error;
    int comm = MPI_COMM_WORLD;
    cluster_sparse_solver(pt_, &amp;amp;one, &amp;amp;one, &amp;amp;mtype, &amp;amp;phase, &amp;amp;glbRows, matrix.valuePtr(), matrix.outerIndexPtr(), matrix.innerIndexPtr(),
                          nullptr, &amp;amp;one, iparm_, &amp;amp;one, b.data(), x.data(), &amp;amp;comm, &amp;amp;error);

    if (rank == 0) {
        std::cout &amp;lt;&amp;lt; "# of iterative refinement steps: " &amp;lt;&amp;lt; iparm_[6] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "# of perturbed pivots: " &amp;lt;&amp;lt; iparm_[13] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "peak memory on symbolic factorization: " &amp;lt;&amp;lt; iparm_[14] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "permanent memory on symbolic factorization: " &amp;lt;&amp;lt; iparm_[15] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "size of memory on numerical factorization and solution: " &amp;lt;&amp;lt; iparm_[16] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "# of non-zeros elements in the factors: " &amp;lt;&amp;lt; iparm_[17] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "# of floating point operations: " &amp;lt;&amp;lt; iparm_[18] &amp;lt;&amp;lt; '\n';
        std::cout &amp;lt;&amp;lt; "error = " &amp;lt;&amp;lt; error &amp;lt;&amp;lt; std::endl;
    }

    std::ofstream xout(file_x);
    xout &amp;lt;&amp;lt; x;

    MPI_Finalize();
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:37:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1311429#M31959</guid>
      <dc:creator>miao0109</dc:creator>
      <dc:date>2021-09-01T12:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: MKL 2021 and MKL 2018 call cluster_sparse_solver() and the calculation results are different？</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1311446#M31960</link>
      <description>&lt;P&gt;I didn't check, but do you expect to see identical results?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 13:57:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1311446#M31960</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2021-09-01T13:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: MKL 2021 and MKL 2018 call cluster_sparse_solver() and the calculation results are different？</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1311579#M31962</link>
      <description>&lt;P&gt;It should be roughly the same, but the calculation result of MKL2021 is completely different. I think it should be a bug.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 22:44:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1311579#M31962</guid>
      <dc:creator>miao0109</dc:creator>
      <dc:date>2021-09-01T22:44:57Z</dc:date>
    </item>
    <item>
      <title>Re:MKL 2021 and MKL 2018 call cluster_sparse_solver() and the calculation results are different？</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1311627#M31965</link>
      <description>&lt;P&gt;yes, I confirmed the problem You reported. We will investigate the cause of the issue.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Sep 2021 03:48:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1311627#M31965</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2021-09-02T03:48:55Z</dc:date>
    </item>
    <item>
      <title>Re:MKL 2021 and MKL 2018 call cluster_sparse_solver() and the calculation results are different？</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1312591#M32003</link>
      <description>&lt;P&gt;As a temporary workaround, please set iparm_[12] = 1 and the results would be as expected. &lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Sep 2021 04:11:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-2021-and-MKL-2018-call-cluster-sparse-solver-and-the/m-p/1312591#M32003</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2021-09-07T04:11:07Z</dc:date>
    </item>
  </channel>
</rss>

