Skip to content

Support sorting arrays of bitsets #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
degawa opened this issue Jun 20, 2023 · 2 comments · Fixed by #723
Closed

Support sorting arrays of bitsets #720

degawa opened this issue Jun 20, 2023 · 2 comments · Fixed by #723
Labels
idea Proposition of an idea and opening an issue to discuss it

Comments

@degawa
Copy link
Contributor

degawa commented Jun 20, 2023

Motivation

Currently, stdlib does not support the sorting of bitset arrays. Support for sorting arrays of bitsets may allow stdlib to apply to modern numerical simulations.

In recent years, adaptive mesh refinement (AMR) has attracted much attention in fluid simulations. In some research aimed at the efficient implementation of AMR, a bit sequence like 11010010 representing the grid position and refinement level is used as an ID for a grid, and the bitset is used to store IDs.
The IDs represented by bitsets are sorted for load balancing in parallel computations. stdlib has bitsets but cannot perform sorting. This prevents the implementation of AMR using stdlib.
Thus, it is worth supporting sorting arrays of bitsets.

Prior Art

Additional Information

stdlib already implements the assignment operator (=) and comparison operators (>, >=, <, <=) for bitsets. So it is easy to support sorting arrays of bitsets by adding a few lines to stdlib_sorting.fypp and related files:

+#! Derived type bitsets
+#:set BITSET_KINDS = ["bitset_64", "bitset_large"]
+
+#! Bitset types to be considered during templating
+#:set BITSET_TYPES = ["type({})".format(k) for k in BITSET_KINDS]
+#:set BITSET_TYPES_ALT_NAME = list(zip(BITSET_TYPES, BITSET_TYPES, BITSET_KINDS))

#! For better code reuse in fypp, make lists that contain the input types,
#! with each having output types and a separate name prefix for subroutines
#! This approach allows us to have the same code for all input types.
-#:set IRSC_TYPES_ALT_NAME = INT_TYPES_ALT_NAME + REAL_TYPES_ALT_NAME + STRING_TYPES_ALT_NAME + CHAR_TYPES_ALT_NAME
+#:set IRSC_TYPES_ALT_NAME = INT_TYPES_ALT_NAME + REAL_TYPES_ALT_NAME + STRING_TYPES_ALT_NAME + CHAR_TYPES_ALT_NAME + BITSET_TYPES_ALT_NAME
@degawa degawa added the idea Proposition of an idea and opening an issue to discuss it label Jun 20, 2023
@jvdp1
Copy link
Member

jvdp1 commented Jun 24, 2023

Thank you @degawa . I think it is a good idea and doable.
It seems that you already identified the changes in stdlib_sorting.fypp. Would you like to give it a try and open a MR?

@degawa
Copy link
Contributor Author

degawa commented Jun 26, 2023

Thank you @jvdp1 for your positive comments.
I'm currently implementing it and will send the pull request soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Proposition of an idea and opening an issue to discuss it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants