MPQC  3.0.0-alpha
compute.h
1 //
2 // compute.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _util_misc_compute_h
29 #define _util_misc_compute_h
30 
31 #include <set>
32 
33 #include <util/state/state.h>
34 #include <util/state/stateio.h>
35 
36 namespace sc {
37 
38 class ResultInfo;
39 class StateIn;
40 class StateOut;
41 
42 typedef ResultInfo* ResultInfoP;
43 
51 class Compute
52 {
53  friend class ResultInfo;
54  friend class AccResultInfo;
55  private:
56  std::set<ResultInfoP> _results;
57 
58  void add(ResultInfo*);
59 
60  // Prohibit copy
61  Compute(const Compute&) {};
62 
63  protected:
67  virtual void compute() = 0;
68  public:
69  Compute();
70  virtual ~Compute();
71  virtual bool throw_if_tolerance_exceeded() const;
72 
75  virtual void obsolete();
76 };
77 
83 {
84  protected:
85  int _compute;
86  int _computed;
87  Compute* _c;
88  // This make sure that the datum is up to date. If it is not then
89  // Compute::compute() will be called.
90  virtual void update();
91  protected:
93  ResultInfo(const ResultInfo&,Compute*);
94  virtual void save_data_state(StateOut&);
95  virtual void restore_state(StateIn&);
96  ResultInfo& operator=(const ResultInfo&);
97  public:
99  virtual ~ResultInfo();
100  int& compute() { return _compute; }
101  const int& compute() const { return _compute; }
102  int compute(int c) { int r = _compute; _compute = c; return r; }
103  int& computed() { return _computed; }
104  const int& computed() const { return _computed; }
105  virtual int needed() const;
106 };
107 
111 {
112  private:
113  double _actual_accuracy;
114  double _desired_accuracy;
115  protected:
118  virtual void save_data_state(StateOut&);
119  virtual void restore_state(StateIn&);
120  AccResultInfo& operator=(const AccResultInfo&);
121  void update();
122  public:
124  ~AccResultInfo();
125  double actual_accuracy() const;
126  double desired_accuracy() const;
127  void set_desired_accuracy(double);
128  void set_actual_accuracy(double);
129  int computed_to_desired_accuracy() const
130  { return computed() && _actual_accuracy <= _desired_accuracy; }
131  int needed() const;
132 };
133 
134 }
135 
136 #include <util/misc/comptmpl.h>
137 
138 namespace sc {
139 
140 typedef NCResult<int> Resultint;
141 typedef NCResult<double> Resultdouble;
142 typedef NCAccResult<double> AccResultdouble;
143 
144 }
145 
146 #endif
147 
148 // Local Variables:
149 // mode: c++
150 // c-file-style: "CLJ"
151 // End:
sc::AccResultInfo
This is like ResultInfo but the accuracy with which a result was computed as well as the desired accu...
Definition: compute.h:110
sc::StateIn
Definition: statein.h:79
sc::ResultInfo
This is a base class for all of Compute's result types.
Definition: compute.h:82
sc::Compute::obsolete
virtual void obsolete()
Marks all results as being out of date.
sc::StateOut
Definition: stateout.h:71
sc::Compute
The Compute class provides a means of keeping results up to date.
Definition: compute.h:51
sc::Compute::compute
virtual void compute()=0
Recompute at least the results that have compute true and are not already computed.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.