Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • qsort() can only swap whole elements of a single array-like object around, so the answer is "no". Commented Jun 14, 2024 at 14:28
  • If you constructed an array of consecutive indices, you could sort that array of indices with the (non-standard) qsort_r function (like qsort but with a context pointer value that also gets passed to the comparison function), using a pointer to the SoA as context. Then you just have the problem of swapping the elements of each array according to the sorted array of indices. It's a bit tricky to do the swapping in-place because in general there will be multiple cyclic chains of elements to be rotated, but there are algorithms to deal with that sort of thing. Commented Jun 14, 2024 at 14:41
  • @ashwin, Why are .n, .size and .numTracers of type ptrdiff_t instead of type size_t? Commented Jun 14, 2024 at 15:15
  • Maybe you can incorporate an index array and sort that helper array instead: tracer[0], tracer[1], ... becomes tracer[helper[0]], tracer[helper[1]], ... keeping tracer[0], tracer[1], ... unmoved Commented Jun 14, 2024 at 15:17
  • @chux-ReinstateMonica, I did this because the fluid arrays will be sent to FFTW library for parallel transforms, which since version 3.x.x, demands that all of its MPI routines take ptrdiff_t arguments instead of int as for the serial FFTW. As per their documentation, ptrdiff_t is a standard C integer type which is (at least) 32 bits wide on a 32-bit machine and 64 bits wide on a 64-bit machine. This is to make it easy to specify very large parallel transforms on a 64-bit machine. Commented Jun 15, 2024 at 3:23