文章目录

  • Metis
    • 安装
    • 示例
    • 相关接口函数
  • Parmetis
    • 安装
  • pymetis
    • 例子
    • part_graph

Metis

安装

官方文档
方法一:Metis从安装到使用全教程(Linux): 这个里面有使用介绍,但是安装后,可以按照教程例子测试了。如果需要在程序中调用,好像不好使,可能是需要配置环境变量啥的。

方法二:ubuntu安装metis: 简单暴力,好用,适合需要在代码中调用的需求。

sudo apt-get install libmetis-dev

安装完,仍然需要做如下配置:
include/metis.h 中修改以下代码,做到与自己计算机位数匹配(32bit or 64 bit).
不知道位置的可以按如下查询:

whereis metis # 查找命令
metis: /usr/include/metis.h
sudo vim /usr/include/metis.h
//if your system is 64 bit.
#define IDXTYPEWIDTH 64 //if your system is 32 bit
#define IDXTYPEWIDTH 32

示例

图划分软件Metis的使用
数据集

7 11
5 3 2
1 3 4
5 4 2 1
2 3 6 7
1 3 6
5 4 7
6 4
7 11 001
5 1 3 2 2 1
1 1 3 2 4 1
5 3 4 2 2 2 1 2
2 1 3 2 6 2 7 5
1 1 3 3 6 2
5 2 4 2 7 6
6 6 4 5

注意上面的提供的代码是邻接表格式的,第一行表示顶点和表的边的数量(7,11),后面每行表示行号对应的顶点的邻居点及边权,例如,第二行表示第一个顶点的三条边: 1->(5,1),1->(3,2), 1->(2,1)。
然而Metis接收的数据格式是CSR,相关介绍见:稀疏矩阵存储格式总结+存储效率对比:COO,CSR,DIA,ELL,HYB. 下面的示例代码中完成了格式的转换。

代码:

#include <metis.h>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>using namespace std;vector<idx_t> func(vector<idx_t> &xadj, vector<idx_t> &adjncy, vector<idx_t> &adjwgt, decltype(METIS_PartGraphKway) *METIS_PartGraphFunc) {idx_t nVertices = xadj.size() - 1; // 节点数idx_t nEdges = adjncy.size() / 2;  // 边数idx_t nWeights = 1;                // 节点权重维数idx_t nParts = 2;                  // 子图个数≥2idx_t objval;                      // 目标函数值vector<idx_t> part(nVertices, 0);  // 划分结果int ret = METIS_PartGraphFunc(&nVertices, &nWeights, xadj.data(), adjncy.data(),NULL, NULL, adjwgt.data(), &nParts, NULL,NULL, NULL, &objval, part.data());if (ret != rstatus_et::METIS_OK) { cout << "METIS_ERROR" << endl; }cout << "METIS_OK" << endl;cout << "objval: " << objval << endl;for (unsigned part_i = 0; part_i < part.size(); part_i++) {cout << part_i + 1 << " " << part[part_i] << endl;}return part;
}int main() {ifstream ingraph("graph.txt");int vexnum, edgenum;string line;getline(ingraph, line);istringstream tmp(line);tmp >> vexnum >> edgenum;vector<idx_t> xadj(0);vector<idx_t> adjncy(0); // 压缩图表示vector<idx_t> adjwgt(0); // 节点权重idx_t a, w;for (int i = 0; i < vexnum; i++) {xadj.push_back(adjncy.size()); // 对应csr的: row offsets, csr格式见:https://www.cnblogs.com/xbinworld/p/4273506.htmlgetline(ingraph, line);istringstream tmp(line);while (tmp >> a >> w) {adjncy.push_back(a - 1); // 节点id从0开始 // column indicesadjwgt.push_back(w);     // values}}xadj.push_back(adjncy.size());ingraph.close();vector<idx_t> part = func(xadj, adjncy, adjwgt, METIS_PartGraphRecursive);//vector<idx_t> part = func(xadj, adjncy, adjwgt, METIS_PartGraphKway);ofstream outpartition("partition.txt");for (int i = 0; i < part.size(); i++) { outpartition << i + 1 << " " << part[i] << endl; }outpartition.close();return 0;
}

运行命令:

g++ test2.cc -lmetis
./a.out

运行结果:

METIS_OK
objval: 5
1 1
2 1
3 1
4 0
5 1
6 0
7 0

相关接口函数

Parmetis

安装

官网
官方PDF!!!
方案一:
Installing and using the ParMetis library
c++ - ParMETIS:对 `ParMETIS_V3_PartMeshKway’的 undefined reference
方案二:

sudo apt-get install libparmetis-dev  # 安装
mpic++ test_parmetis.cc -lparmetis # 运行案例

pymetis

摘抄自
PyMetis is a Python wrapper for the Metis graph partititioning software by George Karypis, Vipin Kumar and others. It includes version 5.1.0 of Metis and wraps it using the Pybind11 wrapper generator library. So far, it only wraps the most basic graph partitioning functionality (which is enough for my current use), but extending it in case you need more should be quite straightforward. Using PyMetis to partition your meshes is really easy–essentially all you need to pass into PyMetis is an adjacency list for the graph and the number of parts you would like.

例子

import numpy as np
import pymetis
adjacency_list = [np.array([4, 2, 1]),np.array([0, 2, 3]),np.array([4, 3, 1, 0]),np.array([1, 2, 5, 6]),np.array([0, 2, 5]),np.array([4, 3, 6]),np.array([5, 3])]
n_cuts, membership = pymetis.part_graph(2, adjacency=adjacency_list)
# n_cuts = 3
# membership = [1, 1, 1, 0, 1, 0, 0]nodes_part_0 = np.argwhere(np.array(membership) == 0).ravel() # [3, 5, 6]
nodes_part_1 = np.argwhere(np.array(membership) == 1).ravel() # [0, 1, 2, 4]

part_graph

def part_graph(nparts, adjacency=None, xadj=None, adjncy=None,vweights=None, eweights=None, recursive=None):"""Return a partition (cutcount, part_vert) into nparts for an input graph.The input graph is given in either a Pythonic way as the `adjacency' parameteror in the direct C-like way that Metis likes as `xadj' and `adjncy'. Itis an error to specify both graph inputs.The Pythonic graph specifier `adjacency' is required to have the followingproperties:- len(adjacency) needs to return the number of vertices- adjacency[i] needs to be an iterable of vertices adjacent to vertex i.Both directions of an undirected graph edge are required to be stored.If you would like to use *eweights* (edge weights), you need to use thexadj/adjncy way of specifying graph connectivity. This works as follows:The adjacency structure of the graph is stored as follows: Theadjacency list of vertex *i* is stored in array *adjncy* starting atindex ``xadj[i]`` and ending at (but not including) index ``xadj[i +1]``. That is, for each vertex i, its adjacency list is stored inconsecutive locations in the array *adjncy*, and the array *xadj* isused to point to where it begins and where it ends.The weights of the edges (if any) are stored in an additional arraycalled *eweights*. This array contains *2m* elements (where *m* is thenumber of edges, taking into account the undirected nature of thegraph), and the weight of edge ``adjncy[j]`` is stored at location``adjwgt[j]``. The edge-weights must be integers greater than zero. Ifall the edges of the graph have the same weight (i.e., the graph isunweighted), then the adjwgt can be set to ``None``.(quoted with slight adaptations from the Metis docs)"""xadj, adjncy = _prepare_graph(adjacency, xadj, adjncy)if recursive is None:if nparts > 8:recursive = Falseelse:recursive = Truefrom pymetis._internal import part_graphif nparts == 1:# metis has a bug in this case--it disregards the index basereturn 0, [0] * (len(xadj)-1)return part_graph(nparts, xadj, adjncy, vweights, eweights, recursive)

Linux 环境下metis与parmetis安装与使用相关推荐

  1. linux设置密码报错automa,opensuse linux环境下ibm_websphere和ibm_db2安装以及DB2数据迁移操...

    opensuse linux环境下ibm_websphere和ibm_db2安装 ibm_websphere安装: 1.ibm官网下载免费版websphere,如下载文件名为BASETRIAL.age ...

  2. linux查看rabbitmq的插件,【linux环境下】RabbitMq的安装和监控插件安装

    简介这篇文章主要介绍了[linux环境下]RabbitMq的安装和监控插件安装以及相关的经验技巧,文章约2904字,浏览量445,点赞数5,值得参考! [注意安装过程中,提示某些命令not found ...

  3. Linux环境下JDK/Eclipse一键安装脚本

    -------------------------------------------------------------------- author:jiangxin Email:jiangxinn ...

  4. Linux环境下metis与mt-metis的安装和使用

    Linux下的metis与mt-metis的安装和使用 本文的Linux包括VMare和windows下的WSL环境下安装metis串行和并行 本文还讲述了电脑的线程以及和超线程的区别,如何寻找,如何 ...

  5. linux环境下python 库模块安装

    今天要在一台线上服务器上部署一个python脚本,其中用到了MySQLdb,各种尝试下载源码(各种依赖库的相互不兼容),get/yum(这linux真纯净啊  这俩都没法用)安装,wget下载rpm包 ...

  6. linux上pyenv卸载,Linux环境下的 pyenv的安装

    CentOS上安装pyenv: 在安装pyenv前,需要先安装如下的依赖包: 在 CentOS/RHEL/Fedora 下: yum install readline readline-devel r ...

  7. linux环境下redis5.0的安装配置

    文章目录 一.Redis介绍: 二.安装Redis 2.1. 下载 解压 进入文件夹 然后 编译 2.2. 启动Redis 2.2.1. 指定配置文件启动redis 2.2.2. 配置redis后台启 ...

  8. weblogic部署linux静默安装,Linux环境下Weblogic11g中间件-静默安装详解

    第一步: 安装产品 1.配置好java环境变量 java -version查看是否生效,weblogic11g要求最好用1.6以上JDK进行安装配置 2.找到安装介质执行命令:java -jar wl ...

  9. linux环境下GXL软件的安装

    Linux –GXL2015安装 Author Dave Time: 2015-10-29 准备工作:在进行安装之前,我们首先要确定安装包内的东西,一般PCI或者天目公司会如下提供相关内容 local ...

最新文章

  1. poj 2559 Largest Rectangle in a Histogram 栈
  2. C++/C++11中std::runtime_error的使用
  3. entity.Database.SqlQuery() 和entity.Database.SqlCommand()
  4. CTFshow 命令执行 web70
  5. hashmap时间和空间复杂度_Python算法 00--时间复杂度和空间复杂度
  6. ASP.NET MVC 学习之路-4
  7. apache 官方 Dubbo 文档
  8. 数据平面开发套件(DPDK)中的Vhost / Virtio的配置和性能
  9. ES6 的解构赋值前每次都创建一个对象吗?会加重 GC 的负担吗?
  10. 论文笔记--知识表示学习研究进展-2016
  11. 【_ 記 】topjui 多文件上传 (代码)
  12. 腾讯云国际版注册流程详解
  13. python对串口助手传入的16进制字符数据进行绘图
  14. Riverbed助力富邦人寿在市场竞争和数字化进程中抢占先机
  15. 树莓派装专用服务器系统,Raspberry Pi 树莓派安装64位系统打造全功能NAS [全网最正确操作记录]...
  16. Linux proc目录详解
  17. 精品基于Uniapp+Springboot实现的患者服药提醒APP
  18. Archlinux和Windows双系统安装
  19. 你的人生你定义!享你所想,无惧冒险
  20. 网页设计基础学习(一)

热门文章

  1. 手机通过usu共享给电脑网络(win10),电脑变卡的解决办法
  2. Wireles Tools移植
  3. 全国计算机等级考试python试题_全国计算机等级考试二级Python真题及解析(5)
  4. IDEA安装激活一条龙服务
  5. 开发者在国内如何白嫖AWS服务器一年时间,怎样通过SSH工具连接AWS?免费的服务器有什么样的限制?
  6. html文字自动消失了,为什么从网页上复制的文字到word上一修改后面的字就自动消失了...
  7. 微型计算机控制数字量输入输出,[工学]WX_微型计算机控制技术_第二章5.ppt
  8. 算法工程师0——算法工程师学习进阶路线
  9. PIM-SM中DR作用
  10. 第2章 人机交互的相关学科