当我使用eigen :: pardisolu与cmake时发生例外

发布于 2025-01-22 21:15:49 字数 3156 浏览 1 评论 0原文

我正在尝试使用eigen :: pardisolu,但我没有输出。 这是我的cmakelists.txt:

cmake_minimum_required(VERSION 3.9)
project(my_test_project)
aux_source_directory(. SRCS)

add_definitions(-DEIGEN_USE_MKL_ALL)
add_definitions(-DMKL_LP64)

add_executable(my_test ${SRCS})
target_include_directories(my_test 
    PRIVATE
    "./eigen/eigen-3.4.0"
    "C:/Program Files (x86)/Intel/oneAPI/mkl/2022.0.3/include"
    "./")

file(GLOB LIBS "C:/Program Files (x86)/Intel/oneAPI/mkl/2022.0.3/lib/intel64/*.lib")

target_link_libraries(my_test ${LIBS})

在cmake文件中,我添加了我需要的Include Directories和Libs。该路径是相关的。 这是我的测试功能:

#include <Eigen/Dense>
#include <iostream>
#include <Eigen/Sparse>
#include <Eigen/PardisoSupport>

using namespace Eigen;
using namespace std;
void sparseTest()
{
    int cols = 3;
    int rows = 3;
    unsigned int nonzeros_num = 3;
    vector<Triplet<double>> tripletList;
    tripletList.reserve(nonzeros_num);

    SparseMatrix<double> b(rows, 1);

    for (int i = 0; i < nonzeros_num; i++)
    {
        tripletList.push_back(Triplet<double>(i, i, i + 1));
        b.insert(i, 0) = i + 1;
    }
    SparseMatrix<double> mat(rows, cols);
    mat.setFromTriplets(tripletList.begin(), tripletList.end());
    mat.makeCompressed();
    b.makeCompressed();
    cout << mat << endl;
    cout << b << endl;
   
    PardisoLU<SparseMatrix<double>> solver;
    //SparseLU<SparseMatrix<double>> solver;
    solver.compute(mat);

    SparseMatrix<double> result(3, 1);
    result = solver.solve(b);

    cout << result << endl;
}

当我进行此项目时。在“ pardisosupport.h”中发生了一个例外,说“找不到模块” 我已经将所有.lib添加到我的项目中,所以为什么发生例外?
然后我以这种方式尝试:我已经修改了我的cmakelists.txt:

cmake_minimum_required(VERSION 3.9)
project(my_test_project)
aux_source_directory(. SRCS)

#add_definitions(-DEIGEN_USE_MKL_ALL)
#add_definitions(-DMKL_LP64)

add_executable(my_test ${SRCS})
target_include_directories(my_test 
    PRIVATE
    "./eigen/eigen-3.4.0"
    "C:/Program Files (x86)/Intel/oneAPI/mkl/2022.0.3/include"
    "./")
file(GLOB REQUIRES_LIBS "D:/VSCodeData/LU/lib/*.lib")
target_link_libraries(my_test  ${REQUIRES_LIBS} )

不用链接所有libs文件,而只是将这些libs复制到链接目录并链接它们的库中: mkl_intel_lp64.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib
然后,我使用Visual Studio来制作它,并且会出现“找不到libiomp5md.dll”的错误,因此我在“ C:\ Program Files(x86)\ Intel \ oneapi \ compiler \ compiler \ compiler \ compiler \中找到此.dll文件。 2022.0.3 \ Windows \ redist \ intel64_win \ Compiler“并将其复制到我的.EXE目录。在所有这些步骤之后,它终于效果很好。
因此,我认为我无法将MKL安装目录中的所有LIB链接起来。现在,我的新问题是我在项目中需要的.lib和.dll文件以及如何知道。我已经在目标中链接了libiomp5md.lib,但是为什么我还需要libiomp5md.dll? 此文件中还有其他.dll库:
C:\ Program Files(X86)\ Intel \ Oneapi \ Compiler \ 2022.0.3 \ Windows \ redist \ intel64_win \ Compiler
这些.dll如何使用?
这是我在调试模式下的输出:
非零条目: (1,0)(2,1)(3,2)

外部指针: 0 1 2 $

1 0 0
0 2 0
0 0 3

非零条目: (1,0)(2,1)(3,2)

外部指针: 0 $

1
2
3

非零条目: (1,0)(1,1)(1,2)

外部指针: 0 $

1
1
1
它表明它运行良好。

I am trying to use Eigen::pardisoLU but I have no output.
This is my cmakelists.txt:

cmake_minimum_required(VERSION 3.9)
project(my_test_project)
aux_source_directory(. SRCS)

add_definitions(-DEIGEN_USE_MKL_ALL)
add_definitions(-DMKL_LP64)

add_executable(my_test ${SRCS})
target_include_directories(my_test 
    PRIVATE
    "./eigen/eigen-3.4.0"
    "C:/Program Files (x86)/Intel/oneAPI/mkl/2022.0.3/include"
    "./")

file(GLOB LIBS "C:/Program Files (x86)/Intel/oneAPI/mkl/2022.0.3/lib/intel64/*.lib")

target_link_libraries(my_test ${LIBS})

In cmake file I have add the include directories and libs I need. The path is corrrect.
This is my test function:

#include <Eigen/Dense>
#include <iostream>
#include <Eigen/Sparse>
#include <Eigen/PardisoSupport>

using namespace Eigen;
using namespace std;
void sparseTest()
{
    int cols = 3;
    int rows = 3;
    unsigned int nonzeros_num = 3;
    vector<Triplet<double>> tripletList;
    tripletList.reserve(nonzeros_num);

    SparseMatrix<double> b(rows, 1);

    for (int i = 0; i < nonzeros_num; i++)
    {
        tripletList.push_back(Triplet<double>(i, i, i + 1));
        b.insert(i, 0) = i + 1;
    }
    SparseMatrix<double> mat(rows, cols);
    mat.setFromTriplets(tripletList.begin(), tripletList.end());
    mat.makeCompressed();
    b.makeCompressed();
    cout << mat << endl;
    cout << b << endl;
   
    PardisoLU<SparseMatrix<double>> solver;
    //SparseLU<SparseMatrix<double>> solver;
    solver.compute(mat);

    SparseMatrix<double> result(3, 1);
    result = solver.solve(b);

    cout << result << endl;
}

When I make this project. An exception occurred in the "PardisoSupport.h" saying "module not found"
I have add all .lib to my project, so why the exception occurred?
Then I try in this way: I have modified my cmakelists.txt like this:

cmake_minimum_required(VERSION 3.9)
project(my_test_project)
aux_source_directory(. SRCS)

#add_definitions(-DEIGEN_USE_MKL_ALL)
#add_definitions(-DMKL_LP64)

add_executable(my_test ${SRCS})
target_include_directories(my_test 
    PRIVATE
    "./eigen/eigen-3.4.0"
    "C:/Program Files (x86)/Intel/oneAPI/mkl/2022.0.3/include"
    "./")
file(GLOB REQUIRES_LIBS "D:/VSCodeData/LU/lib/*.lib")
target_link_libraries(my_test  ${REQUIRES_LIBS} )

Instead of linking all libs files, I just copy these libs to my libraries linking directory and link them:
mkl_intel_lp64.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib
Then I use visual studio to make it, and There will be a error that "can not find libiomp5md.dll ", so I find this .dll file in the "C:\Program Files (x86)\Intel\oneAPI\compiler\2022.0.3\windows\redist\intel64_win\compiler" and copy it to my .exe directory. After all these steps it works well finally.
So I think I can not link all libs in the mkl install directories. Now my new question is what .lib and .dll files I need in my project and how to know it. I have linked libiomp5md.lib in my target but why I also need the libiomp5md.dll?
There are other .dll libraries in this file:
C:\Program Files (x86)\Intel\oneAPI\compiler\2022.0.3\windows\redist\intel64_win\compiler
how these .dll can be used?
This is my output in debug mode:
Nonzero entries:
(1,0) (2,1) (3,2)

Outer pointers:
0 1 2 $

1 0 0
0 2 0
0 0 3

Nonzero entries:
(1,0) (2,1) (3,2)

Outer pointers:
0 $

1
2
3

Nonzero entries:
(1,0) (1,1) (1,2)

Outer pointers:
0 $

1
1
1
It indicated it works well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生一个溪 2025-01-29 21:15:49

对于正在研究这个问题的任何人来说,这是讨论的摘要:

我在项目中需要的.lib和.dll文件以及如何知道。

要找到使用MKL功能的应用程序所需的库,可以始终从MKL Link Line Advisor工具中获得帮助,这是链接 https://www.intel.com/contel.com/content/content/content/www/us/en/en /developer/tools/oneapi/onemkl-link-link-line-advisor.html#gs.ypos1l

我如何修改CPU内核的数量。我可以更改它或多或少使用CPU内核

默认情况下,英特尔MKL使用与系统上物理内核数量等于物理内核的线程数,是的,您可以控制的数量通过更改mkl_num_threads或OMP_NUM_THREADS环境变量的核心。此链接可能可以帮助您找到完整的详细信息
https://www.intel.com/content./content/content/wwww/www/www/us/en/en/en/develop/develoption/developation/onemkl------ Windows-Developer指导/TOP/TOP/MANAKING-PROVINAME-和MEMORY/REMATING-PROMFORMANCE-WITH-THEREDING/TECHICERES TO-SET-SET-the-number-of-theReads.html

To anyone who is looking into this question, here is the summary of the discussion:

what .lib and .dll files I need in my project and how to know it.

To find the required libraries for your application in which you are using MKL functionalities, one can always take help from the MKL link line advisor tool, here is the link https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html#gs.ypos1l

how can I modify the number of CPU's cores..Can I change it that use more or less CPU cores

By default, Intel MKL uses the number of threads equal to the number of physical cores on the system and yes you can control the number of cores by changing the value of MKL_NUM_THREADS or OMP_NUM_THREADS environment variables. This link probably helps you to find full details
https://www.intel.com/content/www/us/en/develop/documentation/onemkl-windows-developer-guide/top/managing-performance-and-memory/improving-performance-with-threading/techniques-to-set-the-number-of-threads.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文