【问题标题】:Chapel - Ranges defined using bounds of type 'range(int(64),bounded,false)' are not currently supportedChapel - 目前不支持使用 \'range(int(64),bounded,false)\' 类型的边界定义的范围
【发布时间】:2022-11-29 14:20:42
【问题描述】:

当我尝试编译此 5 点模板基准测试代码时,标题“当前不支持使用类型为‘range(int(64),bounded,false)’的边界定义的范围”显示为错误。是什么原因造成的?我用的是chapel 1.8.2,只编译程序不显示。

use Time;
use IO;

/* Use ./2dstencil --n=20000 --iterations=5 to run with different arguments. */
config const n: int = 10000;
config const iterations: int = 10;

const constants = [[0.0, 0.5, 0.0],
                   [0.5, 0.5, 0.5],
                   [0.0, 0.5, 0.0]];

proc relax(input: [1..n, 1..n] real)
{
    var output: [1..n, 1..n] real;

    /* Inner part */
    forall i in [2..n - 1] do
        forall j in [2..n - 1] do
            output[i, j] = + reduce (input[i - 1..i + 1, j - 1..j + 1] * constants);

    /* Boundary */
    output[1, 1..n] = input[1, 1..n];
    output[n, 1..n] = input[n, 1..n];
    output[1..n, 1] = input[1..n, 1];
    output[1..n, n] = input[1..n, n];

    return output;
}

proc stencil(input: [1..n, 1..n] real)
{
    var copy: [1..n, 1..n] real = input;

    for t in [1..iterations] do
        input = relax(input);

    return input;
}

var input: [1..n, 1..n] real = 1;
var watch: Timer;
watch.start();

input = stencil(input);
watch.stop();
stderr.writeln('Anti-optimisation number: ', + reduce input, '\n');

stdout.writeln(watch.elapsed(), '\n');

【问题讨论】:

    标签: chapel


    【解决方案1】:

    这有点微妙,但问题的原因是以下循环:

        forall i in [2..n - 1] do
            forall j in [2..n - 1] do
    

    具体来说,我相信你写这些是为了让 i 和 j 成为从 2 到 n-1 循环的整数变量。为了获得该行为,您需要从这些表达式中删除方括号,原因如下:

    Chapel 中的语法 [expr-list] 表示一个数组文字,其元素是方括号之间的表达式。例如,forall i in [1, 3, 5, 4, 6] 将遍历该数组文字表示的整数。在您的代码中,您正在遍历范围值的 1 元素数组,其单个元素是范围 2..n-1。因此,ij 都是表示范围2..n-1 的范围变量。

    然后,在循环体中,当尝试计算表达式 i - 1..i + 1j - 1..j + 1 时,编译器会抱怨由 .. 运算符构造的范围的边界本身就是范围,而不是其他一些受支持的类型(如整数或枚举)。

    要看到这个,try the following code

    forall i in [2..n-1] do
      writeln(i, ": ", i.type:string);
    

    打印为输出:

    2..99: range(int(64),bounded,false)
    

    或者this one

    config var n = 100;
    
    var r = (1..n)..(1..n);
    

    它会打印出与您收到的错误类似的错误。

    这里发生的另一件事是范围支持 +/- 运算符采用整数值,这会导致范围的转换。因此,i + 1,其中 i 是一个单位步幅范围,实际上变成了i.low+1..i.high+1

    由于这种微妙之处,我打开了this issue,询问 Chapel 是否应该要求在单元素数组文字中使用尾随逗号,就像今天对单元素元组所做的那样。

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2022-11-14
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      相关资源
      最近更新 更多