我正在使用 Chapel,并且正在尝试在多bigint
语言环境设置中对数组执行计算。读取每行包含一个整数的文件。每行都转换为一条bigint
记录,然后插入到单个数组中。我有 4 个语言环境,因此我要求每个语言环境仅读取输入文件的 1/4 并仅处理该部分。
我已将问题减少到以下最小示例,该示例也受到影响:
module Hello {
use BigInteger;
use Math;
use Time;
config const inputPath = "/path/to/file";
config const inputSize = 10000000;
config const power = 2000;
proc dwriteln(args ...?n) {
var curr = getCurrentTime(unit=TimeUnits.seconds);
writeln("[ ", here.id, ": ", here.name, " ] [ ", curr, " ] ", (...args));
}
proc main() throws {
writeln("Input path: ", inputPath);
writeln("numLocales: ", numLocales);
var elementsPerLocale = divceil(inputSize, numLocales);
writeln("elementsPerLocale: ", elementsPerLocale);
coforall loc in Locales {
on loc {
dwriteln("hello");
var inputFile = open(inputPath, iomode.r, hints=IOHINT_CACHED);
var reader = inputFile.reader();
var startI = here.id * elementsPerLocale;
var endI = startI+elementsPerLocale;
dwriteln("startI = ", startI, " endI= ", endI);
var a: [1..0] bigint;
var i = 0;
for line in reader.lines() {
// i in [startI;endI[
if i >= startI && i < endI {
a.push_back(new bigint(line, 16));
}
i +=1;
}
reader.close();
inputFile.close();
dwriteln("created array of size: ", a.size);
forall elem in a {
// perform some computation
elem = elem ** power;
}
dwriteln("Computed.");
}
}
}
}
我希望语言环境可以并行执行操作,但事实并非如此。
但是,在运行代码时,似乎每个语言环境都按顺序进行处理。换句话说,语言环境 0 读取文件并进行处理,然后语言环境 1 读取文件并进行处理,依此类推。这可能是什么原因?