NEURON
nrn_checkpoint.hpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
8 
9 #pragma once
10 
11 #include "coreneuron/io/phase2.hpp"
12 
13 namespace coreneuron {
14 struct NrnThread;
15 class FileHandler;
16 
17 class CheckPoints {
18  public:
19  CheckPoints(const std::string& save, const std::string& restore);
20  std::string get_save_path() const {
21  return save_;
22  }
23  std::string get_restore_path() const {
24  return restore_;
25  }
26  bool should_save() const {
27  return !save_.empty();
28  }
29  bool should_restore() const {
30  return !restore_.empty();
31  }
32  double restore_time() const;
33  void write_checkpoint(NrnThread* nt, int nb_threads) const;
34  /* return true if special checkpoint initialization carried out and
35  one should not do finitialize
36  */
37  bool initialize();
38  void restore_tqueue(NrnThread&, const Phase2& p2);
39 
40  private:
41  const std::string save_;
42  const std::string restore_;
43  bool restored;
45  double patstim_te;
46 
47  void write_time() const;
48  void write_phase2(NrnThread& nt) const;
49 
50  template <typename T>
51  void data_write(FileHandler& F, T* data, int cnt, int sz, int layout, int* permute) const;
52  template <typename T>
53  T* soa2aos(T* data, int cnt, int sz, int layout, int* permute) const;
54  void write_tqueue(TQItem* q, NrnThread& nt, FileHandler& fh) const;
55  void write_tqueue(NrnThread& nt, FileHandler& fh) const;
56  void restore_tqitem(int type, std::shared_ptr<Phase2::EventTypeBase> event, NrnThread& nt);
57 };
58 
59 
60 int* inverse_permute(int* p, int n);
61 void nrn_inverse_i_layout(int i, int& icnt, int cnt, int& isz, int sz, int layout);
62 
63 extern int patstimtype;
64 
65 #ifndef CHKPNTDEBUG
66 #define CHKPNTDEBUG 0
67 #endif
68 
69 #if CHKPNTDEBUG
70 // Factored out from checkpoint changes to nrnoc/multicore.h and nrnoc/nrnoc_ml.h
71 // Put here to avoid potential issues with gpu transfer and to allow
72 // debugging comparison with respect to checkpoint writing to verify that
73 // data is same as on reading when inverse transforming SoA and permutations.
74 // Following is a mixture of substantive information which is lost during
75 // nrn_setup.cpp and debugging only information which is retrievable from
76 // NrnThread and Memb_list. Ideally, this should all go away
77 
78 struct Memb_list_chkpnt {
79  // debug only
80  double* data_not_permuted;
81  Datum* pdata_not_permuted;
82  int* nodeindices_not_permuted;
83 };
84 
85 #endif // CHKPNTDEBUG but another section for it below
86 
88  int file_id;
89 
90 #if CHKPNTDEBUG
91  int nmech;
92  double* area;
93  int* parent;
94  Memb_list_chkpnt** mlmap;
95 
96  int n_outputgids;
97  int* output_vindex;
98  double* output_threshold;
99 
100  int* pnttype;
101  int* pntindex;
102  double* delay;
103 
104  // BBCOREPOINTER
105  int nbcp;
106  int* bcptype;
107  int* bcpicnt;
108  int* bcpdcnt;
109 
110  // VecPlay
111  int* vtype;
112  int* mtype;
113  int* vecplay_ix;
114 #endif // CHKPNTDEBUG
115 };
116 
118 } // namespace coreneuron
static double restore(void *v)
std::string get_save_path() const
std::string get_restore_path() const
void restore_tqitem(int type, std::shared_ptr< Phase2::EventTypeBase > event, NrnThread &nt)
void write_tqueue(TQItem *q, NrnThread &nt, FileHandler &fh) const
void write_phase2(NrnThread &nt) const
T * soa2aos(T *data, int cnt, int sz, int layout, int *permute) const
void write_checkpoint(NrnThread *nt, int nb_threads) const
const std::string restore_
double restore_time() const
todo : need to broadcast this rather than all reading a double
void data_write(FileHandler &F, T *data, int cnt, int sz, int layout, int *permute) const
const std::string save_
void restore_tqueue(NrnThread &, const Phase2 &p2)
CheckPoints(const std::string &save, const std::string &restore)
#define cnt
Definition: tqueue.hpp:44
#define area
Definition: md1redef.h:12
#define i
Definition: md1redef.h:19
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
void nrn_inverse_i_layout(int i, int &icnt, int cnt, int &isz, int sz, int layout)
Definition: nrn_setup.cpp:680
int * inverse_permute(int *p, int n)
NrnThreadChkpnt * nrnthread_chkpnt
static int pntindex
Definition: prcellstate.cpp:24
static int permute(int i, NrnThread &nt)
Definition: prcellstate.cpp:28
int const size_t const size_t n
Definition: nrngsl.h:10
size_t q
size_t p
short type
Definition: cabvars.h:10
static double save(void *v)
Definition: ocbox.cpp:344
Represent main neuron object computed by single thread.
Definition: multicore.h:58
Non-template stable handle to a generic value.