Home My Page Projects Code Snippets Project Openings diderot
 Summary Activity Tracker Tasks SCM

# SCM Repository

[diderot] View of /branches/lamont/test/reduction/reduction-test.diderot
 [diderot] / branches / lamont / test / reduction / reduction-test.diderot # View of /branches/lamont/test/reduction/reduction-test.diderot

Wed Mar 13 00:37:12 2013 UTC (6 years, 6 months ago) by lamonts
File size: 1748 byte(s)
`Uploading update reduction-test`
```/*! \file reduction-test.diderot
*
* \author Lamont Samuels
*
* This example tests the global reductions.
*/

/*
* COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
*/
int nNumbers = 10;
real gMean = 0;
real gVar = 0;
real steps = 1;
bool gAll = true;
bool gExists = false;
real gMin = ∞;
real gMax = -∞;
real gProduct = 1;
real gSum = 0;

strand Reduction (int i, real number) {
real num = number;
output real out = 0.0;
int id = i;

update {

if(id == 1 && steps == 34)
new Reduction(nNumbers,25);
if(id == 1 && steps == 15)
new Reduction(nNumbers + 1, 34);

if((id == 1 || id == 2) && steps == 15)
stabilize;

if(steps >= 50) {
//Lamont Note: Strands 1 & 2 have already stabilized so the gMean & gAll should be based only on strand's 1 && 2 values
if(id == 3) {
print("gMean = ", gMean, "\ngVar = ", gVar,
"\ngAll = ", gAll, "\ngExists =", gExists, "\ngProduct = ", gProduct,
"\ngSum = ", gSum, "\ngMin = ", gMin, "\ngMax = ", gMax, "\n");
}
stabilize;
}
}
}

global {
gProduct = product{S.num | S in Reduction.all};
gSum = sum{S.num | S in Reduction.all};
gMin = minr {S.num | S in Reduction.all};
gMax = maxr {S.num | S in Reduction.all};
gExists = exists{S.num > 5 | S in Reduction.all};
gAll = all{S.num > 100 | S in Reduction.stable};
gMean = mean{S.num | S in Reduction.stable};
gVar = variance{ S.num | S in Reduction.all};
steps = steps + 1;
}

initially [ Reduction(vi,vi) | vi in 1..nNumbers];
```

 root@smlnj-gforge.cs.uchicago.edu ViewVC Help Powered by ViewVC 1.0.0