2

我没有找到域映射如何将多维域中的索引映射到多维目标语言环境。

1.) 目标语言环境(一维)如何以等于分布维度的多维方式排列以映射索引?

2.) 在文档中指出,对于多维情况,计算应该在每个维度上进行。对于域{1..8, 1..8}==> dom 假设dom是块分布在 6 个目标语言环境中。

映射步骤

1 对于第一维(1..8)进行计算
,如果idxlow<=idx<=high然后locid
floor (idx-low)*N / (high-low+1)给我一个索引说i

对第二维重复相同的操作,这给了我一个索引 say j
现在我有一个元组( i, j ) ,它是如何映射到维度 2 的目标语言环境数组的?

域映射如何将一维目标语言环境数组更改为分布维度?

是像重塑功能吗?

如果这缺乏足够的信息,请告诉我。

4

1 回答 1

2

关于域的索引如何映射到程序的语言环境的具体细节不是由 Chapel 语言本身定义的,而是由用于声明域的域映射的实现来定义的。在您的问题下的评论中,您提到您指的是Block分发,因此我将在我的回答中重点关注这一点(在此处记录),但请注意,任何其他域映射都可以采用不同的方法。

Block分布采用一个可选targetLocales参数,允许您指定要定位的语言环境集,以及它们的虚拟拓扑。例如,如果我声明并填充一些语言环境数组:

var grid1: [1..3, 1..2] locale,   // a 3 x 2 array of locales
    grid2: [1..2, 1..3] locale;   // a 2 x 3 array of locales

for i in 1..3 {
  for j in 1..2 {
    grid1[i,j] = Locales[(2*(i-1) + j-1)%numLocales];
    grid2[j,i] = Locales[(3*(j-1) + i-1)%numLocales];
  }
}

然后我可以将它们作为targetLocales参数传递给一个Block分布式域的几个实例:

use BlockDist;

config const n = 8;

const D = {1..n, 1..n},
      D1 = D dmapped Block(D, targetLocales=grid1),
      D2 = D dmapped Block(D, targetLocales=grid2);

每个域将其n行分配到其targetLocales网格的第一个维度,将其n列分配到第二个维度。我们可以通过在这些域上声明整数数组并并行分配它们以使每个元素存储其拥有的区域设置 ID 来查看此分布的结果,如下所示:

var A1: [D1] int,
    A2: [D2] int;

forall a in A1 do
  a = here.id;

forall a in A2 do
  a = here.id;

writeln(A1, "\n");
writeln(A2, "\n");

在六个或更多语言环境 ( ./a.out -nl 6) 上运行时,输出如下,揭示了底层网格结构:

0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
2 2 2 2 3 3 3 3
2 2 2 2 3 3 3 3
2 2 2 2 3 3 3 3
4 4 4 4 5 5 5 5
4 4 4 4 5 5 5 5

0 0 0 1 1 1 2 2
0 0 0 1 1 1 2 2
0 0 0 1 1 1 2 2
0 0 0 1 1 1 2 2
3 3 3 4 4 4 5 5
3 3 3 4 4 4 5 5
3 3 3 4 4 4 5 5
3 3 3 4 4 4 5 5

For a 1-dimensional targetLocales array, the documentation says:

If the rank of targetLocales is 1, a greedy heuristic is used to reshape the array of target locales so that it matches the rank of the distribution and each dimension contains an approximately equal number of indices.

For example, if we distribute to a 1-dimensional 4-element array of locales:

var grid3: [1..4] locale;

for i in 1..4 do
  grid3[i] = Locales[(i-1)%numLocales];

var D3 = D dmapped Block(D, targetLocales=grid3);

var A3: [D3] int;

forall a in A3 do
  a = here.id;

writeln(A3);

we can see that the target locales form a square, as expected:

0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
2 2 2 2 3 3 3 3
2 2 2 2 3 3 3 3
2 2 2 2 3 3 3 3
2 2 2 2 3 3 3 3

The documentation is intentionally vague about how a 1D targetLocales argument will be reshaped if it's not a perfect square, but we can find out what's done in practice by using the targetLocales() query on the domain. Also, note that if no targetLocales array is supplied, the entire Locales array (which is 1D) is used by default. As an illustration of both these things, if the following code is run on six locales:

var D0 = D dmapped Block(D);

writeln(D0.targetLocales());

we get:

LOCALE0 LOCALE1
LOCALE2 LOCALE3
LOCALE4 LOCALE5

illustrating that the current heuristic matches our explicit grid1 declaration above.

于 2017-08-07T23:16:08.280 回答