QUDA  v0.5.0
A library for QCD on GPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
util_quda.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <cstdio>
3 #include <cstring>
4 #include <stack>
5 #include <sys/time.h>
6 
7 #include <enum_quda.h>
8 #include <util_quda.h>
9 
10 
11 static const size_t MAX_PREFIX_SIZE = 100;
12 
13 static QudaVerbosity verbosity_ = QUDA_SUMMARIZE;
14 static char prefix_[MAX_PREFIX_SIZE] = "";
15 static FILE *outfile_ = stdout;
16 
17 static const int MAX_BUFFER_SIZE = 1000;
18 static char buffer_[MAX_BUFFER_SIZE] = "";
19 
20 QudaVerbosity getVerbosity() { return verbosity_; }
21 char *getOutputPrefix() { return prefix_; }
22 FILE *getOutputFile() { return outfile_; }
23 
24 void setVerbosity(QudaVerbosity verbosity)
25 {
26  verbosity_ = verbosity;
27 }
28 
29 void setOutputPrefix(const char *prefix)
30 {
31  strncpy(prefix_, prefix, MAX_PREFIX_SIZE);
32  prefix_[MAX_PREFIX_SIZE-1] = '\0';
33 }
34 
35 void setOutputFile(FILE *outfile)
36 {
37  outfile_ = outfile;
38 }
39 
40 
41 static std::stack<QudaVerbosity> vstack;
42 
44 {
45  vstack.push(getVerbosity());
46  setVerbosity(verbosity);
47 
48  if (vstack.size() > 10) {
49  warningQuda("Verbosity stack contains %u elements. Is there a missing popVerbosity() somewhere?",
50  static_cast<unsigned int>(vstack.size()));
51  }
52 }
53 
55 {
56  if (vstack.empty()) {
57  errorQuda("popVerbosity() called with empty stack");
58  }
59  setVerbosity(vstack.top());
60  vstack.pop();
61 }
62 
63 char *getPrintBuffer() { return buffer_; }