教堂迭代

时间:2017-04-13 00:47:45

标签: parallel-processing chapel

当前正在处理 并尝试迭代类型为:eltType的数组 {renderLinkIf( <span><span className={sectionCompleted(30) ? 'completed' : null}> {sectionCompleted(30) ? <CheckIcon /> : <HeaderPersonalInfo />} </span> Personal Info</span>, true, '/dashboard', )} ,并且其中包含元素。

我正在尝试遍历整个数组hi并打印出每个元素,所以我正在做:

hi

当我尝试时,我收到此错误:

  

无法迭代int(64)类型的值

不确定如何迭代它或为什么会发生这种错误 任何想法或指南?我一直在看Chapel API。

1 个答案:

答案 0 :(得分:4)

您的代码示例有一个错误,因为'hi'是一个整数(存储数组的大小)。你可能意味着'forall i in 1..hi'。无论哪种方式,这里都是一个代码清单,其中包含一些用于此类迭代的常见模式。

// Declare a 1-D array storing 10, 20, 30
// Such array literals start at index 1
var elements = [10,20,30];

// Note: elements.domain is the index set of the array;
// in this case {1..3}.

writeln("loop 1");
// iterate over range, accessing elements
for i in 1..elements.size {
  writeln("Index: ", i, " Element: ", elements[i]);
}

writeln("loop 2");
// as above, but in parallel (output order will differ run to run)
forall i in 1..elements.size {
  writeln("Index: ", i, " Element: ", elements[i]);
}

writeln("loop 3");
// zippered iteration to iterate over array, indexes at once
for (element,i) in zip(elements,elements.domain) {
  writeln("Index: ", i, " Element: ", element);
}

writeln("loop 4");
// as above, but in parallel (output order will differ run to run)
forall (element,i) in zip(elements,elements.domain) {
  writeln("Index: ", i, " Element: ", element);
}

另见

http://chapel.cray.com/docs/latest/users-guide/base/forloops.html

http://chapel.cray.com/docs/latest/users-guide/base/zip.html

http://chapel.cray.com/docs/latest/primers/ranges.html