Skip to content

Commit

Permalink
Support for reading zarr stores with a custom locale distribution (ch…
Browse files Browse the repository at this point in the history
…apel-lang#25803)

This PR adds support for customizing the distribution of Zarr stores
across locales with an `targetLocale` argument. This will help with
getting reasonable distributions for stores that have small sizes in the
first dimension.

Tested locally and on chapdl with none and gasnet comms

Reviewed by: @benharsh
  • Loading branch information
brandon-neth authored Aug 23, 2024
2 parents 63c0b95 + 113e8d1 commit 0448cc2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/packages/Zarr.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ module Zarr {
:arg dimCount: Dimensionality of the zarr array
*/
proc readZarrArray(directoryPath: string, type dtype, param dimCount: int, bloscThreads: int(32) = 1) throws {
proc readZarrArray(directoryPath: string, type dtype, param dimCount: int, bloscThreads: int(32) = 1, targetLocales: [] locale = Locales) throws {
var md = getMetadata(directoryPath);
validateMetadata(md, dtype, dimCount);
// Size and shape tuples
Expand All @@ -365,7 +365,7 @@ module Zarr {

// Initialize the distributed domain and array
const undistD : domain(dimCount) = totalRanges;
const Dist = new blockDist(boundingBox=undistD);
const Dist = new blockDist(boundingBox=undistD, targetLocales=targetLocales);
const D = Dist.createDomain(undistD);
var A: [D] dtype;

Expand Down
5 changes: 5 additions & 0 deletions test/library/packages/Zarr/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ Test3D
c-blosc
*.dylib
*.so*
*.dll*
LocalIOStore_*
TestLocal
TestTargetLocale

2 changes: 2 additions & 0 deletions test/library/packages/Zarr/CLEANFILES
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Test1D
Test2D
Test3D
LocalIOStore_*
TestLocal
TestTargetLocale
39 changes: 39 additions & 0 deletions test/library/packages/Zarr/ZarrTargetLocale.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use Zarr;
use Random;
use BlockDist;
use IO;


const D = {0..<10, 0..<10};
var A: [D] real(32);
fillRandom(A);

// write the store that we will read in a distributed fashion
writeZarrArrayLocal("TestTargetLocale", A, (3,3));

// read with the default
var defaultArray = readZarrArray("TestTargetLocale", real(32), 2);

// read with custom locale distribution
const myTargetLocales = reshape(Locales, {0..0, 0..#numLocales});
var targetedArray = readZarrArray("TestTargetLocale", real(32), 2, targetLocales=myTargetLocales);

on Locales[0] {
var defaultLocale0 = defaultArray.localSubdomain();
assert(defaultLocale0 == {0..<5, 0..<10}, "Locale 0 subdomain incorrect for default locale distribution: %?".format(defaultLocale0));
var targetLocale0 = targetedArray.localSubdomain();
assert(targetLocale0 == {0..<10, 0..<5}, "Locale 0 subdomain incorrect for targeted locale distribution: %?".format(targetLocale0));
}

on Locales[1] {
var defaultLocale1 = defaultArray.localSubdomain();
assert(defaultLocale1 == {5..<10, 0..<10}, "Locale 1 subdomain incorrect for default locale distribution: %?".format(defaultLocale1));
var targetLocale1 = targetedArray.localSubdomain();
assert(targetLocale1 == {0..<10, 5..<10}, "Locale 1 subdomain incorrect for targeted locale distribution: %?".format(targetLocale1));
}

for i in D {
assert(defaultArray[i] == A[i], "Default locale distribution read incorrect at index %?".format(i));
assert(targetedArray[i] == A[i], "Targeted locale distribution read incorrect at index %?".format(i));
}
writeln("Pass");
1 change: 1 addition & 0 deletions test/library/packages/Zarr/ZarrTargetLocale.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pass
1 change: 1 addition & 0 deletions test/library/packages/Zarr/ZarrTargetLocale.numlocales
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
1 change: 1 addition & 0 deletions test/library/packages/Zarr/ZarrTargetLocale.skipif
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHPL_COMM==none

0 comments on commit 0448cc2

Please sign in to comment.