Skip to content

Commit

Permalink
Merge pull request boutproject#2045 from boutproject/fix-examples-war…
Browse files Browse the repository at this point in the history
…nings

Fix examples warnings
  • Loading branch information
ZedThree authored May 30, 2020
2 parents 51151e5 + 4f3f78f commit ee6e9da
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 191 deletions.
6 changes: 3 additions & 3 deletions examples/boundary-conditions/advection/advection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class Advection : public PhysicsModel {

protected:
/// Initialise, specify evolving variables
int init(bool restarting) {
int init(bool) {
// Solve for a single variable (f)
SOLVE_FOR(f);
return 0;
}

/// Calculate time derivatives
///
/// df/dt = 1 * df/dy
///
/// Implemented using Vpar_Grad_par so
/// the method can be changed in the input
int rhs(BoutReal t) {
int rhs(BoutReal) {
mesh->communicate(f);

ddt(f) = -Vpar_Grad_par(Field2D(1.0), f);
Expand Down
6 changes: 2 additions & 4 deletions examples/constraints/alfven-wave/alfven.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class Alfven : public PhysicsModel {
std::unique_ptr<Laplacian> phiSolver{nullptr}; // Old Laplacian in X-Z
std::unique_ptr<LaplaceXZ> newSolver{nullptr}; // New Laplacian in X-Z
protected:

int init(bool restarting) {

int init(bool) {
// Normalisation
auto opt = Options::root()["alfven"];
Tnorm = opt["Tnorm"].withDefault(100); // Reference temperature [eV]
Expand Down Expand Up @@ -151,7 +149,7 @@ class Alfven : public PhysicsModel {
*
* ddt(f) = Result of the inversion
*/
int precon(BoutReal t, BoutReal gamma, BoutReal delta) {
int precon(BoutReal, BoutReal, BoutReal) {
if(newXZsolver) {
ddt(phi) = newSolver->solve(ddt(phi) - ddt(Vort), 0.0);
}else {
Expand Down
4 changes: 2 additions & 2 deletions examples/performance/arithmetic/arithmetic.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct Durations {

class Arithmetic : public PhysicsModel {
protected:
int init(bool restarting) {
int init(bool) {

Field3D a = 1.0;
Field3D b = 2.0;
Expand Down Expand Up @@ -92,7 +92,7 @@ class Arithmetic : public PhysicsModel {
SOLVE_FOR(n);
return 0;
}

int rhs(BoutReal) {
ddt(n) = 0;
return 0;
Expand Down
34 changes: 18 additions & 16 deletions examples/performance/arithmetic_3d2d/arithmetic_3d2d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,41 @@

#include <bout/expr.hxx>

#include <algorithm>
#include <chrono>
#include <iomanip>

using SteadyClock = std::chrono::time_point<std::chrono::steady_clock>;
using Duration = std::chrono::duration<double>;
using namespace std::chrono;

#define TIMEIT(NAME, ...) \
{ \
SteadyClock start = steady_clock::now(); \
__VA_ARGS__ \
Duration diff = steady_clock::now() - start; \
auto elapsed = elapsedMap[NAME];\
elapsed.min = diff > elapsed.min ? elapsed.min : diff; \
elapsed.max = diff < elapsed.max ? elapsed.max : diff; \
elapsed.count++; \
elapsed.avg = elapsed.avg * (1 - 1. / elapsed.count) + diff / elapsed.count; \
elapsedMap[NAME] = elapsed; \
#define TIMEIT(NAME, ...) \
{ \
SteadyClock start = steady_clock::now(); \
__VA_ARGS__ \
Duration diff = steady_clock::now() - start; \
auto elapsed = elapsedMap[NAME]; \
elapsed.min = std::min(diff, elapsed.min); \
elapsed.max = std::max(diff, elapsed.max); \
elapsed.count++; \
elapsed.avg = elapsed.avg * (1 - 1. / elapsed.count) + diff / elapsed.count; \
elapsedMap[NAME] = elapsed; \
}

struct Durations {
Duration max;
Duration min;
Duration avg;
int count;
Durations(): min(Duration::max()), max(Duration::min()), avg(Duration::zero()), count(0) {};
Durations()
: max(Duration::min()), min(Duration::max()), avg(Duration::zero()), count(0){};
};

class Arithmetic : public PhysicsModel {
protected:
std::map<std::string, Durations> elapsedMap;
int init(bool restarting) {

int init(bool) {
Field3D a = 1.0;
Field3D b = 2.0;
Field2D c = 3.0;
Expand Down Expand Up @@ -81,7 +83,7 @@ class Arithmetic : public PhysicsModel {
}

output.enable();
int width = 15;
constexpr int width = 15;
output<<std::setw(width)<<"TIMING";
output<<std::setw(width)<<"min";
output<<std::setw(width)<<"avg";
Expand All @@ -101,7 +103,7 @@ class Arithmetic : public PhysicsModel {
SOLVE_FOR(n);
return 0;
}

int rhs(BoutReal) {
ddt(n) = 0;
return 0;
Expand Down
10 changes: 5 additions & 5 deletions examples/performance/bracket/bracket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int main(int argc, char **argv) {
time_output << "Case legend";
time_output << "\n------------------------------------------------\n";

for (int i = 0; i < names.size(); i++) {
for (std::size_t i = 0; i < names.size(); i++) {
time_output << std::setw(width) << "Case " << i << ".\t" << names[i] << "\n";
}
time_output << "\n";
Expand All @@ -128,7 +128,7 @@ int main(int argc, char **argv) {
<< "\t";
time_output << std::setw(width) << "Nz (global)"
<< "\t";
for (int i = 0; i < names.size(); i++) {
for (std::size_t i = 0; i < names.size(); i++) {
time_output << std::setw(width) << "Case " << i << "\t";
}
time_output << "\n";
Expand All @@ -141,12 +141,12 @@ int main(int argc, char **argv) {
time_output << std::setw(width) << mesh->GlobalNx << "\t";
time_output << std::setw(width) << mesh->GlobalNy << "\t";
time_output << std::setw(width) << mesh->GlobalNz << "\t";
for (int i = 0; i < names.size(); i++) {
for (std::size_t i = 0; i < names.size(); i++) {
time_output << std::setw(width) << times[i].count() / NUM_LOOPS << "\t";
}
time_output << "\n";
} else {
int width = 0;
std::size_t width = 0;
for (const auto i : names) {
width = i.size() > width ? i.size() : width;
};
Expand All @@ -155,7 +155,7 @@ int main(int argc, char **argv) {
<< "\t"
<< "Time per iteration (s)"
<< "\n";
for (int i = 0; i < names.size(); i++) {
for (std::size_t i = 0; i < names.size(); i++) {
time_output << std::setw(width) << names[i] << "\t" << times[i].count() / NUM_LOOPS
<< "\n";
}
Expand Down
29 changes: 7 additions & 22 deletions examples/performance/ddx/ddx.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,16 @@ int main(int argc, char **argv) {
result = DDX(a);
);

ITERATOR_TEST_BLOCK(
"DDX C2",
result = DDX(a, CELL_DEFAULT, DIFF_C2);
);
ITERATOR_TEST_BLOCK("DDX C2", result = DDX(a, CELL_DEFAULT, "DIFF_C2"););

ITERATOR_TEST_BLOCK(
"DDX C4",
result = DDX(a, CELL_DEFAULT, DIFF_C4);
);

ITERATOR_TEST_BLOCK(
"DDX S2",
result = DDX(a, CELL_DEFAULT, DIFF_S2);
);
ITERATOR_TEST_BLOCK("DDX C4", result = DDX(a, CELL_DEFAULT, "DIFF_C4"););

ITERATOR_TEST_BLOCK(
"DDX W2",
result = DDX(a, CELL_DEFAULT, DIFF_W2);
);
ITERATOR_TEST_BLOCK("DDX S2", result = DDX(a, CELL_DEFAULT, "DIFF_S2"););

ITERATOR_TEST_BLOCK("DDX W2", result = DDX(a, CELL_DEFAULT, "DIFF_W2"););

ITERATOR_TEST_BLOCK("DDX W3", result = DDX(a, CELL_DEFAULT, "DIFF_W3"););

ITERATOR_TEST_BLOCK(
"DDX W3",
result = DDX(a, CELL_DEFAULT, DIFF_W3);
);

if (profileMode) {
int nthreads = 0;
#ifdef _OPENMP
Expand Down
29 changes: 7 additions & 22 deletions examples/performance/ddy/ddy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,16 @@ int main(int argc, char **argv) {
result = DDY(a);
);

ITERATOR_TEST_BLOCK(
"DDY C2",
result = DDY(a, CELL_DEFAULT, DIFF_C2);
);
ITERATOR_TEST_BLOCK("DDY C2", result = DDY(a, CELL_DEFAULT, "DIFF_C2"););

ITERATOR_TEST_BLOCK(
"DDY C4",
result = DDY(a, CELL_DEFAULT, DIFF_C4);
);

ITERATOR_TEST_BLOCK(
"DDY S2",
result = DDY(a, CELL_DEFAULT, DIFF_S2);
);
ITERATOR_TEST_BLOCK("DDY C4", result = DDY(a, CELL_DEFAULT, "DIFF_C4"););

ITERATOR_TEST_BLOCK(
"DDY W2",
result = DDY(a, CELL_DEFAULT, DIFF_W2);
);
ITERATOR_TEST_BLOCK("DDY S2", result = DDY(a, CELL_DEFAULT, "DIFF_S2"););

ITERATOR_TEST_BLOCK("DDY W2", result = DDY(a, CELL_DEFAULT, "DIFF_W2"););

ITERATOR_TEST_BLOCK("DDY W3", result = DDY(a, CELL_DEFAULT, "DIFF_W3"););

ITERATOR_TEST_BLOCK(
"DDY W3",
result = DDY(a, CELL_DEFAULT, DIFF_W3);
);

if (profileMode) {
int nthreads = 0;
#ifdef _OPENMP
Expand Down
34 changes: 8 additions & 26 deletions examples/performance/ddz/ddz.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,18 @@ int main(int argc, char **argv) {
result = DDZ(a);
);

ITERATOR_TEST_BLOCK(
"DDZ C2",
result = DDZ(a, CELL_DEFAULT, DIFF_C2);
);
ITERATOR_TEST_BLOCK("DDZ C2", result = DDZ(a, CELL_DEFAULT, "DIFF_C2"););

ITERATOR_TEST_BLOCK(
"DDZ C4",
result = DDZ(a, CELL_DEFAULT, DIFF_C4);
);

ITERATOR_TEST_BLOCK(
"DDZ S2",
result = DDZ(a, CELL_DEFAULT, DIFF_S2);
);
ITERATOR_TEST_BLOCK("DDZ C4", result = DDZ(a, CELL_DEFAULT, "DIFF_C4"););

ITERATOR_TEST_BLOCK(
"DDZ W2",
result = DDZ(a, CELL_DEFAULT, DIFF_W2);
);
ITERATOR_TEST_BLOCK("DDZ S2", result = DDZ(a, CELL_DEFAULT, "DIFF_S2"););

ITERATOR_TEST_BLOCK(
"DDZ W3",
result = DDZ(a, CELL_DEFAULT, DIFF_W3);
);
ITERATOR_TEST_BLOCK("DDZ W2", result = DDZ(a, CELL_DEFAULT, "DIFF_W2"););

ITERATOR_TEST_BLOCK("DDZ W3", result = DDZ(a, CELL_DEFAULT, "DIFF_W3"););

ITERATOR_TEST_BLOCK("DDZ FFT", result = DDZ(a, CELL_DEFAULT, "DIFF_FFT"););

ITERATOR_TEST_BLOCK(
"DDZ FFT",
result = DDZ(a, CELL_DEFAULT, DIFF_FFT);
);

if (profileMode) {
int nthreads = 0;
#ifdef _OPENMP
Expand Down
18 changes: 9 additions & 9 deletions examples/performance/iterator/iterator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ int main(int argc, char **argv) {
nthreads = omp_get_max_threads();
#endif

int width = 12;
constexpr int width = 12;
if(includeHeader){
time_output << "\n------------------------------------------------\n";
time_output << "Case legend";
time_output <<"\n------------------------------------------------\n";
for (int i = 0 ; i < names.size(); i++){
time_output << std::setw(width) << "Case " << i << ".\t" << names[i] << "\n";

for (std::size_t i = 0; i < names.size(); i++) {
time_output << std::setw(width) << "Case " << i << ".\t" << names[i] << "\n";
}
time_output << "\n";
time_output << std::setw(width) << "Nprocs" << "\t";
Expand All @@ -146,8 +146,8 @@ int main(int argc, char **argv) {
time_output << std::setw(width) << "Nx (global)" << "\t";
time_output << std::setw(width) << "Ny (global)" << "\t";
time_output << std::setw(width) << "Nz (global)" << "\t";
for (int i = 0 ; i < names.size(); i++){
time_output << std::setw(width) << "Case " << i << "\t";
for (std::size_t i = 0; i < names.size(); i++) {
time_output << std::setw(width) << "Case " << i << "\t";
}
time_output << "\n";
}
Expand All @@ -159,16 +159,16 @@ int main(int argc, char **argv) {
time_output << std::setw(width) << mesh->GlobalNx << "\t";
time_output << std::setw(width) << mesh->GlobalNy << "\t";
time_output << std::setw(width) << mesh->GlobalNz << "\t";
for (int i = 0 ; i < names.size(); i++){
for (std::size_t i = 0; i < names.size(); i++) {
time_output << std::setw(width) << times[i].count()/NUM_LOOPS << "\t";
}
time_output << "\n";
}else{
int width = 0;
std::size_t width = 0;
for (const auto i: names){ width = i.size() > width ? i.size() : width;};
width = width + 5;
time_output << std::setw(width) << "Case name" << "\t" << "Time per iteration (s)" << "\n";
for(int i = 0 ; i < names.size(); i++){
for (std::size_t i = 0; i < names.size(); i++) {
time_output << std::setw(width) << names[i] << "\t" << times[i].count()/NUM_LOOPS << "\n";
}
};
Expand Down
Loading

0 comments on commit ee6e9da

Please sign in to comment.