Multi-caliber computation in a bigint array

I am using Chapel and I am trying to do the calculation in an array bigintin a tiered setup. Read a file containing one integer per line. Each row is converted to a record bigint, which is then inserted into a single array. I have 4 locales, and so I ask each locale to read only 1/4 of the input file and process only this part.

I reduced my problem to the following minimal example, which is also affected:

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.");
        }
    }


}


}

I expect locales to perform operations in parallel, but this is not the case.

, . , locale 0 , , 1 . ?

+4
1

-:

/

A file . , . channel , .

, - . , ( ) , , . , C, FILE * - fseek fwrite. - Chapel, -, , , .

, IO :

,

iohints undefined.
...
proc open( out error: syserr, path: string = "", mode: iomode, hints: iohints = IOHINT_NONE, style: iostyle = defaultIOStyle(), url: string = "" ): file

, , / < IOHINT_PARALLEL.

ad-hoc- for line in reader.lines() {...} IO IOHINT_CACHED IOHINT_SEQUENTIAL openreader() channel.

iohints -, . -.

iohints . iohints:

  *  IOHINT_NONE       defines an empty set, which provides no hints.
  *  IOHINT_RANDOM     suggests to expect random access.
  *  IOHINT_SEQUENTIAL suggests to expect sequential access.
  *  IOHINT_CACHED     suggests that the file data is or should be cached
                       in memory, possibly all at once.
  *  IOHINT_PARALLEL   suggests to expect many channels working with this file
                       in parallel.
0

Source: https://habr.com/ru/post/1690439/


All Articles