PostRefine: bound its fixed 16 Ceres threads by the machine's hardware threads
Build Packages / Create release (push) Successful in 8s
Build Packages / Build documentation (push) Successful in 46s
Build Packages / build:portable:linux-x86_64:cuda (push) Canceled after 2m50s
Build Packages / build:portable:linux-x86_64:nocuda (push) Canceled after 2m52s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Canceled after 2m48s
Build Packages / Unit tests (push) Canceled after 3m8s
Build Packages / Validation Battery (push) Canceled after 0s
Build Packages / build:jfjoch:rocky8:cuda (push) Canceled after 0s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Canceled after 0s
Build Packages / build:jfjoch:rocky8:nocuda (push) Canceled after 2m46s
Build Packages / build:jfjoch:rocky9:cuda (push) Canceled after 0s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Canceled after 2m8s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Canceled after 3m6s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Canceled after 0s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Canceled after 0s
Build Packages / build:portable:macos-arm64:nocuda (push) Canceled after 2m6s
Build Packages / build:jfjoch:rocky9:nocuda (push) Canceled after 2m44s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Canceled after 0s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Canceled after 0s
Build Packages / Generate python client (push) Canceled after 0s
Build Packages / build:portable:windows-x86_64:cuda (push) Canceled after 2m26s
Build Packages / build:portable:windows-x86_64:nocuda (push) Canceled after 2m26s

Post-refinement asks Ceres for a fixed 16 threads (so the pieces Ceres sums the
cost in do not move with -N). On a machine with fewer hardware threads, Ceres
bounds the request itself and prints, through abseil logging, "Specified
options.num_threads: 16 exceeds maximum available from the threading model Ceres
was compiled with: 14" for every solve, along with the "All log messages before
absl::InitializeLog()" banner. The count is now bounded first, by the same
std::thread::hardware_concurrency() Ceres uses, so Ceres runs exactly as it did
before and stays silent. Machines with 16 or more hardware threads are unchanged.

Checked by making a run see 14 hardware threads (get_nprocs shimmed): the previous
binary printed the warning 6 times on an open rotation set, the new one prints it
0 times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVeDQrPqZ52Tp6rzzZGxf3
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-11-20 04:20:47 +01:00
1 parent 81c8b48b1f
commit c44056b3f9
1 file changed
+7 -2
@@ -13,6 +13,7 @@
#include <memory>
#include <numeric>
#include <string>
#include <thread>
#include "../../common/JFJochMath.h" // PI
#include "XtalResidual.h" // the positional detector<->reciprocal residual, and the cell it is parameterised by
@@ -710,10 +711,14 @@ PostRefineResult PostRefineRotationGeometry(PostRefineObservations observations,
// A fixed thread count, not -N: Ceres sums the cost and gradient in 4 * num_threads
// pieces, so the steps it accepts and where it stops would otherwise move with -N. It
// hands the pieces to its threads in scheduling order, which only one thread makes
// exact - and one thread costs a second or more here - so that part is left.
// exact - and one thread costs a second or more here - so that part is left. Ceres bounds
// it by the machine's hardware threads, with a warning, so it is bounded here first.
constexpr int POSTREFINE_CERES_THREADS = 16;
const int hardware_threads = static_cast<int>(std::thread::hardware_concurrency());
ceres::Solver::Options o; o.linear_solver_type = ceres::DENSE_QR; o.max_num_iterations = 60;
o.num_threads = POSTREFINE_CERES_THREADS; o.logging_type = ceres::LoggingType::SILENT;
o.num_threads = hardware_threads > 0 ? std::min(POSTREFINE_CERES_THREADS, hardware_threads)
: POSTREFINE_CERES_THREADS;
o.logging_type = ceres::LoggingType::SILENT;
ceres::Solver::Summary sum; ceres::Solve(o, &p, &sum);
if (distance_corr && !fix_distance && sum.IsSolutionUsable()) {
std::fill(distance_corr, distance_corr + 4, std::numeric_limits<double>::quiet_NaN());