1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
//------------------------------------------------------------------------------
// GB_msort_2: sort a 2-by-n list of integers, using A[0:1][ ] as the key
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// A parallel mergesort of an array of 2-by-n integers. Each key
// consists of two 32-bit or 64-bit unsigned integers.
#include "sort/GB_sort.h"
//------------------------------------------------------------------------------
// GB_msort_2_32_32
//------------------------------------------------------------------------------
#define GB_A0_t uint32_t
#define GB_A1_t uint32_t
#define GB_msort_2_binary_search GB_msort_2_binary_search_32_32
#define GB_msort_2_create_merge_tasks GB_msort_2_create_merge_tasks_32_32
#define GB_msort_2_merge GB_msort_2_merge_32_32
#define GB_msort_2_method GB_msort_2_32_32
#include "sort/factory/GB_msort_2_template.c"
//------------------------------------------------------------------------------
// GB_msort_2_32_64
//------------------------------------------------------------------------------
#undef GB_A0_t
#undef GB_A1_t
#undef GB_msort_2_binary_search
#undef GB_msort_2_create_merge_tasks
#undef GB_msort_2_merge
#undef GB_msort_2_method
#define GB_A0_t uint32_t
#define GB_A1_t uint64_t
#define GB_msort_2_binary_search GB_msort_2_binary_search_32_64
#define GB_msort_2_create_merge_tasks GB_msort_2_create_merge_tasks_32_64
#define GB_msort_2_merge GB_msort_2_merge_32_64
#define GB_msort_2_method GB_msort_2_32_64
#include "sort/factory/GB_msort_2_template.c"
//------------------------------------------------------------------------------
// GB_msort_2_64_32
//------------------------------------------------------------------------------
#undef GB_A0_t
#undef GB_A1_t
#undef GB_msort_2_binary_search
#undef GB_msort_2_create_merge_tasks
#undef GB_msort_2_merge
#undef GB_msort_2_method
#define GB_A0_t uint64_t
#define GB_A1_t uint32_t
#define GB_msort_2_binary_search GB_msort_2_binary_search_64_32
#define GB_msort_2_create_merge_tasks GB_msort_2_create_merge_tasks_64_32
#define GB_msort_2_merge GB_msort_2_merge_64_32
#define GB_msort_2_method GB_msort_2_64_32
#include "sort/factory/GB_msort_2_template.c"
//------------------------------------------------------------------------------
// GB_msort_2_64_64
//------------------------------------------------------------------------------
#undef GB_A0_t
#undef GB_A1_t
#undef GB_msort_2_binary_search
#undef GB_msort_2_create_merge_tasks
#undef GB_msort_2_merge
#undef GB_msort_2_method
#define GB_A0_t uint64_t
#define GB_A1_t uint64_t
#define GB_msort_2_binary_search GB_msort_2_binary_search_64_64
#define GB_msort_2_create_merge_tasks GB_msort_2_create_merge_tasks_64_64
#define GB_msort_2_merge GB_msort_2_merge_64_64
#define GB_msort_2_method GB_msort_2_64_64
#include "sort/factory/GB_msort_2_template.c"
//------------------------------------------------------------------------------
// GB_msort_2
//------------------------------------------------------------------------------
GrB_Info GB_msort_2 // sort array A of size 2-by-n
(
void *restrict A_0, // size n array
bool A0_is_32, // if true: A_0 is uint32, else uint64
void *restrict A_1, // size n array
bool A1_is_32, // if true: A_1 is uint32, else uint64
const int64_t n,
int nthreads_max // max # of threads to use
)
{
//--------------------------------------------------------------------------
// handle small problems with a single thread
//--------------------------------------------------------------------------
int nthreads = GB_nthreads (n, GB_MSORT_BASECASE, nthreads_max) ;
if (nthreads <= 1 || n <= GB_MSORT_BASECASE)
{
// sequential quicksort
GB_qsort_2 (A_0, A0_is_32, A_1, A1_is_32, n) ;
return (GrB_SUCCESS) ;
}
//--------------------------------------------------------------------------
// call the type-specific GB_msort_2 method
//--------------------------------------------------------------------------
if (A0_is_32)
{
if (A1_is_32)
{
return (GB_msort_2_32_32 (A_0, A_1, n, nthreads)) ;
}
else
{
return (GB_msort_2_32_64 (A_0, A_1, n, nthreads)) ;
}
}
else
{
if (A1_is_32)
{
return (GB_msort_2_64_32 (A_0, A_1, n, nthreads)) ;
}
else
{
return (GB_msort_2_64_64 (A_0, A_1, n, nthreads)) ;
}
}
}
|