CoreNEURON
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
coreneuron::Phase2
Definition: phase2.hpp:24
coreneuron::CheckPoints::restore_tqueue
void restore_tqueue(NrnThread &, const Phase2 &p2)
Definition: nrn_checkpoint.cpp:857
coreneuron::CheckPoints
Definition: nrn_checkpoint.hpp:17
coreneuron::pntindex
static int pntindex
Definition: prcellstate.cpp:24
coreneuron::CheckPoints::soa2aos
T * soa2aos(T *data, int cnt, int sz, int layout, int *permute) const
Definition: nrn_checkpoint.cpp:619
coreneuron::CheckPoints::initialize
bool initialize()
Definition: nrn_checkpoint.cpp:575
coreneuron::nrnthread_chkpnt
NrnThreadChkpnt * nrnthread_chkpnt
Definition: nrn_checkpoint.cpp:651
coreneuron::NrnThreadChkpnt::file_id
int file_id
Definition: nrn_checkpoint.hpp:88
coreneuron::Datum
int Datum
Definition: nrnconf.h:23
coreneuron::CheckPoints::write_time
void write_time() const
Definition: nrn_checkpoint.cpp:560
coreneuron::CheckPoints::get_save_path
std::string get_save_path() const
Definition: nrn_checkpoint.hpp:20
coreneuron::TQItem
Definition: tqueue.hpp:69
data
Definition: alignment.cpp:18
coreneuron::CheckPoints::should_save
bool should_save() const
Definition: nrn_checkpoint.hpp:26
coreneuron::nrn_inverse_i_layout
void nrn_inverse_i_layout(int i, int &icnt, int cnt, int &isz, int sz, int layout)
Definition: nrn_setup.cpp:669
coreneuron::CheckPoints::restore_time
double restore_time() const
todo : need to broadcast this rather than all reading a double
Definition: nrn_checkpoint.cpp:46
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
coreneuron::CheckPoints::restored
bool restored
Definition: nrn_checkpoint.hpp:43
coreneuron::i
int i
Definition: cellorder.cpp:485
coreneuron::CheckPoints::save_
const std::string save_
Definition: nrn_checkpoint.hpp:41
coreneuron::CheckPoints::should_restore
bool should_restore() const
Definition: nrn_checkpoint.hpp:29
coreneuron::FileHandler
Definition: nrn_filehandler.hpp:32
coreneuron::NrnThread
Definition: multicore.hpp:75
cnt
#define cnt
Definition: tqueue.hpp:44
coreneuron::CheckPoints::data_write
void data_write(FileHandler &F, T *data, int cnt, int sz, int layout, int *permute) const
Definition: nrn_checkpoint.cpp:644
coreneuron::CheckPoints::CheckPoints
CheckPoints(const std::string &save, const std::string &restore)
Definition: nrn_checkpoint.cpp:34
coreneuron::patstimtype
int patstimtype
Definition: nrn_checkpoint.cpp:653
coreneuron::CheckPoints::restore_tqitem
void restore_tqitem(int type, std::shared_ptr< Phase2::EventTypeBase > event, NrnThread &nt)
Definition: nrn_checkpoint.cpp:726
coreneuron::CheckPoints::write_checkpoint
void write_checkpoint(NrnThread *nt, int nb_threads) const
Definition: nrn_checkpoint.cpp:60
coreneuron::CheckPoints::get_restore_path
std::string get_restore_path() const
Definition: nrn_checkpoint.hpp:23
coreneuron::CheckPoints::write_phase2
void write_phase2(NrnThread &nt) const
Definition: nrn_checkpoint.cpp:118
coreneuron::CheckPoints::patstim_te
double patstim_te
Definition: nrn_checkpoint.hpp:45
area
#define area
Definition: md1redef.h:12
coreneuron::inverse_permute
int * inverse_permute(int *p, int n)
Definition: node_permute.cpp:131
coreneuron::NrnThreadChkpnt
Definition: nrn_checkpoint.hpp:87
phase2.hpp
coreneuron::CheckPoints::write_tqueue
void write_tqueue(TQItem *q, NrnThread &nt, FileHandler &fh) const
Definition: nrn_checkpoint.cpp:655
coreneuron::CheckPoints::patstim_index
int patstim_index
Definition: nrn_checkpoint.hpp:44
coreneuron::permute
static int permute(int i, NrnThread &nt)
Definition: prcellstate.cpp:28
coreneuron::CheckPoints::restore_
const std::string restore_
Definition: nrn_checkpoint.hpp:42