1 #ifndef LINGEN_CHECKPOINTS_HPP_
2 #define LINGEN_CHECKPOINTS_HPP_
3 
4 #include <stddef.h>               // for size_t
5 #include <stdexcept>              // for runtime_error
6 #include <string>                 // for string
7 #include "lingen_bigmatpoly.hpp"  // for bigmatpoly
8 class matpoly;
9 struct bmstatus;
10 struct cxx_param_list;
11 
12 enum cp_which {
13     LINGEN_CHECKPOINT_E,
14     LINGEN_CHECKPOINT_PI,
15 };
16 
17 template<typename matpoly_type>
18 int load_checkpoint_file(bmstatus & bm, cp_which which, matpoly_type &, unsigned int t0, unsigned int t1);
19 template<typename matpoly_type>
20 int save_checkpoint_file(bmstatus & bm, cp_which which, matpoly_type const &, unsigned int t0, unsigned int t1);
21 
22 template<>
23 int load_checkpoint_file<matpoly>(bmstatus & bm, cp_which which, matpoly &, unsigned int t0, unsigned int t1);
24 template<>
25 int save_checkpoint_file<matpoly>(bmstatus & bm, cp_which which, matpoly const &, unsigned int t0, unsigned int t1);
26 
27 template<>
28 int load_checkpoint_file<bigmatpoly>(bmstatus & bm, cp_which which, bigmatpoly &, unsigned int t0, unsigned int t1);
29 template<>
30 int save_checkpoint_file<bigmatpoly>(bmstatus & bm, cp_which which, bigmatpoly const &, unsigned int t0, unsigned int t1);
31 
32 struct lingen_checkpoint {
33     bmstatus & bm;
34     int level;
35     unsigned int t0;
36     unsigned int t1;
37     unsigned int target_t;
38     int mpi;
39     int rank;
40     std::string auxfile;
41     std::string sdatafile;
42     std::string gdatafile;
43     std::string datafile; /* a copy of either sdatafile or gdatafile */
44     /* be sure to change when needed */
45     static constexpr unsigned long format = 4;
46     static std::string get_cp_basename(bmstatus & bm, cp_which which, unsigned int t0, unsigned int t1);
47     lingen_checkpoint(bmstatus & bm, unsigned int t0, unsigned int t1, int mpi, std::string base);
lingen_checkpointlingen_checkpoint48     lingen_checkpoint(bmstatus & bm, cp_which which, unsigned int t0, unsigned int t1, int mpi) : lingen_checkpoint(bm, t0, t1, mpi, get_cp_basename(bm, which, t0, t1)) {}
49     bool save_aux_file(size_t Xsize) const;
50     bool load_aux_file(size_t & Xsize);
51     bool checkpoint_already_present() const;
52     int load_data_file(matpoly & X);
53     int save_data_file(matpoly const & X);
54     struct invalid_aux_file : public std::runtime_error {
invalid_aux_filelingen_checkpoint::invalid_aux_file55         invalid_aux_file(std::string const & s) : std::runtime_error(s) {}
56     };
57     static void decl_usage(cxx_param_list & pl);
58     static void lookup_parameters(cxx_param_list & pl);
59     static void interpret_parameters(cxx_param_list & pl);
60     static const char * directory;
61     static unsigned int threshold;
62     static int save_gathered;
63 };
64 
65 #endif	/* LINGEN_CHECKPOINTS_HPP_ */
66