From b91133fbc2a595cad621403d393f8d6b97318c38 Mon Sep 17 00:00:00 2001 From: Paul Emsley Date: Tue, 26 Nov 2024 18:30:35 +0000 Subject: [PATCH] Set and use max number of threads in refine_direct() in the api --- api/coot-molecule.cc | 3 ++- api/coot-molecule.hh | 1 + api/molecules-container-nanobind.cc | 1 + api/molecules-container.cc | 6 +++++- src/c-interface.cc | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/coot-molecule.cc b/api/coot-molecule.cc index 967743a91..383dfd222 100644 --- a/api/coot-molecule.cc +++ b/api/coot-molecule.cc @@ -2399,6 +2399,7 @@ coot::molecule_t::get_fixed_atoms() const { int coot::molecule_t::refine_direct(std::vector rv, const std::string &alt_loc, const clipper::Xmap &xmap, + unsigned int max_number_of_threads, float map_weight, int n_cycles, const coot::protein_geometry &geom, bool do_rama_plot_restraints, float rama_plot_weight, bool do_torsion_restraints, float torsion_weight, @@ -2447,7 +2448,7 @@ coot::molecule_t::refine_direct(std::vector rv, const std::stri if (do_torsion_restraints) flags = TYPICAL_RESTRAINTS_WITH_TORSIONS; pseudo_restraint_bond_type pseudos = NO_PSEUDO_BONDS; - int n_threads = 4; // coot::get_max_number_of_threads(); + int n_threads = max_number_of_threads; ctpl::thread_pool thread_pool(n_threads); restraints.thread_pool(&thread_pool, n_threads); diff --git a/api/coot-molecule.hh b/api/coot-molecule.hh index f6c16f957..75b6d7544 100644 --- a/api/coot-molecule.hh +++ b/api/coot-molecule.hh @@ -1133,6 +1133,7 @@ namespace coot { //! real space refinement int refine_direct(std::vector rv, const std::string &alt_loc, const clipper::Xmap &xmap, + unsigned int max_number_of_threads, float map_weight, int n_cycles, const coot::protein_geometry &geom, bool do_rama_plot_restraints, float rama_plot_weight, bool do_torsion_restraints, float torsion_weight, diff --git a/api/molecules-container-nanobind.cc b/api/molecules-container-nanobind.cc index 44974fb1a..ea539c4bb 100644 --- a/api/molecules-container-nanobind.cc +++ b/api/molecules-container-nanobind.cc @@ -398,6 +398,7 @@ NB_MODULE(chapi, m) { .def("set_make_backups",&molecules_container_t::set_make_backups) .def("set_map_sampling_rate",&molecules_container_t::set_map_sampling_rate) .def("set_map_weight",&molecules_container_t::set_map_weight) + .def("set_max_number_of_threads",&molecules_container_t::set_max_number_of_threads) .def("set_molecule_name",&molecules_container_t::set_molecule_name) .def("set_rama_plot_restraints_weight",&molecules_container_t::set_rama_plot_restraints_weight) .def("set_refinement_is_verbose",&molecules_container_t::set_refinement_is_verbose) diff --git a/api/molecules-container.cc b/api/molecules-container.cc index 1ec8f5abb..c916f93b4 100644 --- a/api/molecules-container.cc +++ b/api/molecules-container.cc @@ -2891,11 +2891,15 @@ molecules_container_t::refine_direct(int imol, std::vector rv, << " and imol_refinement_map " << imol_refinement_map << std::endl; + // this is not stored in molecules_container! + unsigned int max_number_of_threads = thread_pool.size(); + int status = 0; if (is_valid_model_molecule(imol)) { if (is_valid_map_molecule(imol_refinement_map)) { const clipper::Xmap &xmap = molecules[imol_refinement_map].xmap; - status = molecules[imol].refine_direct(rv, alt_loc, xmap, map_weight, n_cycles, geom, + status = molecules[imol].refine_direct(rv, alt_loc, xmap, max_number_of_threads, + map_weight, n_cycles, geom, use_rama_plot_restraints, rama_plot_restraints_weight, use_torsion_restraints, torsion_restraints_weight, refinement_is_quiet); diff --git a/src/c-interface.cc b/src/c-interface.cc index eb0c8491f..8659dd6e8 100644 --- a/src/c-interface.cc +++ b/src/c-interface.cc @@ -2108,7 +2108,7 @@ void set_map_radius_em(float radius) { for (int ii=0; ii args; args.push_back(radius); add_to_history_typed(cmd, args);