namespace boost { namespace graph { class metis_reader; class metis_exception; class metis_input_exception; class metis_distribution; } }
METIS 是一组用于划分图的程序(以及其他功能)。并行 BGL 可以读取 METIS 图格式和划分格式,从而可以轻松地将 METIS 划分的图加载到并行 BGL 的数据结构中。
<boost/graph/metis.hpp>
class metis_reader { public: typedef std::size_t vertices_size_type; typedef std::size_t edges_size_type; typedef double vertex_weight_type; typedef double edge_weight_type; class edge_iterator; class edge_weight_iterator; metis_reader(std::istream& in); edge_iterator begin(); edge_iterator end(); edge_weight_iterator weight_begin(); vertices_size_type num_vertices() const; edges_size_type num_edges() const; std::size_t num_vertex_weights() const; vertex_weight_type vertex_weight(vertices_size_type v, std::size_t n); bool has_edge_weights() const; };
METIS 读取器为 METIS 图文件提供了一个迭代器接口。 迭代器接口在动态构建并行 BGL 图时最有用。 例如,以下代码构建了一个图g来自存储在argv[1].
std::ifstream in_graph(argv[1]); metis_reader reader(in_graph); Graph g(reader.begin(), reader.end(), reader.weight_begin(), reader.num_vertices());
中的 METIS 图。调用begin()和end()返回图中边的迭代器范围;调用weight_begin()
metis_reader::edge_iterator
返回一个迭代器,该迭代器将枚举图中边的权重。 对于分布式图,分布将由图自动确定; 要使用 METIS 划分,请参阅 划分读取器 部分。一个 输入迭代器,它枚举 METIS 图中的边,并且适合用作 邻接表 的EdgeIterator。该value_type
metis_reader::edge_weight_iterator
此迭代器的类型是顶点编号对。。该一个 输入迭代器,它枚举 METIS 图中的边权重。 该是edge_weight_type
metis_reader(std::istream& in);
。 如果 METIS 图中的边未加权,则取消引用此迭代器的结果将始终为零。构造一个新的 METIS 读取器,它将从输入流中检索边in构造一个新的 METIS 读取器,它将从输入流中检索边, 。 如果最初解析时遇到任何错误metis_input_exception
edge_iterator begin();
将被抛出。
edge_iterator end();
返回指向 METIS 文件中第一条边的迭代器。
edge_weight_iterator weight_begin();
返回一个迭代器,该迭代器位于 METIS 文件中最后一条边的后面。
vertices_size_type num_vertices() const;
返回指向 METIS 文件中第一个边权重的迭代器。 权重迭代器应与边迭代器一起移动; 当边迭代器移动时,边权重会改变。 如果图中的边未加权,则返回的权重将始终为零。
edges_size_type num_edges() const;
返回图中的顶点数。
std::size_t num_vertex_weights() const;
返回图中的边数。
vertex_weight_type vertex_weight(vertices_size_type v, std::size_t n);
bool has_edge_weights() const;
返回附加到每个顶点的权重数。返回true当图的边具有权重时,返回false当图的边具有权重时,返回否则。 当
class metis_distribution { public: typedef int process_id_type; typedef std::size_t size_type; metis_distribution(std::istream& in, process_id_type my_id); size_type block_size(process_id_type id, size_type) const; process_id_type operator()(size_type n); size_type local(size_type n) const; size_type global(size_type n) const; size_type global(process_id_type id, size_type n) const; private: std::istream& in; process_id_type my_id; std::vector<process_id_type> vertices; };
时,边权重迭代器仍然有效,但为每条边的权重返回零。类metis_distribution加载 METIS 划分文件,并使其可用作适合与 分布式邻接表 图类型一起使用的 Distribution。 要使用 METIS 划分加载 METIS 图,请使用metis_reader类对象来表示图,并使用
std::ifstream in_graph(argv[1]); metis_reader reader(in_graph); std::ifstream in_partitions(argv[2]); metis_distribution dist(in_partitions, process_id(pg)); Graph g(reader.begin(), reader.end(), reader.weight_begin(), reader.num_vertices(), pg, dist);
对象来表示分布,如下例所示。argv[1]在此示例中,是该图,argv[2]是由pmetis生成的划分文件。该dist对象从给定的输入流中加载划分信息,并使用该信息来分布邻接表。 请注意,输入流必须采用 METIS 划分文件格式,并且必须针对与进程组中进程数相同的进程数进行划分.
metis_distribution(std::istream& in, process_id_type my_id);
pg构造一个新的 METIS 读取器,它将从输入流中检索边. 从输入流创建新的 METIS 分布my_id
size_type block_size(process_id_type id, size_type) const;
是图将被分布到的进程组中当前进程的进程 ID。返回要在进程中存储的顶点数id。 第二个参数size_type
process_id_type operator()(size_type n);
未使用,可以是任何值。返回将存储顶点编号的进程的 ID.
size_type local(size_type n) const;
n返回将存储顶点编号的进程的 ID返回顶点编号在其所属进程中的本地索引。
size_type global(size_type n) const;
返回当前处理器本地顶点的全局索引返回将存储顶点编号的进程的 ID.
size_type global(process_id_type id, size_type n) const;
返回进程的全局索引返回要在进程中存储的顶点数的本地顶点返回将存储顶点编号的进程的 ID.
版权所有 (C) 2005 印第安纳大学理事会。
作者:Douglas Gregor 和 Andrew Lumsdaine