From da38ae03707902a3104745f23121297fb65540be Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Oct 2018 08:57:33 -0400 Subject: [PATCH] apply fix for merge sort from issue #1163 by @jtfrey and re-enable it --- src/lmptype.h | 7 ------- src/mergesort.h | 6 +++++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lmptype.h b/src/lmptype.h index 7c3dbc1c3d..4743a38837 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -46,13 +46,6 @@ #define PRId64 "ld" #endif -// favor qsort over mergesort for stable release -// TODO: to be removed after stable release - -#ifndef LMP_QSORT -#define LMP_QSORT -#endif - namespace LAMMPS_NS { // enum used for KOKKOS host/device flags diff --git a/src/mergesort.h b/src/mergesort.h index 50addd0a72..edb745922f 100644 --- a/src/mergesort.h +++ b/src/mergesort.h @@ -98,7 +98,7 @@ static void merge_sort(int *index, int num, void *ptr, int *tmp = dest; dest = hold; hold = tmp; - // merge from hold array to destiation array + // merge from hold array to destination array for (i=0; i < num-1; i += 2*chunk) { j = i + 2*chunk; @@ -107,6 +107,10 @@ static void merge_sort(int *index, int num, void *ptr, if (m > num) m=num; do_merge(dest,hold,i,m,m,j,ptr,comp); } + + // copy all indices not handled by the chunked merge sort loop + + for ( ; i < num ; i++ ) dest[i] = hold[i]; chunk *= 2; }