Consolidate duplicate code for generating sort indices.
Add some hdf5 multithreading tests.