Commit e63919e7 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Disable parallel algorithms for property maps of type python::object

This fixes issue #362.
parent 7ad89287
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
#include "graph_selectors.hh" #include "graph_selectors.hh"
#include "graph_util.hh" #include "graph_util.hh"
#ifdef USING_OPENMP
#include <omp.h>
#endif
using namespace std; using namespace std;
using namespace boost; using namespace boost;
using namespace graph_tool; using namespace graph_tool;
...@@ -41,7 +45,15 @@ struct do_edge_endpoint ...@@ -41,7 +45,15 @@ struct do_edge_endpoint
eprop_t eprop = any_cast<eprop_t>(aeprop); eprop_t eprop = any_cast<eprop_t>(aeprop);
eprop.reserve(edge_index_range); eprop.reserve(edge_index_range);
parallel_vertex_loop #ifdef USING_OPENMP
size_t __attribute__ ((unused)) nt = omp_get_num_threads();
if (std::is_convertible<val_t,python::object>::value)
nt = 1; // python is not thread-safe
#endif
#pragma omp parallel if (num_vertices(g) > OPENMP_MIN_THRESH) \
num_threads(nt)
parallel_vertex_loop_no_spawn
(g, (g,
[&](auto v) [&](auto v)
{ {
......
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
#include "graph_selectors.hh" #include "graph_selectors.hh"
#include "graph_util.hh" #include "graph_util.hh"
#ifdef USING_OPENMP
#include <omp.h>
#endif
using namespace std; using namespace std;
using namespace boost; using namespace boost;
using namespace graph_tool; using namespace graph_tool;
...@@ -160,7 +164,15 @@ struct do_out_edges_op ...@@ -160,7 +164,15 @@ struct do_out_edges_op
auto vprop = boost::any_cast<VProp>(avprop).get_unchecked(num_vertices(g)); auto vprop = boost::any_cast<VProp>(avprop).get_unchecked(num_vertices(g));
parallel_vertex_loop #ifdef USING_OPENMP
size_t __attribute__ ((unused)) nt = omp_get_num_threads();
if (std::is_convertible<eval_t,python::object>::value)
nt = 1; // python is not thread-safe
#endif
#pragma omp parallel if (num_vertices(g) > OPENMP_MIN_THRESH) \
num_threads(nt)
parallel_vertex_loop_no_spawn
(g, (g,
[&](auto v) [&](auto v)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment