summaryrefslogtreecommitdiffhomepage
path: root/chapel.html.markdown
diff options
context:
space:
mode:
authorIan Bertolacci <ian.bertolacci@gmail.com>2015-07-22 19:08:22 -0700
committerIan Bertolacci <ian.bertolacci@gmail.com>2015-07-22 19:08:22 -0700
commit3332ce43bb73dcb850250847c6cffdc396338d5e (patch)
tree157d9c587f1ea65f2bc81d50d51b09543a1892e7 /chapel.html.markdown
parent77daaef8ed6d2fed88405cf038d4e5f0b82dc1ef (diff)
added scans and reductions
Diffstat (limited to 'chapel.html.markdown')
-rw-r--r--chapel.html.markdown19
1 files changed, 19 insertions, 0 deletions
diff --git a/chapel.html.markdown b/chapel.html.markdown
index 520f959d..e058bde9 100644
--- a/chapel.html.markdown
+++ b/chapel.html.markdown
@@ -837,6 +837,25 @@ sync {
someSingleVar$ = 5; // first and only write ever.
}
}
+
+// we can define the operations + * & | ^ && || min max minloc maxloc
+// over an entire array using scans and reductions
+// Reductions apply the operation over the entire array and
+// result in a single value
+var listOfValues: [1..10] int = [456,354,15,57,36,45,15,8,678,2];
+var sumOfValues = + reduce listOfValues;
+var maxValue = max reduce listOfValues; // give just max value
+// gives max value and index of the max value
+var (theMaxValue, idxOfMax) = maxloc reduce zip(listOfValues, listOfValues.domain);
+writeln( (sumOfValues, maxValue, idxOfMax, listOfValues[ idxOfMax ] ) );
+
+// Scans apply the operation incrementally and return an array of the
+// value of the operation at that index as it progressed through the
+// array from array.domain.low to array.domain.high
+var runningSumOfValues = + scan listOfValues;
+var maxScan = max scan listOfValues;
+writeln( runningSumOfValues );
+writeln( maxScan );
```
Who is this tutorial for?