diff --git a/image_analysis/scale_merge/RotationScaleMerge.cpp b/image_analysis/scale_merge/RotationScaleMerge.cpp index 6132d97db..d941e3c00 100644 --- a/image_analysis/scale_merge/RotationScaleMerge.cpp +++ b/image_analysis/scale_merge/RotationScaleMerge.cpp @@ -1230,14 +1230,17 @@ int RotationScaleMerge::ComputeAsuGroups(const HKLKeyGenerator &keygen) { // The key travels with the run it belongs to, so the sort and the run-detection below read the // key they are standing on instead of chasing it back through `key` - an indirect compare is a // cache miss per comparison, and there are a few tens of millions of them. Which of two runs - // with the SAME key ends up first is left to the sort, and cannot matter: the packed key holds - // h, k, l and the hand exactly, so every run in a tie reduces to the same ASU reflection. + // with the SAME key ends up first cannot matter: the packed key holds h, k, l and the hand + // exactly, so every run in a tie reduces to the same ASU reflection. The tie is still broken on + // the run, so the order is a total one and the sort can go on all threads (ParallelSort). struct RunKey { uint64_t key; int32_t run; }; std::vector sorted; sorted.reserve(n_run); for (int r = 0; r < n_run; ++r) if (eligible[r]) sorted.push_back({key[r], r}); - std::sort(sorted.begin(), sorted.end(), [](const RunKey &a, const RunKey &b) { return a.key < b.key; }); + ParallelSort(sorted.begin(), sorted.end(), nthreads, [](const RunKey &a, const RunKey &b) { + return a.key < b.key || (a.key == b.key && a.run < b.run); + }); // Where a group starts is a property of the sorted keys alone, so mark the starts on all threads and // number them with a prefix - the same ids the append-as-you-go walk handed out. The gemmi ASU