4 );std::vector Triplet double triplets; // 初始化非零元素 int r[

时间:2022-06-27 07:33:11

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 ([email protected]) 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})