gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
noneprinter.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
23 
24 
25 #ifndef __none_printer_hpp__
26 #define __none_printer_hpp__
27 
28 // Gambit
32 
33 // MPI bindings
35 
36 // BOOST_PP
37 #include <boost/preprocessor/seq/for_each_i.hpp>
38 
39 // Code!
40 namespace Gambit
41 {
42  namespace Printers
43  {
44 
45  class nonePrinter : public BasePrinter
46  {
47  public:
48  // Constructor
49  nonePrinter(const Options& options, BasePrinter* const primary)
50  : BasePrinter(primary,options.getValueOrDef<bool>(false,"auxilliary"))
51 #ifdef WITH_MPI
52  , myComm()
53 #endif
54  {
55 #ifdef WITH_MPI
56  this->setRank(myComm.Get_rank());
57 #endif
58 
59  // There is only work to do if this printer is the primary one.
60  if (!is_auxilliary_printer())
61  {
62 
63  // Create the file of the resume file
64  std::ostringstream ff;
65  ff << options.getValue<std::string>("default_output_path") << "/";
66  ff << "nonePrinter.resume";
67  std::string resumeFileName = ff.str();
68 
69  // Check if the resume file exist.
70  if ( not Utils::file_exists(resumeFileName))
71  {
72  // If it does not exist, we do not resume
73  set_resume(false);
74 
75  // Create the file (only rank 0 is allowed to do that)
76  if (getRank() == 0)
77  {
78  std::ofstream ofs(resumeFileName, std::ofstream::trunc);
79  ofs << "This file was automatically created ";
80  ofs << "by the nonePrinter.\n";
81  ofs << "It is required to resume the scan.\n";
82  ofs << "Please do not delete this file";
83  ofs.close();
84  }
85  }
86  else
87  {
88  // If it exists, options.getValue("resume") tells us what to do
89  set_resume(options.getValue<bool>("resume"));
90  }
91 
92 #ifdef WITH_MPI
93  // Let all processes wait here.
94  // (Not sure if that is really needed though)
95  myComm.Barrier();
96 #endif
97  }
98  }
99 
102 
103  // Initialisation function
104  // Run by dependency resolver, which supplies the functors with a vector of VertexIDs whose requiresPrinting flags are set to true.
105  void initialise(const std::vector<int>&) {}
106  void reset(bool) {}
107  void finalise(bool) {}
108  void flush() {} // No buffers with this printer, so flush function doesn't need to do anything
109 
110  // Permanently unavailable for this printer
112  {
113  std::ostringstream err;
114  err << "The none printer is intrinsically incapable of reading from previous output, since the previous output was never printed." << std::endl;
115  printer_error().raise(LOCAL_INFO, err.str());
116  return Options();
117  }
118 
120 
121  // PRINT FUNCTIONS
122  //----------------------------
123  // Need to define one of these for every type we want to print!
124  // Could use macros again to generate identical print functions
125  // for all types that have a << operator already defined.
126 
128  using BasePrinter::_print; // Tell compiler we are using some of the base class overloads of this on purpose.
129  #define DECLARE_PRINT(r,data,i,elem) void _print(elem const&, const std::string&, const int, const uint, const ulong) { /* do nothing */}
131  #ifndef SCANNER_STANDALONE
133  #endif
134  #undef DECLARE_PRINT
135 
137  private:
138 #ifdef WITH_MPI
139  GMPI::Comm myComm;
140 #endif
141 
142  };
143 
144  // Register printer so it can be constructed via inifile instructions
145  // First argument is string label for inifile access, second is class from which to construct printer
147 
148  } // end namespace Printers
149 } // end namespace Gambit
150 
151 #endif //ifndef __none_printer_hpp__
EXPORT_SYMBOLS error & printer_error()
Printer errors.
void initialise(const std::vector< int > &)
Virtual function overloads:
nonePrinter(const Options &options, BasePrinter *const primary)
Definition: noneprinter.hpp:49
#define DECLARE_PRINT(r, data, i, elem)
#define ASCII_BACKEND_TYPES
Definition: asciitypes.hpp:30
#define LOCAL_INFO
Definition: local_info.hpp:34
General small utility functions.
TYPE getValue(const args &... keys) const
EXPORT_SYMBOLS bool file_exists(const std::string &filename)
Check if a file exists.
#define ASCII_TYPES
Definition: asciitypes.hpp:23
Declaration and definition of printer base class.
BOOST_PP_SEQ_FOR_EACH_I(DECLARE_PRINT,, ASCII_TYPES) BOOST_PP_SEQ_FOR_EACH_I(DECLARE_PRINT
#define LOAD_PRINTER(tag,...)
Definition: baseprinter.hpp:57
Sequence of all types printable by the ASCII printer.
A simple C++ wrapper for the MPI C bindings.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
A small wrapper object for &#39;options&#39; nodes.