Win10 VS2013 suitesparse-metis-for-windows 1.3.1
Posted FlyingGod
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Win10 VS2013 suitesparse-metis-for-windows 1.3.1相关的知识,希望对你有一定的参考价值。
suitesparse-metis-for-windows 1.3.1 安装包内附SuiteSparse 4.5.1, Metis 5.1.0和 lapack 3.4.1
Github上面由整理好的suitesparse包适合在Windows安装 https://github.com/jlblancoc/suitesparse-metis-for-windows,并附有详细的安装指导,但是会有一点bug
问题1:metis/GKlib/gk_arch.h
中有个bug,从C++11开始标准库中已经支持rint函数了,VS 2013开始支持这一函数,修复方式
#ifdef __MSC__ /* MSC does not have rint() function */ #if (_MSC_VER < 1800) /*visual studio 2013编译器版本*/ #define rint(x) ((int)((x)+0.5)) #endif /* MSC does not have INFINITY defined */ #ifndef INFINITY #define INFINITY FLT_MAX #endif #endif #endif
安装后测试方式
1.在环境变量中设置SuiteSparse_DIR位置是SuiteSoarse的安装位置,例如C:\\Program Files (x86)\\Suitesparse
2.测试程序
#include <iostream> #include "Eigen/Eigen" #include "Eigen/SPQRSupport" using namespace Eigen; int main() { SparseMatrix < double > A(4, 4); std::vector < Triplet < double > > triplets; // 初始化非零元素 int r[3] = { 0, 1, 2 }; int c[3] = { 1, 2, 2 }; double val[3] = { 6.1, 7.2, 8.3 }; for (int i = 0; i < 3; ++i) triplets.push_back(Triplet < double >(r[i], c[i], val[i])); // 初始化稀疏矩阵 A.setFromTriplets(triplets.begin(), triplets.end()); std::cout << "A = \\n" << A << std::endl; // 一个QR分解的实例 SPQR < SparseMatrix < double > > qr; // 计算分解 qr.compute(A); // 求一个A x = b Vector4d b(1, 2, 3, 4); Vector4d x = qr.solve(b); std::cout << "x = \\n" << x; std::cout << "A x = \\n" << A * x; getchar(); return 0; }
2.相同文件夹下的CMakeLists.txt
# ----------------------------------------------- # Test CMake script for building against SuiteSparse # http://code.google.com/p/suitesparse-metis-for-windows/ # Created by Jose Luis Blanco (University of Almeria) 2013 # Updated by jesnault (jerome.esnault@inria.fr) 2014-01-21 # ----------------------------------------------- PROJECT(CholmodExample) cmake_minimum_required(VERSION 2.8) # ------------------------------------------------------------------ # Detect SuiteSparse libraries: # If not found automatically, set SuiteSparse_DIR in CMake to the # directory where SuiteSparse was built. # ------------------------------------------------------------------ LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmakemodule/") # Add the directory where FindSuiteSparse.cmake module can be found. set(SuiteSparse_USE_LAPACK_BLAS ON) find_package(SuiteSparse QUIET NO_MODULE) # 1st: Try to locate the *config.cmake file. if(NOT SuiteSparse_FOUND) #set(SuiteSparse_VERBOSE ON) find_package(SuiteSparse REQUIRED) # 2nd: Use FindSuiteSparse.cmake module include_directories(${SuiteSparse_INCLUDE_DIRS}) else() message(STATUS "Find SuiteSparse : include(${USE_SuiteSparse})") include(${USE_SuiteSparse}) endif() MESSAGE(STATUS "SuiteSparse_LIBS: ${SuiteSparse_LIBRARIES}") # ------------------------------------------------------------------ # End of SuiteSparse detection # ------------------------------------------------------------------ # ------------------------------------------------------------------ # Declare an example program: # ------------------------------------------------------------------ ADD_EXECUTABLE(cholmod-test cholmod-test.c) TARGET_LINK_LIBRARIES(cholmod-test ${SuiteSparse_LIBRARIES})
3.命名文件夹src,并将上面两个文件放进去,并创建build文件夹,利用cmake的configure和generate Visual Studio2013工程文件,直接生成就可以(根据自己的FindSuiteSparse.cmake文件的位置设置CMakeLists.txt中变量CMAKE_MODULE_PATH的位置)即可
4.如果不使用cmake工具,记得在VS的工程属性中设置lapack和suitesparse库的安装位置,链接如下库即可
C:\\Program Files (x86)\\Suitesparse\\lib64\\metisd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\suitesparseconfigd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libamdd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libbtfd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libcamdd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libccolamdd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libcolamdd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libcholmodd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libcxsparsed.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libklud.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libldld.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libumfpackd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\libspqrd.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\lapack_blas_windows\\libblas.lib
C:\\Program Files (x86)\\Suitesparse\\lib\\lapack_blas_windows\\liblapack.lib
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
#输出结果如下
b
以上是关于Win10 VS2013 suitesparse-metis-for-windows 1.3.1的主要内容,如果未能解决你的问题,请参考以下文章