在 Chapel 中的 Locales 之间按行分布二维数组
Distribute 2D array row wise among Locales in Chapel
我正在学习 Chapel 并使用过 blockdist,但我不知道如何在语言环境中以行方式分布二维数组。
关键是将重塑的 Locales
数组作为 targetLocales
参数传递给 Block
。这将在下面进一步解释。
这是一个以行方式分布二维数组的简单示例:
use BlockDist;
// Using a 2D targetLocales rather than the default 1D Locales argument
var targetLocales = reshape(Locales, {0..#numLocales, 0..0});
const Space = {1..4, 1..4};
const D: domain(2) dmapped Block(boundingBox=Space, targetLocales=targetLocales) = Space;
var A: [D] int;
forall a in A do
a = a.locale.id;
writeln(A);
示例输出:
./row-wise -nl 4
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
./row-wise -nl 2
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
默认情况下,发行版将使用内置 Locales
array as the targetLocales
argument, which specifies how to paritition the elements of an array across the locales within a particular domain map, e.g. Block
。
由于 Locales
是一个一维数组,而您正在分发一个二维数组,因此 Block
分发会像这样包装 Locales
:
1D targetLocales:
0 1 2 3 -> 0 1
2 3
因此,形状为 (4,4)
的数组将映射到 4 个语言环境,如:
0 0 1 1
0 0 1 1
2 2 3 3
2 2 3 3
通过提供 2D targetLocales
参数,我们可以明确地告诉 Block
我们希望如何将元素映射到语言环境,而不是依赖包装。传递形状为 (4,1)
的 targetLocales
语言环境数组将导致所需的按行分布:
2D targetLocales:
0
1
2
3
因此,形状为 (4,4)
的数组将映射到 4 个语言环境,如:
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
这个概念也适用于其他distributions。
我正在学习 Chapel 并使用过 blockdist,但我不知道如何在语言环境中以行方式分布二维数组。
关键是将重塑的 Locales
数组作为 targetLocales
参数传递给 Block
。这将在下面进一步解释。
这是一个以行方式分布二维数组的简单示例:
use BlockDist;
// Using a 2D targetLocales rather than the default 1D Locales argument
var targetLocales = reshape(Locales, {0..#numLocales, 0..0});
const Space = {1..4, 1..4};
const D: domain(2) dmapped Block(boundingBox=Space, targetLocales=targetLocales) = Space;
var A: [D] int;
forall a in A do
a = a.locale.id;
writeln(A);
示例输出:
./row-wise -nl 4
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
./row-wise -nl 2
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
默认情况下,发行版将使用内置 Locales
array as the targetLocales
argument, which specifies how to paritition the elements of an array across the locales within a particular domain map, e.g. Block
。
由于 Locales
是一个一维数组,而您正在分发一个二维数组,因此 Block
分发会像这样包装 Locales
:
1D targetLocales:
0 1 2 3 -> 0 1
2 3
因此,形状为 (4,4)
的数组将映射到 4 个语言环境,如:
0 0 1 1
0 0 1 1
2 2 3 3
2 2 3 3
通过提供 2D targetLocales
参数,我们可以明确地告诉 Block
我们希望如何将元素映射到语言环境,而不是依赖包装。传递形状为 (4,1)
的 targetLocales
语言环境数组将导致所需的按行分布:
2D targetLocales:
0
1
2
3
因此,形状为 (4,4)
的数组将映射到 4 个语言环境,如:
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
这个概念也适用于其他distributions。