You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-11Lines changed: 12 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# SyncSort: Cross-Architecture Synchronised Sorting of Multiple Arrays
2
2
3
-
While key-value pairs are standard in sorting, oftentimes these keys and values are kept in separate arrays (see Explanation below); we can sort multiple secondary vector following the values of a primary key vector using a new sorting interface:
3
+
While key-value pairs are standard in sorting, oftentimes these keys and values are kept in separate arrays (see Explanation below); we can sort multiple secondary vectors following the values of a primary key vector using a new sorting interface:
# Reordering applied to `ids` will be done in sync with `xcoords` and `ycoords`
14
15
syncsort!(ids, xcoords, ycoords)
15
-
16
16
```
17
17
18
18
19
19
## Explanation
20
+
20
21
Key-value pair sorting assumes an _Array of Structures_ (AoS) format - e.g., a `Vector{Particle}` where `struct Particle` contains some fields `coord::Float64` and `id::Int64`. However, in many applications, it is more performant to store these fields as a _Structure of Arrays_ (SoA), i.e. separate `coords::Vector{Float64` and `ids::Vector{Int64}`.
21
22
22
23
If we had an Array of Structures, using standard sorting interfaces - as is the case in virtually all programming languages - we'd do something like:
23
24
24
25
```julia
25
26
# One primary key and two secondary values
26
27
struct Particle
27
-
id::Int64
28
-
xcoord::Float64
29
-
ycoord::Float64
28
+
id::Int64
29
+
xcoord::Float64
30
+
ycoord::Float64
30
31
end
31
32
32
33
# Array of structures
@@ -39,12 +40,12 @@ sort!(particles; by=p->p.id)
39
40
In high-performance applications, we'd use a Structure of Arrays, where we have separate arrays for our keys and values; the typical solution would involve creating a mask of indices sorting the primary array, in Julia named `sortperm`:
40
41
41
42
```julia
42
-
# Keys and values held in separate, contiguous arrays - could be bundled in a Structure of Arrays
43
+
# Keys and values held in separate vectors
43
44
ids =rand(Int64, 10_000)
44
45
xcoords =rand(Float64, 10_000)
45
46
ycoords =rand(Float64, 10_000)
46
47
47
-
# Get indices permutation that sort the primary array
48
+
# Get indices permutation that sorts the primary array
The CPU sorting routines in `src/cpu_sort.jl` are copied verbatim from the Julia standard library, with some changes to propagate the secondary arrays and follow the swaps done by the standard sorting routines. All credits go to the Julia contributors, with special thanks to @LilithHafner for writing one of the most performant sorting algorithms of [any programming language](https://github.com/LilithHafner/InterLanguageSortingComparisons) - thank you! The Julia license text is included within the file, while this package is shared under the same MIT license.
73
+
The CPU sorting routines in `src/cpu_sort.jl` are copied verbatim from the Julia standard library, with some changes to propagate the secondary arrays and follow the swaps done by the standard sorting routines. All credits go to the Julia contributors, with special thanks to @LilithHafner for writing one of the most performant sorting algorithms of [any programming language](https://github.com/LilithHafner/InterLanguageSortingComparisons) - thank you! The Julia license text is included within the file.
73
74
74
75
75
76
## License
76
77
77
-
This package is shared under the same license as the Julia standard library, MIT.
78
+
This package is shared under the same license as the Julia standard library, MIT.
0 commit comments