autotuner.h 1.63 KB
Newer Older
Luka Stanisic's avatar
Luka Stanisic committed
1 2
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   < BioEM software for Bayesian inference of Electron Microscopy images>
Luka Stanisic's avatar
Luka Stanisic committed
3 4
   Copyright (C) 2017 Pilar Cossio, Markus Rampp, Luka Stanisic and Gerhard
   Hummer.
Luka Stanisic's avatar
Luka Stanisic committed
5
   Max Planck Institute of Biophysics, Frankfurt, Germany.
Luka Stanisic's avatar
Luka Stanisic committed
6
   Max Planck Computing and Data Facility, Garching, Germany.
Luka Stanisic's avatar
Luka Stanisic committed
7

Luka Stanisic's avatar
Luka Stanisic committed
8
   Released under the GNU Public License, v3.
Luka Stanisic's avatar
Luka Stanisic committed
9 10 11 12 13 14 15
   See license statement for terms of distribution.

   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

#ifndef AUTOTUNER_H
#define AUTOTUNER_H

Luka Stanisic's avatar
Luka Stanisic committed
16 17
class Autotuner
{
Luka Stanisic's avatar
Luka Stanisic committed
18 19

public:
Luka Stanisic's avatar
Luka Stanisic committed
20
  Autotuner() { stopTuning = true; }
Luka Stanisic's avatar
Luka Stanisic committed
21

Luka Stanisic's avatar
Luka Stanisic committed
22 23 24 25 26 27 28
  /* Setting variables to initial values */
  inline void Initialize(int alg = 3, int st = 7)
  {
    algo = alg;
    stable = st;
    Reset();
  }
Luka Stanisic's avatar
Luka Stanisic committed
29

Luka Stanisic's avatar
Luka Stanisic committed
30 31
  /* Resetting variables to initial values */
  void Reset();
Luka Stanisic's avatar
Luka Stanisic committed
32

Luka Stanisic's avatar
Luka Stanisic committed
33 34
  /* Check if autotuning is needed, depending on which comparison is finished */
  bool Needed(int iteration);
Luka Stanisic's avatar
Luka Stanisic committed
35

Luka Stanisic's avatar
Luka Stanisic committed
36 37
  /* Check if optimal workload value has been computed */
  bool Finished();
Luka Stanisic's avatar
Luka Stanisic committed
38

Luka Stanisic's avatar
Luka Stanisic committed
39 40
  /* Set a new workload value to test, depending on the algorithm */
  void Tune(double compTime);
Luka Stanisic's avatar
Luka Stanisic committed
41

Luka Stanisic's avatar
Luka Stanisic committed
42 43
  /* Return workload value */
  inline int Workload() { return workload; }
Luka Stanisic's avatar
Luka Stanisic committed
44 45

private:
Luka Stanisic's avatar
Luka Stanisic committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  int algo;
  int stable;

  bool stopTuning;
  int workload;

  /* Variables needed for AlgoSimple and AlgoRatio */
  double best_time;
  int best_workload;

  /* Variables needed for AlgoBisection */
  int a;
  int b;
  int c;
  int x;
  int limit;
  double fb, fx;

  /* Autotuning algorithms */
  void AlgoSimple(double compTime);
  void AlgoRatio(double compTime);
  void AlgoBisection(double compTime);
Luka Stanisic's avatar
Luka Stanisic committed
68 69 70
};

#endif