Unverified Commit b57e27d7 authored by Carlos Mastalli's avatar Carlos Mastalli Committed by GitHub
Browse files

Merge pull request #1043 from cmastalli/topic/disable-python-multithreading

Disable multithreading when we use models derived from Python code
parents e95b9a3d 0a62690c
Pipeline #17447 passed with stage
in 85 minutes and 6 seconds
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2020, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -47,6 +47,7 @@ class ActionModelAbstract_wrap : public ActionModelAbstract, public bp::wrapper<
}
boost::shared_ptr<ActionDataAbstract> createData() {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<ActionDataAbstract> >(createData.ptr());
}
......
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2020, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -37,6 +37,7 @@ class ActivationModelAbstract_wrap : public ActivationModelAbstract, public bp::
}
boost::shared_ptr<ActivationDataAbstract> createData() {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<ActivationDataAbstract> >(createData.ptr());
}
......
......@@ -2,7 +2,7 @@
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2020, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -49,6 +49,7 @@ class ActuationModelAbstract_wrap : public ActuationModelAbstract, public bp::wr
}
boost::shared_ptr<ActuationDataAbstract> createData() {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<ActuationDataAbstract> >(createData.ptr());
}
......
......@@ -2,7 +2,7 @@
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2021, LAAS-CNRS, University of Edinburgh, University of Trento
// Copyright (C) 2021-2022, LAAS-CNRS, University of Edinburgh, University of Trento
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -51,6 +51,7 @@ class ControlParametrizationModelAbstract_wrap : public ControlParametrizationMo
}
boost::shared_ptr<ControlParametrizationDataAbstract> createData() {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<ControlParametrizationDataAbstract> >(createData.ptr());
}
......
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2021, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -64,6 +64,7 @@ class CostModelAbstract_wrap : public CostModelAbstract, public bp::wrapper<Cost
}
boost::shared_ptr<CostDataAbstract> createData(DataCollectorAbstract* const data) {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<CostDataAbstract> >(createData.ptr(), boost::ref(data));
}
......
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2020, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -50,6 +50,7 @@ class DifferentialActionModelAbstract_wrap : public DifferentialActionModelAbstr
}
boost::shared_ptr<DifferentialActionDataAbstract> createData() {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<DifferentialActionDataAbstract> >(createData.ptr());
}
......
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2021, LAAS-CNRS, University of Edinburgh, University of Trento
// Copyright (C) 2021-2022, LAAS-CNRS, University of Edinburgh, University of Trento
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -56,6 +56,7 @@ class IntegratedActionModelAbstract_wrap : public IntegratedActionModelAbstract,
}
boost::shared_ptr<ActionDataAbstract> createData() {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<IntegratedActionDataAbstract> >(createData.ptr());
}
......
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2021, University of Edinburgh
// Copyright (C) 2021-2022, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -56,6 +56,7 @@ class ResidualModelAbstract_wrap : public ResidualModelAbstract, public bp::wrap
}
boost::shared_ptr<ResidualDataAbstract> createData(DataCollectorAbstract* const data) {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<ResidualDataAbstract> >(createData.ptr(), boost::ref(data));
}
......@@ -70,4 +71,4 @@ class ResidualModelAbstract_wrap : public ResidualModelAbstract, public bp::wrap
} // namespace python
} // namespace crocoddyl
#endif // BINDINGS_PYTHON_CROCODDYL_CORE_RESIDUAL_BASE_HPP_
\ No newline at end of file
#endif // BINDINGS_PYTHON_CROCODDYL_CORE_RESIDUAL_BASE_HPP_
......@@ -2,7 +2,7 @@
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2020, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -28,7 +28,9 @@ class StateAbstract_wrap : public StateAbstract, public bp::wrapper<StateAbstrac
using StateAbstract::nx_;
using StateAbstract::ub_;
StateAbstract_wrap(int nx, int ndx) : StateAbstract(nx, ndx), bp::wrapper<StateAbstract>() {}
StateAbstract_wrap(int nx, int ndx) : StateAbstract(nx, ndx), bp::wrapper<StateAbstract>() {
enableMultithreading() = false;
}
Eigen::VectorXd zero() const { return bp::call<Eigen::VectorXd>(this->get_override("zero").ptr()); }
......
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2020, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -39,6 +39,7 @@ class ContactModelAbstract_wrap : public ContactModelAbstract, public bp::wrappe
}
boost::shared_ptr<ContactDataAbstract> createData(pinocchio::DataTpl<Scalar>* const data) {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<ContactDataAbstract> >(createData.ptr(), boost::ref(data));
}
......
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2020, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -38,6 +38,7 @@ class ImpulseModelAbstract_wrap : public ImpulseModelAbstract, public bp::wrappe
}
boost::shared_ptr<ImpulseDataAbstract> createData(pinocchio::DataTpl<Scalar>* const data) {
enableMultithreading() = false;
if (boost::python::override createData = this->get_override("createData")) {
return bp::call<boost::shared_ptr<ImpulseDataAbstract> >(createData.ptr(), boost::ref(data));
}
......
......@@ -42,7 +42,6 @@ terminalModel = crocoddyl.IntegratedActionModelEuler(
T = 100
x0 = np.array([3.14, 0., 0., 0.])
problem = crocoddyl.ShootingProblem(x0, [runningModel] * T, terminalModel)
problem.nthreads = 1 # TODO(cmastalli): Remove after Crocoddyl supports multithreading with Python-derived models
solver = crocoddyl.SolverFDDP(problem)
cameraTF = [1.4, 0., 0.2, 0.5, 0.5, 0.5, 0.5]
......
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2021, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -13,6 +13,11 @@
namespace crocoddyl {
inline bool& enableMultithreading() {
static bool enable = true;
return enable;
}
enum AssignmentOp { setto, addto, rmfrom };
inline bool is_a_AssignmentOp(AssignmentOp op) { return (op == setto || op == addto || op == rmfrom); }
......
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2021, LAAS-CNRS, University of Edinburgh, University of Oxford
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh, University of Oxford
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
......@@ -61,7 +61,9 @@ ShootingProblemTpl<Scalar>::ShootingProblemTpl(
allocateData();
#ifdef CROCODDYL_WITH_MULTITHREADING
nthreads_ = CROCODDYL_WITH_NTHREADS;
if (enableMultithreading()) {
nthreads_ = CROCODDYL_WITH_NTHREADS;
}
#endif
}
......@@ -121,7 +123,9 @@ ShootingProblemTpl<Scalar>::ShootingProblemTpl(
}
#ifdef CROCODDYL_WITH_MULTITHREADING
nthreads_ = CROCODDYL_WITH_NTHREADS;
if (enableMultithreading()) {
nthreads_ = CROCODDYL_WITH_NTHREADS;
}
#endif
}
......@@ -485,6 +489,12 @@ void ShootingProblemTpl<Scalar>::set_nthreads(const int nthreads) {
} else {
nthreads_ = static_cast<std::size_t>(nthreads);
}
if (enableMultithreading()) {
std::cerr << "Warning: the number of threads won't affect the computational performance as multithreading "
"support is not enabled."
<< std::endl;
nthreads_ = 1;
}
#endif
}
......
Supports Markdown
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