Linux下的metis与mt-metis的安装和使用

  • 本文的Linux包括VMare和windows下的WSL环境下安装metis串行和并行
  • 本文还讲述了电脑的线程以及和超线程的区别,如何寻找,如何判别,请看下文

装备:

  1. Ubuntu18.6.4LTS
  2. gcc7.5.0
  3. cmake version 3.10.2

metis的安装

别相信网上的一键sudo apt-get install libmetis-dev,有很多问题!!!


  1. 下载链接->metis-5.1.0.tar.gz
  2. 解压成文件夹,名字假设为A
  3. 打开A/include/metis.h,根据自己电脑的位数(32or64)选择
// 64位
#define IDXTYPEWIDTH 64 
 
// 32位
#define IDXTYPEWIDTH 32 
  1. 在A目录执行以下编译命令
make config
make
sudo make install
  1. 可能出现的问题:

    1. make[2]: Leaving directory ‘/home/xxx/metis/build/Linux-x86_64’
      1. 无伤大雅,没有问题
  2. 配置环境

    1. sudo vim /etc/ld.so.conf
    2. 末尾添加include /usr/local/bin保存
    3. 运行sudo ldconfig更新
  3. 测试环境

#include <cstddef> /* NULL */
#include <metis.h>
#include <iostream>
#include <vector>

int main(){

    idx_t nVertices = 6;//顶点个数
    idx_t nEdges    = 7;//边的条数
    idx_t nWeights  = 1;//权重
    idx_t nParts    = 2;//几类

    idx_t objval;
    std::vector<idx_t> part(nVertices, 0);


    // Indexes of starting points in adjacent array
    std::vector<idx_t> xadj = {0,2,5,7,9,12,14};

    // Adjacent vertices in consecutive index order
    std::vector<idx_t> adjncy = {1,3,0,4,2,1,5,0,4,3,1,5,4,2};

    // Weights of vertices
    // if all weights are equal then can be set to NULL
    std::vector<idx_t> vwgt(nVertices * nWeights, 0);
    


    int ret = METIS_PartGraphKway(&nVertices,& nWeights, xadj.data(), adjncy.data(),
				       NULL, NULL, NULL, &nParts, NULL,
       				  NULL, NULL, &objval, part.data());

    std::cout << ret << std::endl;
    
    for(unsigned part_i = 0; part_i < part.size(); part_i++){
	std::cout << part_i << " " << part[part_i] << std::endl;
    }

    
    return 0;
}
  1. g++ -std=c++11 test.cpp -o test -lmetis
  2. 结果:
1
0 1
1 0
2 0
3 1
4 1
5 0

**ps:**分割是随机的,只要看你是不是分为0,1共2类

mt-metis的安装

mt-metis就是metis的多线程版本,能够进行并行计算

  1. 下载链接->mt-metis-0.7.2.tar.gz
  2. 解压成文件夹,名字假设为A
  3. 打开A/metis/include/metis.h,根据自己电脑的位数(32or64)选择
// 64位
#define IDXTYPEWIDTH 64 
 
// 32位
#define IDXTYPEWIDTH 32 
  1. 回到A目录里,运行编译命令
./configure
make
sudo make install
  1. 可能的问题
    1. ./configure:command not found 解决办法sh configure 然后添加执行权限 chmod u+x configure
    2. 如果是wsl安装,把第一个命令改成bash ./configure即可
  2. 使用方法
mtmetis test.graph 2 test.part -t -T n

解释:

  1. test.graph 是图表的文件,例如下面内容:第一行就是顶点和边的个数,顶点从1开始,下面就是每两个顶点连接成的边
    10 10
    10 2
    1 3
    2 4
    3 5
    4 6
    5 7
    6 8
    7 9
    8 10
    9 1
    
  2. 2是分成的类别数量
  3. test.part是分割后生成的文件
  4. -t能显示mtmetis的运行时间
  5. -T n n代表线程数量,默认以全部线程数,不能超过最大的线程数

超线程与线程

接着上题,你可能会疑惑该如何查找自己的线程数量为多少?那什么又是超线程呢?

  • 以windows为例,打开任务管理器-》性能
  • 能够看到右下角有内核逻辑处理器,能发现逻辑处理器=内核*2,这里的逻辑处理器数量就是超线程数量,线程数量=内核数量
  • 超线程是intel提出的虚拟化处理器,在高性能计算中我们不能使用超线程,因此一定要知道自己最真实的线程数量有多少
  • 在vmare虚拟机的处理器配置中也用到了超线程,为了规避这种情况,可以设置1个处理器,内核数量为真实线程数量(因为每个人就是1个CPU处理器,x核,而intel使用超线程让内核*2)
  • 你可能还看到左侧线程有3000,4000。刚刚又说电脑只有n个总线程,远小于他!xd,可别忘了,线程切换的开销很小,电脑一会就切换了好多线程,所以你看到了有3,4k。

转载至我的博客

  • 18
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 17
    评论
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
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

染念

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值