Changes

Jump to: navigation, search

GPU621/Chapel

4,044 bytes added, 10:59, 30 November 2022
Presenttion
*The begin statement spawns a thread of execution that is independent of the current (main) thread of execution.
writeln("1: ### The begin statement ###");
begin writeln("1: output from spawned task");
 
*The cobegin statement can be used to spawn a block of tasks, one for each statement.
writeln("2: ### The cobegin statement ###");
config const n = 5;
=== Forall loop ===
The forall loop is a way to leverage data parallelism or engage user-defined parallel iterators.
config const n = 5;
var A: [1..n] real;
forall i in 1..n {
A[i] = i;
}
== Library Utilities ==
=== File I/O ===
config var n = 9,
filename = "Arr.dat";
config const num = 128*1024;
config const example = 0;
config const testfile = "test.bin";
config const epsilon = 10e-13;
use FileSystem;
use IO;
It initializes an array and writes its size and data to a file. It then opens the file, uses the size in the file to declare a new domain and array, and reads in the array data.
if example == 0 || example == 1 {
// Create a domain of the specified problem size.
const ADom = {1..n, 1..n};
// Create and initialize an array of the specified size.
var A: [ADom] real = [(i,j) in ADom] i + j/10.0;
// Write the problem size and array out to the specified filename.
writeSquareArray(n, A, filename);
// Read an array in from the specified filename, storing in a new variable, B.
var B = readArray(filename);
// Print out B as a debugging step.
writeln("B is:\n", B);
// Verify that the values in A and B are within tolerance.
const numErrors = + reduce [i in ADom] (abs(A(i) - B(i)) > epsilon);
if (numErrors > 0) {
writeln("FAILURE");
} else {
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;
}
=== List ===
The Chapel List module provides the implementation of the list type. Lists are useful for building up and iterating over a collection of values in a structured manner.
private use List;
config const quiet: bool = false;
*The append() method appends the following element into the array.
*The sort() method sorts the list in ascending order.
*The pop() method pops the element at the specified index.
*The clear() clears all elements from the list.
*The indexOf() retrieves the index of the value specified, returns -1 if not found.
*The insert() method inserts the value at the specified index.
=== Timer ===
The Chapel allows user to use Timer from the timer module.
use Time;
/* Create a Timer t */
var t: Timer;
t.start();
writeln(“Operation start”);
sleep(5);
writeln(“Operation end”);
t.stop();
/* return time in milliseconds that was recorded by the timer */
writeln(t.elapsed(TimeUnits.milliseconds));
t.clear();
 
= Presentation =
*video: https://seneca-my.sharepoint.com/:v:/g/personal/lhuangtang_myseneca_ca/EWl4yNsl02ZGo-b2btiJO8kBNQ_yR2WF124CGAvtbQB0dQ?e=2CD3TR
*PowerPoint: https://docs.google.com/presentation/d/1ZIANDNRD1rRb_WYuBxX2kxDzAqaIm_kI/edit?usp=sharing&ouid=117424265169520381830&rtpof=true&sd=true
= Reference =
73
edits

Navigation menu