Skip to content

Commit 82acc82

Browse files
committed
Event indexing is now performed using a small struct eventID rather than a string for performance. Added unit test for eventID.
Chimbuko now uses boost. configure script now checks for boost installation Configure now properly fails if ADIOS2 is not specified
1 parent 6e35d0c commit 82acc82

17 files changed

Lines changed: 178 additions & 94 deletions

configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ if test "x$with_adios2" != "x"; then
9393
else
9494
AC_MSG_NOTICE([Detected ADIOS 2.6+])
9595
fi
96+
else
97+
AC_MSG_FAILURE(["ADIOS2 install path must be specified with --with-adios2"])
9698
fi
9799

98100
#Choose network
@@ -141,6 +143,14 @@ fi
141143
AC_ARG_WITH([perf-metric], AS_HELP_STRING([--with-perf-metric], [Specify use of performance metrics]),[PS_FLAGS+=" -D_PERF_METRIC"],[])
142144

143145

146+
#Check for boost
147+
AC_ARG_WITH([boost], AS_HELP_STRING([--with-boost], [Specify Boost install directory]),[],[])
148+
if test "x$with_boost" != "x"; then
149+
CPPFLAGS+=" -I$with_boost/include"
150+
LIBS+=" -L$with_boost/lib"
151+
fi
152+
AC_CHECK_HEADERS([boost/math/distributions/normal.hpp], [], [AC_MSG_ERROR(Boost library is required)])
153+
144154

145155
AC_CONFIG_HEADERS([chimbuko_config.h])
146156
AC_SUBST([PS_FLAGS])

include/chimbuko/ad/ADEvent.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace chimbuko {
7474
* @brief A type that stores some information about an event whose data may have been deleted
7575
*/
7676
struct EventInfo{
77-
std::string id;
77+
eventID id;
7878
EventDataType type;
7979
unsigned long ts;
8080

@@ -110,7 +110,7 @@ namespace chimbuko {
110110
case EventDataType::COUNT:
111111
os << "COUNT, "; break;
112112
}
113-
os << id << ", " << ts << "}";
113+
os << id.toString() << ", " << ts << "}";
114114
return os.str();
115115
}
116116

@@ -212,13 +212,13 @@ namespace chimbuko {
212212
*
213213
* throws a runtime error if the call is not present in the call-list
214214
*/
215-
CallListIterator_t getCallData(const std::string &event_id) const;
215+
CallListIterator_t getCallData(const eventID &event_id) const;
216216

217217
/**
218218
* @brief Get a pair of iterators marking the start and one-past-the-end of a window of size (up to) win_size events
219219
* on either size around the given event occurring on the same thread
220220
*/
221-
std::pair<CallListIterator_t, CallListIterator_t> getCallWindowStartEnd(const std::string &event_id, const int win_size) const;
221+
std::pair<CallListIterator_t, CallListIterator_t> getCallWindowStartEnd(const eventID &event_id, const int win_size) const;
222222

223223
/**
224224
* @brief clear
@@ -354,7 +354,7 @@ namespace chimbuko {
354354
*
355355
* Completed calls are removed from this list every IO step by calls to trimCallList
356356
*/
357-
std::unordered_map<std::string, CallListIterator_t> m_callIDMap;
357+
std::unordered_map<eventID, CallListIterator_t> m_callIDMap;
358358

359359

360360
/**
@@ -368,7 +368,7 @@ namespace chimbuko {
368368
/**
369369
* @brief Map of event index to the number of unmatched correlation IDs
370370
*/
371-
std::unordered_map<std::string,size_t> m_unmatchedCorrelationID_count;
371+
std::unordered_map<eventID,size_t> m_unmatchedCorrelationID_count;
372372

373373
/**
374374
* @brief verbose

include/chimbuko/ad/ADParser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ namespace chimbuko {
299299
* @brief Create an Event_t instance from the data at the provided pointer and run simple validation
300300
* @param log_error If true a recoverable error will be logged for invalid events
301301
*/
302-
std::pair<Event_t,bool> createAndValidateEvent(const unsigned long * data, EventDataType t, size_t idx, std::string id, bool log_error = true) const;
302+
std::pair<Event_t,bool> createAndValidateEvent(const unsigned long * data, EventDataType t, size_t idx, const eventID &id, bool log_error = true) const;
303303

304304

305305

include/chimbuko/ad/ExecData.hpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
2-
#include "chimbuko/ad/ADDefine.hpp"
2+
#include <chimbuko/ad/ADDefine.hpp>
3+
#include <chimbuko/ad/utils.hpp>
34
#include <iostream>
45
#include <string>
56
#include <vector>
@@ -26,9 +27,9 @@ class Event_t {
2627
* @param data pointer to raw performance event vector
2728
* @param t event type
2829
* @param idx event index
29-
* @param id event (string) id
30+
* @param id event id
3031
*/
31-
Event_t(const unsigned long * data, EventDataType t, size_t idx, std::string id="event_id")
32+
Event_t(const unsigned long * data, EventDataType t, size_t idx, const eventID &id = eventID())
3233
: m_data(data), m_t(t), m_id(id), m_idx(idx) {}
3334
/**
3435
* @brief Destroy the Event_t object
@@ -45,7 +46,7 @@ class Event_t {
4546
/**
4647
* @brief return event id
4748
*/
48-
std::string id() const { return m_id; }
49+
const eventID &id() const { return m_id; }
4950
/**
5051
* @brief return event index, typically the index of the event in the input array for the timestep on which it was spawned
5152
*/
@@ -141,7 +142,7 @@ class Event_t {
141142
private:
142143
const unsigned long * m_data; /**< pointer to raw performance trace data vector */
143144
EventDataType m_t; /**< event type */
144-
std::string m_id; /**< event id */
145+
eventID m_id; /**< event id */
145146
size_t m_idx; /**< event index */
146147
};
147148

@@ -172,7 +173,7 @@ class CommData_t {
172173
* @param ev constant reference to a Event_t object
173174
* @param commType communication type (e.g. SEND/RECV)
174175
*/
175-
CommData_t(const Event_t& ev, std::string commType);
176+
CommData_t(const Event_t& ev, const std::string &commType);
176177
/**
177178
* @brief Destroy the CommData_t object
178179
*
@@ -206,12 +207,12 @@ class CommData_t {
206207
*
207208
* @param key execution id
208209
*/
209-
void set_exec_key(std::string key) { m_execkey = key; }
210+
void set_exec_key(const eventID &key) { m_execkey = key; }
210211

211212
/**
212213
* @brief Get the execution key id. This is equal to the "id" string associated with a parent ExecData_t object
213214
*/
214-
const std::string & get_exec_key() const { return m_execkey; }
215+
const eventID & get_exec_key() const { return m_execkey; }
215216

216217
/**
217218
* @brief compare two communication data
@@ -239,7 +240,7 @@ class CommData_t {
239240
m_bytes, /**< communication data size in bytes */
240241
m_tag; /**< communication tag */
241242
unsigned long m_ts; /**< communication timestamp */
242-
std::string m_execkey; /**< execution key (or id) where this communication event occurs */
243+
eventID m_execkey; /**< execution key (or id) where this communication event occurs */
243244
};
244245

245246

@@ -306,12 +307,12 @@ class CommData_t {
306307
*
307308
* @param key execution id
308309
*/
309-
void set_exec_key(std::string key) { m_execkey = key; }
310+
void set_exec_key(const eventID &key) { m_execkey = key; }
310311

311312
/**
312313
* @brief Get the execution key id. This is equal to the "id" string associated with a parent ExecData_t object
313314
*/
314-
const std::string & get_exec_key() const { return m_execkey; }
315+
const eventID & get_exec_key() const { return m_execkey; }
315316

316317
private:
317318
std::string m_countername; /**< counter name */
@@ -322,7 +323,7 @@ class CommData_t {
322323
m_cid, /**< counted id */
323324
m_value, /**< counter value */
324325
m_ts; /**< counter timestamp */
325-
std::string m_execkey; /**< execution key (or id) where this counter event occurs */
326+
eventID m_execkey; /**< execution key (or id) where this counter event occurs */
326327
};
327328

328329

@@ -355,7 +356,7 @@ class ExecData_t {
355356
/**
356357
* @brief Get the id of this execution data
357358
*/
358-
const std::string &get_id() const { return m_id; }
359+
const eventID &get_id() const { return m_id; }
359360
/**
360361
* @brief Get the function name of this execution data
361362
*/
@@ -405,7 +406,7 @@ class ExecData_t {
405406
/**
406407
* @brief Get the parent function id of this execution data
407408
*/
408-
std::string get_parent() const { return m_parent; }
409+
const eventID & get_parent() const { return m_parent; }
409410
/**
410411
* @brief Get a list of communication data occured in this execution data
411412
*/
@@ -441,7 +442,7 @@ class ExecData_t {
441442
*
442443
* @param parent the parent execution id
443444
*/
444-
void set_parent(std::string parent) { m_parent = parent; }
445+
void set_parent(const eventID &parent) { m_parent = parent; }
445446
/**
446447
* @brief Set the function name of this execution
447448
*
@@ -521,7 +522,7 @@ class ExecData_t {
521522
/**
522523
* @brief Set the partner event linked by a GPU correlation ID
523524
*/
524-
void set_GPU_correlationID_partner(const std::string event_id){ m_gpu_correlation_id_partner.push_back(event_id); }
525+
void set_GPU_correlationID_partner(const eventID &event_id){ m_gpu_correlation_id_partner.push_back(event_id); }
525526

526527
/**
527528
* @brief Return true if this event has been matched to a partner event by a GPU correlation ID
@@ -539,10 +540,10 @@ class ExecData_t {
539540
*
540541
* Throws error if index out of range
541542
*/
542-
const std::string & get_GPU_correlationID_partner(const size_t i) const;
543+
const eventID & get_GPU_correlationID_partner(const size_t i) const;
543544

544545
private:
545-
std::string m_id; /**< execution id */
546+
eventID m_id; /**< execution id */
546547
std::string m_funcname; /**< function name */
547548
unsigned long
548549
m_pid, /**< program id */
@@ -555,13 +556,13 @@ class ExecData_t {
555556
m_runtime, /**< inclusive running time (i.e. including time of child calls) */
556557
m_exclusive; /**< exclusive running time (i.e. excluding time of child calls) */
557558
int m_label; /**< 1 for normal, -1 for abnormal execution */
558-
std::string m_parent; /**< parent execution */
559+
eventID m_parent; /**< parent execution */
559560
unsigned long m_n_children; /**< the number of childrent executions */
560561
unsigned long m_n_messages; /**< the number of messages */
561562
std::deque<CommData_t> m_messages; /**< a vector of all messages */
562563
std::deque<CounterData_t> m_counters; /**< a vector of all counters */
563564
bool m_can_delete; /**< Flag indicating that the event is deletable by the garbage collection */
564-
std::vector<std::string> m_gpu_correlation_id_partner; /**< The event ids partner events linked by a correlation ID, either the launching CPU event or the GPU kernel event */
565+
std::vector<eventID> m_gpu_correlation_id_partner; /**< The event ids partner events linked by a correlation ID, either the launching CPU event or the GPU kernel event */
565566
};
566567

567568

include/chimbuko/ad/utils.hpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
22

3+
#include<functional>
4+
#include<boost/functional/hash.hpp>
5+
36
namespace chimbuko{
47
/**
58
* @brief Return a random character
@@ -12,7 +15,7 @@ namespace chimbuko{
1215
* WARNING: this is slow, apparently
1316
*/
1417
std::string generate_hex(const unsigned int len);
15-
18+
1619
/*
1720
* @brief Generate an event_id string of form ${rank}:${step}:${idx}
1821
*/
@@ -24,6 +27,36 @@ namespace chimbuko{
2427
std::string generate_event_id(int rank, int step, size_t idx, unsigned long eid);
2528

2629

30+
/**
31+
* @brief A class representing a unique descriptor for an event
32+
*/
33+
struct eventID{
34+
int rank; /**< Process rank of event */
35+
int step; /**< IO step in which event occurred */
36+
long idx; /**< Index of event within the IO step */
37+
38+
eventID(): rank(0),step(0),idx(0){}
39+
eventID(const int rank, const int step, const long idx): rank(rank), step(step), idx(idx){}
40+
41+
/**
42+
* @brief Return an event representing the special "root" event
43+
*/
44+
inline static eventID root(){ return eventID(-1,-1,-1); }
45+
46+
/**
47+
* @brief Is this event the special root event?
48+
*/
49+
inline bool isRoot() const{ return rank == -1 && step == -1 && idx == -1; }
50+
51+
inline bool operator==(const eventID &r) const{ return r.rank == rank && r.step == step && r.idx == idx; }
52+
inline bool operator!=(const eventID &r) const{ return r.rank != rank || r.step != step || r.idx != idx; }
53+
54+
/**
55+
* @brief Return a string representing the event of the form "${rank}:${step}:${idx}" or "root" for the special root event
56+
*/
57+
inline std::string toString() const{ return isRoot() ? "root" : generate_event_id(rank, step, idx); }
58+
};
59+
2760
/*
2861
* @brief Get the IP of the hierarchical pserver endpoint that this rank should connect to. Ports are offset round-robin by the MPI rank of the process
2962
* @param base_ip The base IP of the server
@@ -33,3 +66,19 @@ namespace chimbuko{
3366
std::string getHPserverIP(const std::string &base_ip, const int hpserver_nthr, const int rank);
3467
};
3568

69+
namespace std{
70+
/**
71+
* @brief Specialize std::hash for eventID type
72+
*/
73+
template <>
74+
struct hash<chimbuko::eventID>
75+
{
76+
inline std::size_t operator()(const chimbuko::eventID& k) const{
77+
std::size_t hash = 0;
78+
boost::hash_combine(hash, k.rank);
79+
boost::hash_combine(hash, k.step);
80+
boost::hash_combine(hash, k.idx);
81+
return hash;
82+
}
83+
};
84+
};

include/chimbuko/util/hash.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
#pragma once
22

33
#include<array>
4+
#include<boost/functional/hash.hpp>
45

56
namespace chimbuko{
6-
77
/**
88
* @brief Hash function for std::array
99
*/
1010
template<typename T, size_t N>
1111
struct ArrayHasher {
1212
std::size_t operator()(const std::array<T, N>& a) const{
1313
std::size_t h = 0;
14-
15-
for (auto e : a) {
16-
h ^= std::hash<T>{}(e) + 0x9e3779b9 + (h << 6) + (h >> 2);
17-
}
14+
for (auto e : a)
15+
boost::hash_combine(h, e);
1816
return h;
1917
}
2018
};

0 commit comments

Comments
 (0)