1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#ifndef __PROGRESS_H
#define __PROGRESS_H
#include <cmath>
#include <algorithm>
static bool progress(unsigned iter_curr, af::timer t, double time_total)
{
static unsigned iter_prev = 0;
static double time_prev = 0;
static double max_rate = 0;
af::sync();
double time_curr = af::timer::stop(t);
if ((time_curr - time_prev) < 1) return true;
double rate = (iter_curr - iter_prev) / (time_curr - time_prev);
printf(" iterations per second: %.0f (progress %.0f%%)\n",
rate, 100.0f * time_curr / time_total);
max_rate = std::max(max_rate, rate);
iter_prev = iter_curr;
time_prev = time_curr;
if (time_curr < time_total) return true;
printf(" ### %f iterations per second (max)\n", max_rate);
return false;
}
#endif
|