jumov
jumov

Reputation: 53

Conflicting load by thread when running Rcpp with multithreads

I am trying to use c++ Pagmo library for parallelizing an optimization problem that takes too long to run serially. Some of the data used in the problem are R S4 class objects that are loaded from an Rdata file and used as inputs for the optimize function using RInside in c++. However, pagmo exits with below error message:

Error: bad value
Execution halted

When I run valgrind --tool=drd ./optimize it gives the below messages:

==202444== Conflicting load by thread 6 at 0x0d9264d3 size 1
==202444==    at 0x5D97406: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D9A36E: Rf_cons (in /usr/lib/R/lib/libR.so)
==202444==    by 0xD0FA69E: Rcpp::Rcpp_precious_preserve(SEXPREC*) (barrier.cpp:108)
==202444==    by 0x117D4F: Rcpp::Rcpp_precious_preserve(SEXPREC*) (routines.h:155)
==202444==    by 0x117A8B: Rcpp::Rcpp_PreciousPreserve(SEXPREC*) (RcppCommon.h:117)
==202444==    by 0x12F5F0: Rcpp::PreserveStorage<Rcpp::Vector<16, Rcpp::PreserveStorage> >::set__(SEXPREC*) (PreserveStorage.h:43)
==202444==    by 0x12F8D9: Rcpp::Vector<16, Rcpp::PreserveStorage>& Rcpp::PreserveStorage<Rcpp::Vector<16, Rcpp::PreserveStorage> >::copy__<Rcpp::Vector<16, Rcpp::PreserveStorage> >(Rcpp::Vector<16, Rcpp::PreserveStorage> const&) (PreserveStorage.h:66)
==202444==    by 0x12C579: Rcpp::Vector<16, Rcpp::PreserveStorage>::Vector(Rcpp::Vector<16, Rcpp::PreserveStorage> const&) (Vector.h:64)
==202444==    by 0x159B9E: BoostGraph::getTurnsFromPaths(int) (BoostGraph.h:372)
==202444==    by 0x14C1A8: getQLearningLik(Rcpp::S4_Impl<Rcpp::PreserveStorage>, std::vector<double, std::allocator<double> >, Rcpp::S4_Impl<Rcpp::PreserveStorage>, int, bool) (avgRewardQLearning.cpp:609)
==202444==    by 0x144349: getTurnsLikelihood(Rcpp::S4_Impl<Rcpp::PreserveStorage>, std::vector<double, std::allocator<double> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Rcpp::S4_Impl<Rcpp::PreserveStorage>, int) (TurnsNew.cpp:56)
==202444==    by 0x1140E2: OptimizeRL::fitness(std::vector<double, std::allocator<double> > const&) const (optimize.cpp:17)
==202444== Address 0xd9264d3 is at offset 5667 from 0xd924eb0. Allocation context:
==202444==    at 0x484DBD9: malloc (in /usr/libexec/valgrind/vgpreload_drd-amd64-linux.so)
==202444==    by 0x5D99E54: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D9ACCE: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D90F9C: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D917CC: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5D18A: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D4AA2F: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5A8EF: Rf_eval (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5C48E: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5D2D4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D4AA2F: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5A8EF: Rf_eval (in /usr/lib/R/lib/libR.so)

Another similar error:

==202444== Conflicting load by thread 4 at 0x0b408a73 size 1
==202444==    at 0x5D94B36: SETCAR (in /usr/lib/R/lib/libR.so)
==202444==    by 0x117E00: Rcpp::Rcpp_precious_remove(SEXPREC*) (routines.h:160)
==202444==    by 0x117AA9: Rcpp::Rcpp_PreciousRelease(SEXPREC*) (RcppCommon.h:121)
==202444==    by 0x12C337: Rcpp::PreserveStorage<Rcpp::Vector<16, Rcpp::PreserveStorage> >::~PreserveStorage() (PreserveStorage.h:34)
==202444==    by 0x12AFD5: Rcpp::Vector<16, Rcpp::PreserveStorage>::~Vector() (Vector.h:28)
==202444==    by 0x14CA08: getQLearningLik(Rcpp::S4_Impl<Rcpp::PreserveStorage>, std::vector<double, std::allocator<double> >, Rcpp::S4_Impl<Rcpp::PreserveStorage>, int, bool) (avgRewardQLearning.cpp:755)
==202444==    by 0x144349: getTurnsLikelihood(Rcpp::S4_Impl<Rcpp::PreserveStorage>, std::vector<double, std::allocator<double> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Rcpp::S4_Impl<Rcpp::PreserveStorage>, int) (TurnsNew.cpp:56)
==202444==    by 0x1140E2: OptimizeRL::fitness(std::vector<double, std::allocator<double> > const&) const (optimize.cpp:17)
==202444==    by 0x1230EF: pagmo::detail::prob_inner<OptimizeRL>::fitness(std::vector<double, std::allocator<double> > const&) const (problem.hpp:525)
==202444==    by 0x4A34327: pagmo::problem::fitness(std::vector<double, std::allocator<double> > const&) const (in /home/mattapattu/.local/lib/libpagmo.so.9.0)
==202444==    by 0x4B76357: pagmo::sade::evolve(pagmo::population) const (in /home/mattapattu/.local/lib/libpagmo.so.9.0)
==202444==    by 0x123700: pagmo::detail::algo_inner<pagmo::sade>::evolve(pagmo::population const&) const (algorithm.hpp:222)
==202444== Address 0xb408a73 is at offset 2419 from 0xb408100. Allocation context:
==202444==    at 0x484DBD9: malloc (in /usr/libexec/valgrind/vgpreload_drd-amd64-linux.so)
==202444==    by 0x5D99E54: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D9AEEE: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5D22D: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D4AA2F: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5A8EF: Rf_eval (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5C48E: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5D2D4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D5F528: R_forceAndCall (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5C87C0E: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D9EF16: ??? (in /usr/lib/R/lib/libR.so)
==202444==    by 0x5D3CCC7: ??? (in /usr/lib/R/lib/libR.so)

I am passing R S4 class objects to the optimizing functions, are the errors because mulitple threads are trying to access the S4 objects ? Is there some way to fix these issues ?

Upvotes: 1

Views: 46

Answers (0)

Related Questions