Changes

Jump to: navigation, search

GPU621/Chapel

1,185 bytes added, 00:13, 30 November 2022
File I/O
writeln("SUCCESS");
}
}
This procedure writes a square array out to a file.
 
proc writeSquareArray(n, X, filename) {
 
// Create and open an output file with the specified filename in write mode.
var outfile = open(filename, iomode.cw);
var writer = outfile.writer();
 
// Write the problem size in each dimension to the file.
writer.writeln(n, " ", n);
 
// Write out the array itself.
writer.write(X);
 
// Close the file.
writer.close();
outfile.close();
}
This procedure reads a new array out of a file and returns it.
 
proc readArray(filename) {
// Open an input file with the specified filename in read mode.
var infile = open(filename, iomode.r);
var reader = infile.reader();
// Read the number of rows and columns in the array in from the file.
var m = reader.read(int),
n = reader.read(int);
// Declare an array of the specified dimensions.
var X: [1..m, 1..n] real;
// Read in the array (row-major order is used for whole-array reads
// like this).
reader.read(X);
// Close the file.
reader.close();
infile.close();
// Return the array.
return X;
}
73
edits

Navigation menu