Windows安装Metis(metis.dll缺失)

解决问题

​ Python中使用metis进行图划分时,会遇到缺失METIS.dll文件的问题,如下:

RuntimeError: Could not locate METIS dll. Please set the METIS_DLL environment variable to its full path.

​ 网上直接下载的dll文件也无法加载,因此只好手动编译一下。

准备工具

visual studio

VS官网

​ 使用2022 社区版就行,安装的时候选择“通用windows平台开发”,把"C++"相关的记得勾上。

cmake

CMake官网
请添加图片描述

​ 下载最新版的CMake 3.23.2以便能支持新版vs,实际上只要cmake和vs版本能对应上就行,对应关系见下文

​ 记得安装过程中,勾选给用户或所有人添加环境变量,否则还需要去手动设置一下。

Metis

Metis下载

​ 下载最新版5.1.0就行,但metis网上很多教程都是用的修改版,而且还要改注册表、改文件很麻烦,其实我用官方版本也能编译通过,不知道为什么要用修改后的文件。

​ 我是Windows 11 专业工作站版实测可以,如果其他环境有问题,就去看参考文献里,使用修改版的文件吧。

Graphviz(可选)

下载地址

​ 这是networkx画图所需要的包,若不需要使用networkx,则忽略。

​ 由于在线安装的总是遇到问题,因此手动下载与Python对应的版本,例如我使用Python3.7,这里选择“cp37”的版本下载,以此类推。
在这里插入图片描述
​ 下载完成后,在cmd命令行输入指令进行安装:

pip install pygraphviz-1.6-cp37-cp37m-win_amd64.whl

测试代码

#参考至官方文档进行修改
import networkx as nx
import metis
from networkx.drawing.nx_agraph import write_dot


def example_networkx():
    G = nx.Graph()
    nx.add_star(G,[0,1,2,3,4])
    nx.add_path(G,[4,5,6,7,8])
    nx.add_star(G,[8,9,10,11,12])
    nx.add_path(G,[6,13,14,15])
    nx.add_star(G,[15,16,17,18])
    return G

def example_metis():
    G = example_networkx()
    (edgecuts, parts) = metis.part_graph(G, 3)
    colors = ['red', 'blue', 'green']
    for i, p in enumerate(parts):
        G.nodes[i]['color'] = colors[p]
    write_dot(G, 'example.dot')  # Requires pydot or graphviz


example_metis()

安装步骤

检查CMake是否支持对应VS版本

  1. 启动cmd,输入cmake --help,可以看到如下打印
    在这里插入图片描述

  2. 找到打印中的“Generators”字段
    在这里插入图片描述

    ​ 可以看到我这里的cmake支持vs2008到vs2022的版本,若没有对应vs版本,一般是vs版本太高或者cmake版本太低,自行修改一下。

    ​ 复制对应版本的名称,例如我使用的2022版,复制“Visual Studio 17 2022”。

生成metis工程

  1. 进入metis-5.1.0文件夹

    安装完成各种软件后,解压Metis 5.1.0压缩包,进入解压后的文件夹,在空白地方单击鼠标右键,选择在终端中打开。

    或者在CMD中进入到当前文件夹也是一样的。

  2. 修改生成库类型

    默认会生成静态库metis.lib,但我需要的是动态库metis.dll,因此需要打开metis-5.1.0目录下的CMakeLists.txt文件修改成如下:

    在这里插入图片描述

    添加的相关指令为:

    #设置为动态库
    set(SHARED 1)
    
    ......
    
    #打印
    MESSAGE( STATUS "METIS_LIBRARY_TYPE is = ${METIS_LIBRARY_TYPE}.")
    

    若设置成功,在下一步[生成VS Solution](#生成VS Solution)时,可以看到打印:

    在这里插入图片描述

  3. 生成VS Solution

    cmd中输入,引号内的内容替换为你自己的版本:

    .\vsgen -G "Visual Studio 17 2022"
    

    等待脚本执行完成,出现如下打印:

    在这里插入图片描述

    solution生成在build\windows目录下。

编译生成metis.dll

  1. 编译
    使用vs打开METIS.sln后,点击本地windows调试器编译就行。

    在这里插入图片描述

  2. 编译时遇到rint报错
    在这里插入图片描述

    发现应该是重定义了,直接去gk_arch.h中注释掉就行,如下:
    在这里插入图片描述

  3. 重新编译

    这一步会报错但不影响生成metis.dll,因此可以忽略,如下:
    在这里插入图片描述

    实测生成静态库时不会报错,如下:
    在这里插入图片描述

    我们需要的metis.dll位于libmetis\Release目录下,大功告成。
    在这里插入图片描述

动态库注册

  1. 拷贝文件

    • Windows 95/98/Me系统,将dll复制到C:\Windows\System目录下。

    • Windows NT/2000系统,将dll复制到C:\WINNT\System32目录下。

    • Windows XP/WIN7/10/11系统,将dll复制到C:\Windows\System32目录下。

  2. 注册动态库

    在cmd中执行以下命令即可:

    regsvr32 %windir%\system32\dll /s
    

其他

测试结果

  1. 跑完测试代码后,会在文件目录下一个example.dot文件,保存图划分的信息。

在这里插入图片描述

  1. 命令行中输入dot -Tpng example.dot -o tree.png将dot文件转化成图片表示。

    在这里插入图片描述

:测试需要安装pygraphviz[安装步骤],其实只要不报缺少metis.dll的错,即成功

官方Windows编译文档

Building METIS requires CMake 2.8, found at
http://www.cmake.org/. CMake generates Visual Studio project files,
which then can be built using Visual Studio. There are two ways to
generate visual studio files: using the command line and using the
CMake GUI.

Using the command line

Open the command prompt and cd to the METIS source directory. Run

> cmake --help

and look at the list of generators for the Visual Studio studio you
want to build for. For example, the generator for Visual Studio 2010
is called “Visual Studio 10”.

After you have found the appropriate generator, run

> .\vsgen -G "<GENERATOR>"

to generate the project files. The project files will be placed
build\windows.

Using the CMake GUI

It is also possible to use the CMake GUI, distributed with CMake. To
do this, open the CMake GUI, and browse to the location of METIS’
source with the “Browse Source” button. You can also change the binary
directory. This is where the Visual Studio project files will be
placed. Click “Generate” to select the correct visual studio version
and build the project files.

Using the VS project files

The Visual Studio project will be called METIS.sln. Open it in Visual
Studio. If the configuration is not already “Release”, set it to
“Release”. Type F7 to build. The METIS library will be in
<BINARY_DIR>\libmetis\Release and the executable programs will be in
<BINARY_DIR>\programs\Release. (<BINARY_DIR> will be build\windows if
you used the command line or whatever you choose if using the CMake
GUI.)

参考文献

Metis 5.1.0 安裝心得 in Win10:https://zhuanlan.zhihu.com/p/94100796

Window下python安装metis:https://blog.csdn.net/weixin_45683241/article/details/120779412

METIS for Python 0.1 documentation:https://metis.readthedocs.io/en/latest/#installation

  • 20
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
metis-5.1.0安装包和manual手册 2 What is new in version 5.0 4 2.1 Changes in the command-line programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1.1 Migration issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2 Changes in the API routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2.1 Migration issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3 Overview of METIS 6 3.1 Partitioning a graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 Alternate partitioning objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.3 Support for multi-phase and multi-physics computations . . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 Partitioning a mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.5 Partitioning for heterogeneous parallel computing architectures . . . . . . . . . . . . . . . . . . . . . 8 3.6 Computing a fill-reducing ordering of a sparse matrix . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.7 Converting a mesh into a graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4 METIS’ stand-alone programs 9 4.1 Input file formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.1.1 Graph file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.1.2 Mesh file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.1.3 Target partition weights file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.2 Output file formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.2.1 Partition file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值