MADNESS  version 0.9
worldprofile.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31  $Id$
32 */
33 #ifndef MADNESS_WORLD_WORLDPROFILE_H__INCLUDED
34 #define MADNESS_WORLD_WORLDPROFILE_H__INCLUDED
35 
36 #include <madness/madness_config.h>
39 #include <string>
40 #include <vector>
41 
42 // NEED TO ADD ATTRIBUTION TO SHINY ON SOURCE FORGE
43 
44 namespace madness {
45 
46  class World;
47 
49  template <typename T>
50  struct ProfileStat {
51  T value, max, min, sum; // local value, parallel max, min, sum
52  ProcessID pmax, pmin; // processor with max, min values
53 
55  ProfileStat() : value(0), max(0), min(0), sum(0), pmax(0), pmin(0) {}
56 
59  max = min = sum = value;
60  pmax = pmin = me;
61  }
62 
64  void par_reduce(const ProfileStat<T>& other) {
65  if (other.max > max) {
66  max = other.max;
67  pmax = other.pmax;
68  }
69  if (other.min < min) {
70  min = other.min;
71  pmin = other.pmin;
72  }
73  sum += other.sum;
74  }
75 
77  void clear() {
78  value = max = min = sum = 0;
79  pmax = pmin = 0;
80  }
81 
82  template <class Archive>
83  void serialize(const Archive& ar) {
84  ar & value & max & min & sum & pmax & pmin;
85  }
86  }; // struct ProfileStat
87 
89  struct WorldProfileEntry : public Spinlock {
91  int depth;
92 
96 
97  WorldProfileEntry(const char* name = "");
98 
100 
102 
103  static bool exclusivecmp(const WorldProfileEntry&a, const WorldProfileEntry& b);
104 
105  static bool inclusivecmp(const WorldProfileEntry&a, const WorldProfileEntry& b);
106 
107  void init_par_stats(ProcessID me);
108 
109  void par_reduce(const WorldProfileEntry& other);
110 
111  void clear();
112 
113  template <class Archive>
114  void serialize(const Archive& ar) {
115  ar & name & depth & count & xcpu & icpu;
116  }
117  }; // struct WorldProfileEntry
118 
119 
121 
123  class WorldProfile {
124  //static ConcurrentHashMap<std::string,WorldProfileEntry> items;
125  volatile static std::vector<WorldProfileEntry> items;
126  static Spinlock mutex;
127  static double cpu_start;
128  static double wall_start;
129 
130  static std::vector<WorldProfileEntry>& nvitems();
131 
132 
134  static int find(const std::string& name);
135 
136 
137  public:
139  static int register_id(const char* name);
140 
142  static int register_id(const char* classname, const char* function);
143 
145  static void clear();
146 
148  static WorldProfileEntry& get_entry(int id);
149 
151  static void print(World& world);
152 
153  private:
155  static void recv_stats(World& world, ProcessID p);
156  };
157 
158 
160  static thread_local WorldProfileObj* call_stack;
161  WorldProfileObj* const prev;
162  const int id;
163  const double cpu_base;
164  double cpu_start;
165  public:
166 
167  WorldProfileObj(int id);
168 
170  void pause(double now);
171 
173  void resume(double now);
174 
176  };
177 }
178 
179 #ifdef WORLD_PROFILE_ENABLE
180 # define PROFILE_STRINGIFY(s) #s
181 
182 # define PROFILE_BLOCK(name) \
183  static const int __name##_id=madness::WorldProfile::register_id(PROFILE_STRINGIFY(name)); \
184  madness::WorldProfileObj name(__name##_id)
185 
186 # define PROFILE_FUNC \
187  static const int __profile_id=madness::WorldProfile::register_id(__FUNCTION__); \
188  madness::WorldProfileObj __profile_obj(__profile_id)
189 
190 # define PROFILE_MEMBER_FUNC(classname) \
191  static const int __profile_id=madness::WorldProfile::register_id(PROFILE_STRINGIFY(classname), __FUNCTION__); \
192  madness::WorldProfileObj __profile_obj(__profile_id)
193 
194 
195 #else
196 
197 # define PROFILE_BLOCK(name)
198 # define PROFILE_FUNC
199 # define PROFILE_MEMBER_FUNC(classname)
200 
201 #endif
202 
203 #endif // MADNESS_WORLD_WORLDPROFILE_H__INCLUDED
T max
Definition: worldprofile.h:51
Simple container for parallel profile statistic.
Definition: worldprofile.h:50
void resume(double now)
Resume profiling.
Definition: worldprofile.cc:308
#define thread_local
Definition: config.h:418
Definition: worldprofile.h:159
ProfileStat< double > icpu
inclusive cpu call (i.e., including calls)
Definition: worldprofile.h:95
T min
Definition: worldprofile.h:51
::std::string string
Definition: gtest-port.h:872
Used to store profiler info.
Definition: worldprofile.h:89
static void clear()
Clears all profiling information.
Definition: worldprofile.cc:134
~WorldProfileObj()
Definition: worldprofile.cc:312
std::string name
name of the entry
Definition: worldprofile.h:90
void serialize(const Archive &ar)
Definition: worldprofile.h:83
static bool inclusivecmp(const WorldProfileEntry &a, const WorldProfileEntry &b)
Definition: worldprofile.cc:68
WorldProfileObj(int id)
Definition: worldprofile.cc:294
void pause(double now)
Pause profiling while we are not executing ... accumulate time in self.
Definition: worldprofile.cc:302
void init_par_stats(ProcessID me)
Definition: worldprofile.cc:72
static bool exclusivecmp(const WorldProfileEntry &a, const WorldProfileEntry &b)
Definition: worldprofile.cc:64
int depth
depth of recursive calls (0 if no active calls)
Definition: worldprofile.h:91
void clear()
Definition: worldprofile.cc:84
T sum
Definition: worldprofile.h:51
WorldProfileEntry(const char *name="")
Definition: worldprofile.cc:47
static void print(World &world)
Prints global profiling information. Global fence involved. Implemented in worldstuff.cc.
Definition: worldprofile.cc:203
WorldProfileEntry & operator=(const WorldProfileEntry &other)
Definition: worldprofile.cc:55
Singleton-like class for holding profiling data and functionality.
Definition: worldprofile.h:123
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
ProfileStat< double > xcpu
exclusive cpu time (i.e., excluding calls)
Definition: worldprofile.h:94
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
static WorldProfileEntry & get_entry(int id)
Returns a reference to the specified entry. Throws if id is invalid.
Definition: worldprofile.cc:145
void init_par_stats(ProcessID me)
Copies local stats into parallel stats in prep for global reduction.
Definition: worldprofile.h:58
Implements Mutex, MutexFair, Spinlock, ConditionVariable.
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:37
static int register_id(const char *name)
Returns id for the name, registering if necessary.
Definition: worldprofile.cc:109
ProcessID pmax
Definition: worldprofile.h:52
void par_reduce(const ProfileStat< T > &other)
Reduction of parallel data (max, min, sum)
Definition: worldprofile.h:64
ProfileStat< unsigned long > count
count of times called
Definition: worldprofile.h:93
ProcessID pmin
Definition: worldprofile.h:52
T value
Definition: worldprofile.h:51
Spinlock using pthread spinlock operations.
Definition: worldmutex.h:200
void par_reduce(const WorldProfileEntry &other)
Definition: worldprofile.cc:78
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
void clear()
Zeros all data.
Definition: worldprofile.h:77
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
void serialize(const Archive &ar)
Definition: worldprofile.h:114
ProfileStat()
Constructor initializes all members to zero.
Definition: worldprofile.h:55