Home My Page Projects Code Snippets Project Openings diderot

# 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

Tue Oct 27 15:16:36 2015 UTC (4 years, 7 months ago) by jhr
File size: 2615 byte(s)
`making copyrights consistent for all code in the repository`
```/*! \file reduction-test.diderot
*
* \author Lamont Samuels
*
* This example tests the global reductions.
*/

/*
* This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
*
* COPYRIGHT (c) 2015 The University of Chicago
*/
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 == 3 && steps == 34) {
new Reduction(nNumbers+1,25);
}
if(id == 3 && steps == 15) {
new Reduction(nNumbers + 2, 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
print("id = ", id, "\n");
if(id == 3) {
print("gMean = ", gMean, "\ngVar = ", gVar,
"\ngAll = ", gAll, "\ngExists =", gExists, "\ngProduct = ", gProduct,
"\ngSum = ", gSum, "\ngMin = ", "\n"); // gMin, "\ngMax = ", gMax, "\n");
}
stabilize;
}
}
}

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

update {
if(steps ==1) {
new Reduction(id + nNumbers,25);
}

if(steps >= 2) {
//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 {
bool t = false;
gAll = all{S.num < 100 | S in Reduction.all};
gProduct = product{S.num | S in Reduction.all};
gSum = sum{S.num | S in Reduction.all};
// gMin = min{S.num | S in Reduction.all};
// gMax = max{S.num | S in Reduction.all};

gExists = t || exists{S.num < 3 | S in Reduction.active};
gMean = mean{S.num | S in Reduction.stable};
// gVar = variance{ S.num | S in Reduction.all};
gVar = 10.04;
steps = steps + 1;
}

initially { Reduction(vi,vi) | vi in 1..nNumbers};
```