【发布时间】:2014-04-03 09:34:46
【问题描述】:
我无法以并行模式从 boost adjacency_list 访问边缘属性。我在 C++ 代码中使用 boost 1.54.0 和 OpenMP。我的问题归结为以下沙盒示例:
#include <boost/graph/adjacency_list.hpp>
struct Knoten {int Knoten_Property};
struct Pfeil {int Pfeil_Property};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, Knoten, Pfeil> Graph;
typedef boost::graph_traits<Graph>::edge_descriptor Edge;
typedef boost::graph_traits<Graph>::edge_iterator Edge_iter;
Graph G;
// […]
// some initializations for the graph.
// Test graph contains about 20,000 edges
#pragma omp parallel num_threads(4)
{
#pragma omp for private(i)
for(int i = 0; i < 100; i++)
{
for(pair<Edge_iter, Edge_iter> ei = edges(G); ei.first != ei.second; ++ei.first)
{
for (int i = 0; i < 100000; ++i)
{
Edge E = *ei.first;
int my_test = G[E].Pfeil_Property; // (*)
}
}
}
}
运行此代码时(并行模式,4 个线程),我在第 (*) 行读取时遇到访问冲突。似乎我无法从不同的线程同时访问边缘的属性,尽管这是只读访问。 对此问题的任何帮助将不胜感激。非常感谢!
这是完整的错误信息(德语);上面写着: “例外(第一次机会)... 在位置读取时访问冲突... 未处理的异常..."
Eine Ausnahme (erste Chance) bei 0x000000014042237f in MyApplication.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x000000000257ac58.
Unbehandelte Ausnahme bei 0x000000014042237f in MyApplication.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x000000000257ac58.
【问题讨论】:
-
可能很有趣:Parallel Boost Graph Library boost.org/doc/libs/1_55_0/libs/graph_parallel/doc/html/…
-
请显示完整的错误信息。
-
感谢您的回答。关于 Parallel Boost Graph Library,据我所知,这是为了在多个处理器上分布图。但是,就我而言,该图没有分布(也不应该分布);我只想从多个线程访问边缘属性。
-
您对分布式并行 bgl 的权利,在这里无济于事。既然它说的是未处理的异常,你有没有试过在 try catch 中包围它并打印 std::exception.what()?
-
另一个想法是在内部 for 循环中使用 i。它可能掩盖了 openMP 用于并行化的 i。只是一个想法。没有 openmp 经验。
标签: c++ multithreading boost boost-graph adjacency-list