From d483b99e47cafb5e756932fc4a26e9b3575fbddb Mon Sep 17 00:00:00 2001 From: Peter Reinholdt Date: Mon, 18 Aug 2025 12:29:29 +0200 Subject: [PATCH 1/2] Fix integer division in end_chunk_idx --- pyci/src/common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyci/src/common.cpp b/pyci/src/common.cpp index b6657be1..675b58a3 100644 --- a/pyci/src/common.cpp +++ b/pyci/src/common.cpp @@ -30,7 +30,7 @@ long get_num_threads(void) { } long end_chunk_idx(const long thread_idx, const long num_threads, const long sideLength) { - return ceil(sqrt(thread_idx / num_threads) * sideLength); + return ceil(static_cast(thread_idx) / static_cast(num_threads) * sideLength); } void set_num_threads(const long n) { From 8bff23beb3867fef0e77108f513fd40f73bff308 Mon Sep 17 00:00:00 2001 From: Peter Reinholdt Date: Mon, 18 Aug 2025 12:32:54 +0200 Subject: [PATCH 2/2] Fix data race --- pyci/src/hci.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pyci/src/hci.cpp b/pyci/src/hci.cpp index e934c845..10ff9d7c 100644 --- a/pyci/src/hci.cpp +++ b/pyci/src/hci.cpp @@ -267,11 +267,9 @@ long add_hci(const SQuantOp &ham, WfnType &wfn, const double *coeffs, const doub v_threads.emplace_back(&hci_thread, std::ref(ham), std::ref(wfn), std::ref(v_wfns.back()), coeffs, eps, start, end); } - long n = 0; - for (auto &thread : v_threads) { - thread.join(); - wfn.add_dets_from_wfn(v_wfns[n++]); - } + for (auto &thread : v_threads) thread.join(); + for (auto &wf : v_wfns) wfn.add_dets_from_wfn(wf); + return wfn.ndet - ndet_old; }