diff --git a/heat_equation/src/multiple_machines.chpl b/heat_equation/src/multiple_machines.chpl index aaccf3960655587bbbd719b79e217fb55dad7e7c..a414ca96ea69f8a659803f0ef3c9a69ef12e6d01 100644 --- a/heat_equation/src/multiple_machines.chpl +++ b/heat_equation/src/multiple_machines.chpl @@ -1,8 +1,23 @@ -use BlockDist; - -config const n = 8;//Size of the domain squired +//The format of 'size' is two integers separated with a '*'. +//The first integer is the domain size squired and the second integer is +//the number of iterations. +config const size = "100*10";//Default, 100 by 100 domain and 10 iterations config const epsilon = 1.0e-10;//Stop condition in amount of change -config var iterations = 1000;//Stop condition in number of iterations + +//Parse the --size argument into 'n' and 'iterations' +use Regexp; +const arg = size.matches(compile("(\\d+)*(\\d+)")); +const n = size.substring(arg[1][1]) : int; +const iterations = size.substring(arg[2][1]) : int; + +//Initiate a Timer object +use Time; +var timer : Timer; + +//Now, let's implement the heat equation! + +//We will use the Block distribution +use BlockDist; //A n+2 by n+2 domain. const Grid = {0..n+1, 0..n+1} dmapped Block({1..n, 1..n}); @@ -17,8 +32,9 @@ A[..,n+1] = -273.15; //Right column A[n+1,..] = -273.15; //Bottom row A[0,..] = 40.0; //Top row +timer.start(); +var iter_count = 0; do{ - //Since all iterations are independent, we can use 'forall', which allows //the Chapel runtime system to calculate the iterations in parallel forall (i,j) in Interior do//Iterate over all non-border cells @@ -34,7 +50,12 @@ do{ A[Interior] = T[Interior]; //When 'delta' is smaller than 'epsilon' the calculation has converged - iterations -= 1; -} while (delta > epsilon && iterations > 0); + iter_count += 1; +} while (delta > epsilon && iter_count >= iterations); + +timer.stop(); +writeln("Heat Equation (multiple machines) - n: ",n, + ", iterations: ", iterations, + ", elapsed: ", timer.elapsed(), " seconds"); diff --git a/heat_equation/src/sequential.chpl b/heat_equation/src/sequential.chpl index 968d49179f4fe92eaba9094d1d4ded04e8b0b3a5..776e86eb1f352698f4926f27961e8083d0d50f2f 100644 --- a/heat_equation/src/sequential.chpl +++ b/heat_equation/src/sequential.chpl @@ -1,6 +1,20 @@ -config const n = 8;//Size of the domain squired +//The format of 'size' is two integers separated with a '*'. +//The first integer is the domain size squired and the second integer is +//the number of iterations. +config const size = "100*10";//Default, 100 by 100 domain and 10 iterations config const epsilon = 1.0e-10;//Stop condition in amount of change -config var iterations = 1000;//Stop condition in number of iterations + +//Parse the --size argument into 'n' and 'iterations' +use Regexp; +const arg = size.matches(compile("(\\d+)*(\\d+)")); +const n = size.substring(arg[1][1]) : int; +const iterations = size.substring(arg[2][1]) : int; + +//Initiate a Timer object +use Time; +var timer : Timer; + +//Now, let's implement the heat equation! //A n+2 by n+2 domain. const Grid = {0..n+1, 0..n+1}; @@ -15,8 +29,9 @@ A[..,n+1] = -273.15; //Right column A[n+1,..] = -273.15; //Bottom row A[0,..] = 40.0; //Top row +timer.start(); +var iter_count = 0; do{ - //Since all iterations are independent, we can use 'forall', which allows //the Chapel runtime system to calculate the iterations in parallel for (i,j) in Interior do//Iterate over all non-border cells @@ -32,7 +47,12 @@ do{ A[Interior] = T[Interior]; //When 'delta' is smaller than 'epsilon' the calculation has converged - iterations -= 1; -} while (delta > epsilon && iterations > 0); + iter_count += 1; +} while (delta > epsilon && iter_count >= iterations); + +timer.stop(); +writeln("Heat Equation (sequential) - n: ",n, + ", iterations: ", iterations, + ", elapsed: ", timer.elapsed(), " seconds"); diff --git a/heat_equation/src/single_machine.chpl b/heat_equation/src/single_machine.chpl index 9453d755e78c20ec37b91249015e9905154460ac..e3f147c5290e88c2e2fa254dbd6166656e9c7d37 100644 --- a/heat_equation/src/single_machine.chpl +++ b/heat_equation/src/single_machine.chpl @@ -1,6 +1,20 @@ -config const n = 8;//Size of the domain squired +//The format of 'size' is two integers separated with a '*'. +//The first integer is the domain size squired and the second integer is +//the number of iterations. +config const size = "100*10";//Default, 100 by 100 domain and 10 iterations config const epsilon = 1.0e-10;//Stop condition in amount of change -config var iterations = 1000;//Stop condition in number of iterations + +//Parse the --size argument into 'n' and 'iterations' +use Regexp; +const arg = size.matches(compile("(\\d+)*(\\d+)")); +const n = size.substring(arg[1][1]) : int; +const iterations = size.substring(arg[2][1]) : int; + +//Initiate a Timer object +use Time; +var timer : Timer; + +//Now, let's implement the heat equation! //A n+2 by n+2 domain. const Grid = {0..n+1, 0..n+1}; @@ -15,8 +29,9 @@ A[..,n+1] = -273.15; //Right column A[n+1,..] = -273.15; //Bottom row A[0,..] = 40.0; //Top row +timer.start(); +var iter_count = 0; do{ - //Since all iterations are independent, we can use 'forall', which allows //the Chapel runtime system to calculate the iterations in parallel forall (i,j) in Interior do//Iterate over all non-border cells @@ -32,7 +47,12 @@ do{ A[Interior] = T[Interior]; //When 'delta' is smaller than 'epsilon' the calculation has converged - iterations -= 1; -} while (delta > epsilon && iterations > 0); + iter_count += 1; +} while (delta > epsilon && iter_count >= iterations); + +timer.stop(); +writeln("Heat Equation (single machine) - n: ",n, + ", iterations: ", iterations, + ", elapsed: ", timer.elapsed(), " seconds");