Chris, > I'm doing some experiments with hpx::dataflow and would like to > recursively "chain" a dataflow for execution over a distributed vector of > size_t elements. > Sample code is provided below (apologies if it's not a perfect compile): > static void run( > std::string nom, > size_t v) { > hpx::cout << v << hpx::endl; > } > > HPX_PLAIN_ACTION(run, run_action); > > static hpx::future<void> run_dataflow( > std::string nom, > hpx::partitioned_vector<size_t> &arr, > std::vector<hpx::id_type> locs, > std::vector<size_t>::iterator curr, > std::vector<size_t>::iterator end) { > hpx::future<void> res = (curr != end) ? run_dataflow(nom, arr, locs, > std::next(curr), end) : hpx::make_ready_future(); > return hpx::dataflow( > hpx::util::unwrapped([nom, &arr, localities, &curr] () -> > hpx::future<void> { > size_t v = *c; > return hpx::async<run_action>(localities[arr.get_partition(v)], nom, > v); > }), > std::move(res) ); > > } > > int main(int argc, char **argv) { > ... /* dvec_size is defined up here */ ... > > std::vector<hpx::id_type> locs = hpx::find_all_localities(); > std::string nom = "arr_nom"; > hpx::partitioned_vector<size_t> arr(dvec_size, > hpx::container_layout(locs)); > arr.register_as(nom); > > std::vector<size_t> pos; > std::iota( > std::begin(pos), > std::end(pos), > dvec_size); > > hpx::future<void> fd = run_dataflow( > nom, > arr, > std::begin(pos), > std::end(pos) ); > fd.wait(); > > } > I've been getting a runtime errors for this code (segmentation fault) - > this is probably a semi-trivial bug or misunderstanding on my part - any > help/assistance would be appreciated. (I'm compiling against HPX with MPI)
The main reason for this kind of problems is that variables which are captured by reference into a lambda (or similar) go out of scope before the lambda itself is being executed: void foo() { vector<int> bar = {...}; return async([&bar]() { bar.push_back(42); }); } foo(); In this example, the variable 'bar' is not valid anymore when the lambda (which is scheduled as a new thread) is eventually executed. Please note, that dataflow() runs the function passed to it on a new thread as well. I'd assume that in your example the variable 'arr' goes out of scope before the lambda referencing it is run. HTH Regards Hartmut --------------- http://boost-spirit.com http://stellar.cct.lsu.edu > > V/r, > Chris _______________________________________________ hpx-users mailing list hpx-users@stellar.cct.lsu.edu https://mail.cct.lsu.edu/mailman/listinfo/hpx-users