CHROMA
inline_erase_mg_space.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task to erase an object from a named buffer
3  *
4  * Named object writing
5  */
6 
10 
11 #if BASE_PRECISION == 32
12 #define QDP_Precision 'F'
13 #define QLA_Precision 'F'
14 #define toReal toFloat
15 #elif BASE_PRECISION == 64
16 #define QDP_Precision 'D'
17 #define QLA_Precision 'D'
18 #define toReal toDouble
19 #endif
20 
21 extern "C" {
22  // This should be placed on the include path.
23 #include "wilsonmg-interface.h"
24 
25 }
26 
27 
28 namespace Chroma
29 {
30  namespace InlineEraseMGSpaceEnv
31  {
32  namespace
33  {
34  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
35  const std::string& path)
36  {
37  return new InlineMeas(Params(xml_in, path));
38  }
39 
40  //! Local registration flag
41  bool registered = false;
42 
43  const std::string name = "ERASE_MG_SUBSPACE";
44  }
45 
46  //! Register all the factories
47  bool registerAll()
48  {
49  bool success = true;
50  if (! registered)
51  {
52  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
53  registered = true;
54  }
55  return success;
56  }
57 
58 
59  //! Object buffer
60  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
61  {
62  push(xml, path);
63 
64  write(xml, "object_id", input.object_id);
65 
66  pop(xml);
67  }
68 
69 
70  //! Object buffer
71  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
72  {
73  XMLReader inputtop(xml, path);
74 
75  read(inputtop, "object_id", input.object_id);
76  }
77 
78 
79  // Param stuff
81 
82  Params::Params(XMLReader& xml_in, const std::string& path)
83  {
84  try
85  {
86  XMLReader paramtop(xml_in, path);
87 
88  if (paramtop.count("Frequency") == 1)
89  read(paramtop, "Frequency", frequency);
90  else
91  frequency = 1;
92 
93  // Ids
94  read(paramtop, "NamedObject", named_obj);
95  }
96  catch(const std::string& e)
97  {
98  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
99  QDP_abort(1);
100  }
101  }
102 
103 
104  void
105  Params::writeXML(XMLWriter& xml_out, const std::string& path)
106  {
107  push(xml_out, path);
108 
109  // Ids
110  write(xml_out, "NamedObject", named_obj);
111 
112  pop(xml_out);
113  }
114 
115 
116  void
117  InlineMeas::operator()(unsigned long update_no,
118  XMLWriter& xml_out)
119  {
120  START_CODE();
121 
122  push(xml_out, "erase_mg_subspace");
123  write(xml_out, "update_no", update_no);
124 
125  QDPIO::cout << name << ": object erase" << std::endl;
126 
127  // Erase the object
128  QDPIO::cout << "Attempt to erase object name = " << params.named_obj.object_id << std::endl;
129  write(xml_out, "object_id", params.named_obj.object_id);
131  QDPIO::cout << "MG Subspace: " << params.named_obj.object_id << " found. " << std::endl;
132 
133  void *mg_subspace = TheNamedObjMap::Instance().getData<void *>(params.named_obj.object_id);
134  QDPIO::cout << "Calling QOP Destroy function" << std::endl;
135  MGP(destroy_subspace)(mg_subspace);
136 
137  try {
138  QDPIO::cout << "Attempting to delete from named object store" << std:: endl;
139  // Now erase the object
141 
142  QDPIO::cout << "Object erased" << std::endl;
143  }
144  catch( std::bad_cast ) {
145  QDPIO::cerr << name << ": cast error"
146  << std::endl;
147  QDP_abort(1);
148  }
149  catch (const std::string& e) {
150 
151  QDPIO::cerr << name << ": error message: " << e
152  << std::endl;
153  QDP_abort(1);
154  }
155  }
156  else {
157  QDPIO::cout << "MG Subspace: " << params.named_obj.object_id << " is not in the map. Cannot delete" << std::endl;
158  }
159  QDPIO::cout << name << ": ran successfully" << std::endl;
160 
161  pop(xml_out); // erase_named_obj
162 
163  END_CODE();
164  }
165 
166  }
167 
168 }
Inline measurement factory.
Inline writing of memory objects.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
static T & Instance()
Definition: singleton.h:432
Inline task to erase a named mg space.
Named object function std::map.
static bool registered
Local registration flag.
const std::string name
Name to be used.
bool registerAll()
Register all the factories.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Object buffer.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Object buffer.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
struct Chroma::InlineEraseMGSpaceEnv::Params::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)
struct MGP(Clover_Params) PC(g_param)