Skip to content

Commit 33bfb9a

Browse files
committed
differences for PR #26
1 parent 267d490 commit 33bfb9a

13 files changed

+88
-126
lines changed

.gitkeep

Whitespace-only changes.

01-intro.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Chapel source code must be written in text files with the extension **_.chpl_**.
3535
world"-type program to demonstrate how we write Chapel code! Using your favourite text editor, create the file
3636
`hello.chpl` with the following content:
3737

38-
```chpl
38+
```bash
3939
writeln('If we can see this, everything works!');
4040
```
4141

@@ -46,14 +46,12 @@ chpl --fast hello.chpl
4646
```
4747

4848
The flag `--fast` indicates the compiler to optimise the binary to run as fast as possible in the given
49-
architecture. By default, the compiler will produce a program with the same name
50-
as the source file. In our case, the program will be called `hello`. The `-o`
51-
option can be used to change the name of the generated binary.
49+
architecture. The `-o` option tells Chapel what to call the final output program, in this case `hello.o`.
5250

5351
To run the code, you execute it as you would any other program:
5452

5553
```bash
56-
./hello
54+
./hello.o
5755
```
5856
```output
5957
If we can see this, everything works!
@@ -84,7 +82,7 @@ and then inside that job compile and run the test code
8482

8583
```bash
8684
chpl --fast hello.chpl
87-
./hello
85+
./hello.o
8886
```
8987

9088
For production jobs, you would compile the code and then submit a batch script to the queue:
@@ -139,5 +137,5 @@ So, our objective is to:
139137
::::::::::::::::::::::::::::::::::::: keypoints
140138
- "Chapel is a compiled language - any programs we make must be compiled with `chpl`."
141139
- "The `--fast` flag instructs the Chapel compiler to optimise our code."
142-
- "The `-o` flag tells the compiler what to name our output (otherwise it gets named after the source file)"
140+
- "The `-o` flag tells the compiler what to name our output (otherwise it gets named `a.out`)"
143141
::::::::::::::::::::::::::::::::::::::::::::::::

02-variables.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ In this example, our code is called `operators.chpl`. You can compile it with th
3131

3232
```bash
3333
chpl operators.chpl --fast
34-
./operators
34+
./operators.o
3535
```
3636

3737
You should see output that looks something like the following:
@@ -139,7 +139,7 @@ writeln("counter is ", counter, " and delta is ", delta);
139139
```
140140
```bash
141141
chpl variables.chpl
142-
./variables
142+
./variables.o
143143
```
144144
```output
145145
counter is 0 and delta is 0.0
@@ -154,7 +154,7 @@ writeln('The value of test is ', test, ' and its type is ', test.type:string);
154154
```
155155
```bash
156156
chpl variables.chpl
157-
./variables
157+
./variables.o
158158
```
159159
```output
160160
The value of test is 100 and its type is int(64)

03-ranges-arrays.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ for x in example_range do writeln(x);
2727

2828
```bash
2929
chpl ranges.chpl
30-
./ranges
30+
./ranges.o
3131
```
3232

3333
```output
@@ -66,7 +66,7 @@ writeln('When set to a range: ', example_array);
6666

6767
```bash
6868
chpl ranges.chpl
69-
./ranges
69+
./ranges.o
7070
```
7171

7272
```output
@@ -104,7 +104,7 @@ writeln(example_array);
104104

105105
```bash
106106
chpl ranges.chpl
107-
./ranges
107+
./ranges.o
108108
```
109109

110110
```output
@@ -139,7 +139,7 @@ writeln(example_array);
139139

140140
```bash
141141
chpl ranges.chpl
142-
./ranges
142+
./ranges.o
143143
```
144144

145145
```output

04-conditionals.md

+14-30
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ writeln(1 <= 2);
2828

2929
```bash
3030
chpl conditionals.chpl
31-
./conditionals
31+
./conditionals.o
3232
```
3333

3434
```output
@@ -57,7 +57,7 @@ writeln(true || false);
5757

5858
```bash
5959
chpl conditionals.chpl
60-
./conditionals
60+
./conditionals.o
6161
```
6262

6363
```output
@@ -77,19 +77,12 @@ true
7777
The general syntax of a while statement is:
7878

7979
```chpl
80-
// single-statement form
81-
while condition do
82-
instruction
83-
84-
// multi-statement form
85-
while condition
86-
{
87-
instructions
88-
}
80+
while condition do
81+
{instructions}
8982
```
9083

9184
The code flows as follows: first, the condition is evaluated, and then, if it is satisfied, all the
92-
instructions within the curly brackets or `do` are executed one by one. This will be repeated over and over again
85+
instructions within the curly brackets are executed one by one. This will be repeated over and over again
9386
until the condition does not hold anymore.
9487

9588
The main loop in our simulation can be programmed using a while statement like this
@@ -98,7 +91,7 @@ The main loop in our simulation can be programmed using a while statement like t
9891
//this is the main loop of the simulation
9992
var c = 0;
10093
delta = tolerance;
101-
while (c < niter && delta >= tolerance)
94+
while (c < niter && delta >= tolerance) do
10295
{
10396
c += 1;
10497
// actual simulation calculations will go here
@@ -122,16 +115,9 @@ at the desired position. This is the type of control that an **_if statement_**
122115
is:
123116

124117
```chpl
125-
// single-statement form
126-
if condition then
127-
instruction A
128-
else
129-
instruction B
130-
131-
// multi-statement form
132-
if condition
133-
{instructions A}
134-
else
118+
if condition then
119+
{instructions A}
120+
else
135121
{instructions B}
136122
```
137123

@@ -162,8 +148,6 @@ const y = 50; // column number of the desired position
162148
const tolerance = 0.0001; // smallest difference in temperature that
163149
// would be accepted before stopping
164150
const outputFrequency: int = 20; // the temperature will be printed every outputFrequency iterations
165-
var delta: real; // greatest difference in temperature from one iteration to another
166-
var tmp: real; // for temporary results
167151
168152
// this is our "plate"
169153
var temp: [0..rows+1, 0..cols+1] real = 25;
@@ -174,7 +158,7 @@ writeln('Temperature at start is: ', temp[x, y]);
174158
//this is the main loop of the simulation
175159
var c = 0;
176160
delta = tolerance;
177-
while (c < niter && delta >= tolerance)
161+
while (c < niter && delta >= tolerance) do
178162
{
179163
c += 1;
180164
if (c % outputFrequency == 0)
@@ -186,7 +170,7 @@ while (c < niter && delta >= tolerance)
186170

187171
```bash
188172
chpl base_solution.chpl
189-
./base_solution
173+
./base_solution.o
190174
```
191175

192176
```output
@@ -223,11 +207,11 @@ Of course the temperature is always 25.0 at any iteration other than the initial
223207
computation yet.
224208

225209
::::::::::::::::::::::::::::::::::::: keypoints
226-
- "Use `if <condition> {instructions A} else {instructions B}` syntax to execute one set of instructions
210+
- "Use `if <condition> then {instructions A} else {instructions B}` syntax to execute one set of instructions
227211
if the condition is satisfied, and the other set of instructions if the condition is not satisfied."
228-
- This syntax can be simplified to `if <condition> {instructions}` if we only want to execute the
212+
- This syntax can be simplified to `if <condition> then {instructions}` if we only want to execute the
229213
instructions within the curly brackets if the condition is satisfied.
230-
- "Use `while <condition> {instructions}` to repeatedly execute the instructions within the curly brackets
214+
- "Use `while <condition> do {instructions}` to repeatedly execute the instructions within the curly brackets
231215
while the condition is satisfied. The instructions will be executed over and over again until the condition
232216
does not hold anymore."
233217
::::::::::::::::::::::::::::::::::::::::::::::::

05-loops.md

+10-26
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ a given number of elements, the **_for-loop_** is what we want to use. The for-l
2020
syntax:
2121

2222
```chpl
23-
// single-statement version
2423
for index in iterand do
25-
instruction;
26-
27-
// multi-statement version
28-
for index in iterand
2924
{instructions}
30-
```
25+
```
3126

3227
The *iterand* is a function or statement that expresses an iteration; it could be the range 1..15, for
3328
example. *index* is a variable that exists only in the context of the for-loop, and that will be taking the
@@ -40,7 +35,7 @@ This `for` loop, for example
4035

4136
```chpl
4237
// calculate the new temperatures (temp_new) using the past temperatures (temp)
43-
for i in 1..rows
38+
for i in 1..rows do
4439
{
4540
// do this for every row
4641
}
@@ -52,10 +47,10 @@ this:
5247

5348
```chpl
5449
// calculate the new temperatures (temp_new) using the past temperatures (temp)
55-
for i in 1..rows
50+
for i in 1..rows do
5651
{
5752
// do this for every row
58-
for j in 1..cols
53+
for j in 1..cols do
5954
{
6055
// and this for every column in the row i
6156
}
@@ -67,10 +62,10 @@ follows:
6762

6863
```chpl
6964
// calculate the new temperatures (temp_new) using the past temperatures (temp)
70-
for i in 1..rows
65+
for i in 1..rows do
7166
{
7267
// do this for every row
73-
for j in 1..cols
68+
for j in 1..cols do
7469
{
7570
// and this for every column in the row i
7671
temp_new[i,j] = (temp[i-1,j] + temp[i+1,j] + temp[i,j-1] + temp[i,j+1]) / 4;
@@ -83,17 +78,6 @@ Note that at the end of the outer `for` loop, when all the elements in `temp_new
8378
`temp` with the values of `temp_new`; this way everything is set up for the next iteration of the main `while`
8479
statement.
8580

86-
We're ready to execute our code, but the conditions we have initially set up
87-
will not produce interesting output, because the plate has a temperature
88-
value of `25` everywhere. We can change the boundaries to have temperature `0`
89-
so that the middle will start cooling down. To do this, we should change the
90-
declaration of `temp` to:
91-
92-
```chpl
93-
var temp: [0..rows+1, 0..cols+1] real = 0; // the whole plate starts at 0
94-
temp[1..rows,1..cols] = 25; // set the non-boundary coordinates to 25
95-
```
96-
9781
Now let's compile and execute our code again:
9882

9983
```bash
@@ -255,9 +239,9 @@ the job:
255239
```chpl
256240
// update delta, the greatest difference between temp_new and temp
257241
delta=0;
258-
for i in 1..rows
242+
for i in 1..rows do
259243
{
260-
for j in 1..cols
244+
for j in 1..cols do
261245
{
262246
tmp = abs(temp_new[i,j]-temp[i,j]);
263247
if tmp > delta then delta = tmp;
@@ -353,8 +337,8 @@ The greatest difference in temperatures between the last two iterations was: 0.0
353337

354338
::::::::::::::::::::::::::::::::::::: keypoints
355339
- "You can organize loops with `for` and `while` statements. Use a `for` loop to run over every element of the
356-
iterand, e.g. `for i in 1..rows { ...}` will run over all integers from 1 to `rows`. Use a `while`
340+
iterand, e.g. `for i in 1..rows do { ...}` will run over all integers from 1 to `rows`. Use a `while`
357341
statement to repeatedly execute a code block until the condition does not hold anymore, e.g. `while (c <
358-
niter && delta >= tolerance) {...}` will repeatedly execute the commands in curly braces until one of the
342+
niter && delta >= tolerance) do {...}` will repeatedly execute the commands in curly braces until one of the
359343
two conditions turns false."
360344
::::::::::::::::::::::::::::::::::::::::::::::::

06-procedures.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ procedure and is used to organize the calculations inside the procedure:
6565

6666
```chpl
6767
proc maxOf(x ...?k) { // take a tuple of one type with k elements
68-
var maximum = x[0];
69-
for i in 1..<k do maximum = if maximum < x[i] then x[i] else maximum;
68+
var maximum = x[1];
69+
for i in 2..k do maximum = if maximum < x[i] then x[i] else maximum;
7070
return maximum;
7171
}
7272
```

12-fire-forget-tasks.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ config var numoftasks=2;
302302
303303
writeln("This is the main task: x = ",x);
304304
305-
coforall taskid in 1..numoftasks
305+
coforall taskid in 1..numoftasks do
306306
{
307307
var c=taskid+1;
308308
writeln("this is task ",taskid,": x + ",taskid," = ",x+taskid,". My value of c is: ",c);
@@ -352,7 +352,7 @@ var messages: [1..numoftasks] string;
352352
353353
writeln("This is the main task: x = ", x);
354354
355-
coforall taskid in 1..numoftasks {
355+
coforall taskid in 1..numoftasks do {
356356
var c = taskid + 1;
357357
messages[taskid] = 'this is task ' + taskid:string +
358358
': my value of c is ' + c:string + ' and x is ' + x:string;
@@ -412,7 +412,7 @@ const r = nelem - n*numtasks; // these elements did not fit into the last thread
412412
413413
var d: [1..numtasks] int; // local maxima for each thread
414414
415-
coforall taskid in 1..numtasks {
415+
coforall taskid in 1..numtasks do {
416416
var i, f: int;
417417
i = (taskid-1)*n + 1;
418418
f = (taskid-1)*n + n;
@@ -430,7 +430,7 @@ chpl --fast exercise_coforall_2.chpl
430430
```
431431

432432
```output
433-
the maximum value in x is: 9223372034161572255 # large random integer
433+
the maximum value in x is: 1.0
434434
```
435435

436436
We use the `coforall` loop to spawn tasks that work concurrently in a fraction of the array. The trick here is to

13-synchronization.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ use the following functions:
227227
```chpl
228228
// non-blocking methods
229229
x.reset() //will set the state as empty and the value as the default of x's type
230-
x.isFull //will return true is the state of x is full, false if it is empty
230+
x.isfull() //will return true is the state of x is full, false if it is empty
231231
232232
//blocking read and write methods
233233
x.writeEF(value) //will block until the state of x is empty,

0 commit comments

Comments
 (0)