LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
MallocOpts.h
Go to the documentation of this file.
1 #ifndef art_Utilities_MallocOpts_h
2 #define art_Utilities_MallocOpts_h
3 
4 // -*- C++ -*-
5 //
6 // Package: Utilities
7 // Class : MallocOpts
8 //
9 // Original Author: Jim Kowalkowski
10 //
11 //
12 // ------------------ malloc option setter -----------------------
13 //
14 // There is a global instance of MallocOptionSetter. Upon construction,
15 // it gets the CPU type. If is it AMD or Intel, it sets the mallopt
16 // parameters to a set that works best for that environment. The best
17 // values have been chosen based on running a simple fw job.
18 //
19 // The four values that get reset are:
20 // M_MMAP_MAX, M_TRIM_THRESHOLD, M_TOP_PAD, M_MMAP_THRESHOLD
21 //
22 // Current the best AMD and Intel values were calculated using:
23 // AMD Opteron(tm) Processor 248
24 // Intel Dual Core something or other
25 //
26 // These values will need to be checked when new CPUs are available or
27 // when we move to 64 bit executables.
28 
29 #include "art/Utilities/fwd.h"
30 
31 #include <ostream>
32 #include <string>
33 
34 namespace art {
35  struct MallocOpts {
36  typedef int opt_type;
37 
39  MallocOpts(opt_type max, opt_type trim, opt_type pad, opt_type mmap_thr)
40  : mmap_max_(max), trim_thr_(trim), top_pad_(pad), mmap_thr_(mmap_thr)
41  {}
42 
43  opt_type mmap_max_;
44  opt_type trim_thr_;
45  opt_type top_pad_;
46  opt_type mmap_thr_;
47 
48  bool
49  operator==(const MallocOpts& opts) const
50  {
51  return mmap_max_ == opts.mmap_max_ && trim_thr_ == opts.trim_thr_ &&
52  top_pad_ == opts.top_pad_ && mmap_thr_ == opts.mmap_thr_;
53  }
54  bool
55  operator!=(const MallocOpts& opts) const
56  {
57  return !operator==(opts);
58  }
59  };
60 
61  std::ostream& operator<<(std::ostream& ost, const MallocOpts&);
62 
64  public:
67 
68  bool retrieveFromCpuType();
69  bool retrieveFromEnv();
70  void adjustMallocParams();
71  bool
72  hasErrors() const
73  {
74  return !error_message_.empty();
75  }
76  std::string
77  error_message() const
78  {
79  return error_message_;
80  }
81 
82  void
83  set_mmap_max(opt_type mmap_max)
84  {
85  values_.mmap_max_ = mmap_max;
86  changed_ = true;
87  }
88  void
89  set_trim_thr(opt_type trim_thr)
90  {
91  values_.trim_thr_ = trim_thr;
92  changed_ = true;
93  }
94  void
95  set_top_pad(opt_type top_pad)
96  {
97  values_.top_pad_ = top_pad;
98  changed_ = true;
99  }
100  void
101  set_mmap_thr(opt_type mmap_thr)
102  {
103  values_.mmap_thr_ = mmap_thr;
104  changed_ = true;
105  }
106 
107  MallocOpts
108  get() const
109  {
110  return values_;
111  }
112 
113  private:
114  bool changed_;
116 
117  std::string error_message_;
118  };
119 
121 }
122 
123 #endif /* art_Utilities_MallocOpts_h */
124 
125 // Local Variables:
126 // mode: c++
127 // End:
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
MallocOpts::opt_type opt_type
Definition: MallocOpts.h:65
void set_trim_thr(opt_type trim_thr)
Definition: MallocOpts.h:89
opt_type mmap_max_
Definition: MallocOpts.h:43
MallocOpts(opt_type max, opt_type trim, opt_type pad, opt_type mmap_thr)
Definition: MallocOpts.h:39
opt_type top_pad_
Definition: MallocOpts.h:45
opt_type mmap_thr_
Definition: MallocOpts.h:46
bool operator!=(const MallocOpts &opts) const
Definition: MallocOpts.h:55
std::string error_message_
Definition: MallocOpts.h:117
bool hasErrors() const
Definition: MallocOpts.h:72
Int_t max
Definition: plot.C:27
opt_type trim_thr_
Definition: MallocOpts.h:44
void set_mmap_thr(opt_type mmap_thr)
Definition: MallocOpts.h:101
void set_mmap_max(opt_type mmap_max)
Definition: MallocOpts.h:83
HLT enums.
MallocOptionSetter & getGlobalOptionSetter()
Definition: MallocOpts.cc:207
std::string error_message() const
Definition: MallocOpts.h:77
void set_top_pad(opt_type top_pad)
Definition: MallocOpts.h:95
bool operator==(const MallocOpts &opts) const
Definition: MallocOpts.h:49