OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

vt_unify_defs.h
1 /**
2 * VampirTrace
3 * http://www.tu-dresden.de/zih/vampirtrace
4 *
5 * Copyright (c) 2005-2012, ZIH, TU Dresden, Federal Republic of Germany
6 *
7 * Copyright (c) 1998-2005, Forschungszentrum Juelich, Juelich Supercomputing
8 * Centre, Federal Republic of Germany
9 *
10 * See the file COPYING in the package base directory for details
11 **/
12
13 #ifndef _VT_UNIFY_DEFS_H_
14 #define _VT_UNIFY_DEFS_H_
15
16 #include "config.h"
17
18 #include "vt_unify_defs_recs.h"
19 #include "vt_unify_lvector.hh"
20 #include "vt_unify_usrcom.h"
21
22 #include "vt_inttypes.h"
23
24 #include <algorithm>
25 #include <list>
26 #include <map>
27 #include <set>
28 #include <string>
29
30 //
31 // DefinitionsC class
32 //
33 class DefinitionsC
34 {
35 public:
36
37 // forward declaration of sub-class GroupCountersC
38 class GroupCountersC;
39
40 // constructor
41 DefinitionsC();
42
43 // destructor
44 ~DefinitionsC();
45
46 // unify definitions
47 bool run();
48
49 // rename temporary output files
50 bool cleanUp();
51
52 // get instance of sub-class GroupCountersC
53 GroupCountersC * groupCounters() const { return m_groupCntrs; }
54
55 private:
56
57 // forward declaration of sub-class CommentsC
58 class CommentsC;
59
60 // forward declaration of sub-class ProcessGroupsC
61 class ProcessGroupsC;
62
63 // read local definitions
64 bool readLocal();
65
66 // read local definitions of certain single stream
67 bool readLocal( const uint32_t & streamId,
68 LargeVectorC<DefRec_BaseS*> & locDefs );
69
70 // process local definitions
71 // (i.e. create global tokens)
72 bool processLocal( const LargeVectorC<DefRec_BaseS*> & locDefs );
73
74 // write global definitions
75 bool writeGlobal();
76
77 // instance of sub-class GroupCountersC
78 GroupCountersC * m_groupCntrs;
79
80 // instance of sub-class CommentsC
81 CommentsC * m_comments;
82
83 // instance of sub-class ProcessGroupsC
84 ProcessGroupsC * m_procGrps;
85
86 //
87 // storage of global definitions
88 //
89 struct
90 {
91 // global definitions created by TokenFactoryScopeC
92 // (concerns all definitions which define an identifier token
93 // that has to be unified)
94 //
95
96 std::set<DefRec_DefProcessGroupS> procGrps;
97 std::set<DefRec_DefSclFileS> sclFiles;
98 std::set<DefRec_DefSclS> scls;
99 std::set<DefRec_DefFileGroupS> fileGrps;
100 std::set<DefRec_DefFileS> files;
101 std::set<DefRec_DefFunctionGroupS> funcGrps;
102 std::set<DefRec_DefFunctionS> funcs;
103 std::set<DefRec_DefCollOpS> collops;
104 std::set<DefRec_DefCounterGroupS> cntrGrps;
105 std::set<DefRec_DefCounterS> cntrs;
106 std::set<DefRec_DefKeyValueS> keyVals;
107
108 // miscellaneous global definitions
109 //
110
111 DefRec_DefCreatorS creator;
112 DefRec_DefTimerResolutionS timeres;
113 DefRec_DefTimeRangeS timerange;
114 std::set<DefRec_DefCommentS> comments;
115 std::set<DefRec_DefProcessS> procs;
116 // map global counter token <-> process group assignments
117 std::map<uint32_t, DefRec_DefCounterAssignmentsS>
118 cntrAssigns;
119 // map global process group token <-> attributes
120 std::map<uint32_t, DefRec_DefProcessGroupAttributesS>
121 procGrpAttrs;
122
123 } m_globDefs;
124
125 };
126
127 //
128 // DefinitionsC::GroupCountersC sub-class
129 // (manages process group assignments of group counters)
130 //
131 class DefinitionsC::GroupCountersC
132 {
133 public:
134
135 // constructor
136 GroupCountersC( DefinitionsC & _defs ) : m_defs( _defs ) {}
137
138 // destructor
139 ~GroupCountersC() {}
140
141 // set local process group token for local process/counter token
142 // (only one process group assignment per counter allowed)
143 void setGroup( const uint32_t & proc, const uint32_t & counter,
144 const uint32_t & procGrp )
145 {
146 m_cntr2ProcGrp[std::make_pair( proc, counter )] = procGrp;
147 }
148
149 // get local process group token of certain local process/counter token
150 uint32_t getGroup( const uint32_t & proc, const uint32_t & counter ) const
151 {
152 // search for process group assignment
153 std::map<std::pair<uint32_t, uint32_t>, uint32_t>::const_iterator it =
154 m_cntr2ProcGrp.find( std::make_pair( proc, counter ) );
155
156 // if found, return local process group token; otherwise, return 0
157 //
158 if( it != m_cntr2ProcGrp.end() )
159 return it->second;
160 else
161 return 0;
162 }
163
164 // The following methods are significant for the final stream/process[group]
165 // mapping in the OTF master control file.
166 //
167
168 // add global process group token to stream
169 void addGroupToStream( const uint32_t & streamid, const uint32_t & procGrp )
170 {
171 if( m_streamId2ProcGrps[streamid].insert( procGrp ).second )
172 {
173 // catch multiple added process groups
174 //
175 bool added_once = m_procGrps.insert( procGrp ).second;
176 assert( added_once );
177 }
178 }
179
180 // get global process group tokens of certain stream
181 const std::set<uint32_t> * getGroupsOfStream(
182 const uint32_t & streamid ) const
183 {
184 // search for stream id
185 std::map<uint32_t, std::set<uint32_t> >::const_iterator it =
186 m_streamId2ProcGrps.find( streamid );
187
188 // if found, return pointer to set of global process group tokens;
189 // otherwise, return 0
190 //
191 if( it != m_streamId2ProcGrps.end() )
192 return &(it->second);
193 else
194 return 0;
195 }
196
197 private:
198
199 // reference to parent class instance
200 DefinitionsC & m_defs;
201
202 // set of global process group tokens which have counters
203 std::set<uint32_t> m_procGrps;
204
205 // map stream id <-> global process group tokens
206 std::map<uint32_t, std::set<uint32_t> > m_streamId2ProcGrps;
207
208 // map local process/counter token <-> local process group token
209 std::map<std::pair<uint32_t, uint32_t>, uint32_t> m_cntr2ProcGrp;
210
211 };
212
213 //
214 // DefinitionsC::CommentsC sub-class
215 // (pre-processes comments before adding these to global definitions)
216 //
217 class DefinitionsC::CommentsC
218 {
219 public:
220
221 // constructor
222 CommentsC( DefinitionsC & _defs )
223 : m_defs( _defs ), m_minStartTimeEpoch( (uint64_t)-1 ),
224 m_maxStopTimeEpoch( 0 ), m_seqOrderIdx( 0 ) {}
225
226 // destructor
227 ~CommentsC() {}
228
229 // process local definition comment
230 bool processLocal( const DefRec_DefCommentS & locComment );
231
232 // finish global definition comments
233 // (i.e. add trace time comments to global definitions)
234 bool finish();
235
236 private:
237
238 // reference to parent class instance
239 DefinitionsC & m_defs;
240
241 // trace times
242 //
243 uint64_t m_minStartTimeEpoch;
244 uint64_t m_maxStopTimeEpoch;
245
246 // sequential order index
247 uint32_t m_seqOrderIdx;
248
249 };
250
251 //
252 // DefinitionsC::ProcessGroupsC sub-class
253 // (pre-processes process groups before adding these to global definitions)
254 //
255 class DefinitionsC::ProcessGroupsC
256 {
257 // friend declaration for sub-class DefinitionsC::CommentsC;
258 // needs access to m_userCom to add member process ids to certain user
259 // communicators
260 friend class DefinitionsC::CommentsC;
261
262 public:
263
264 // constructor
265 ProcessGroupsC( DefinitionsC & _defs ) : m_defs( _defs ) {}
266
267 // destructor
268 ~ProcessGroupsC()
269 {
270 for( uint32_t i = 0; i < m_uniqueMembers.size(); i++ )
271 delete m_uniqueMembers[i];
272 }
273
274 // process local process group definition
275 bool processLocal( DefRec_DefProcessGroupS & locProcGrp );
276
277 // finish global process group definitions
278 // (i.e. add process groups for nodes and MPI-comms. to global defs.)
279 bool finish();
280
281 // deflate group member array of certain process group definition
282 // (replaces array elements by an unique id)
283 inline void deflateMembers( DefRec_DefProcessGroupS & procGrp );
284
285 // inflate group members array of certain process group definition
286 // (replaces unique id by the actual array elements)
287 inline void inflateMembers( DefRec_DefProcessGroupS & procGrp );
288
289 private:
290
291 // identifier for deflated group member arrays
292 // (will be putted at the first array element)
293 static const uint32_t DEFLATED_MEMBERS_TAG = (uint32_t)-1;
294
295 //
296 // compare structure for sorting process ids
297 //
298 struct ProcCmpS
299 {
300 bool operator()( const uint32_t & a, const uint32_t & b ) const
301 {
302 if( ( a & VT_TRACEID_BITMASK ) == ( b & VT_TRACEID_BITMASK ) )
303 return a < b;
304 else
305 return ( a & VT_TRACEID_BITMASK ) < ( b & VT_TRACEID_BITMASK );
306 }
307
308 };
309
310 //
311 // structure for storing unique (un-deflated) group member arrays
312 //
313 struct UniqueMembersS
314 {
315 UniqueMembersS( uint32_t _id, uint32_t _nmembers,
316 const uint32_t * _members )
317 : id( _id ), nmembers( _nmembers ), members( 0 )
318 {
319 assert( nmembers > 0 );
320
321 members = new uint32_t[nmembers];
322 assert( members );
323
324 memcpy( members, _members, nmembers * sizeof( uint32_t ) );
325 }
326 ~UniqueMembersS()
327 {
328 delete [] members;
329 }
330
331 uint32_t id; // unique id representing this group member array
332 uint32_t nmembers; // number of group members
333 uint32_t * members; // array of group members
334
335 };
336
337 //
338 // scope for MPI communicators and groups
339 //
340 struct MpiS
341 {
342 //
343 // sub-scope for MPI_COMM_WORLD
344 //
345 struct WorldCommS
346 {
347 WorldCommS() : global_token( 0 ) {}
348
349 // name of final process group
350 static const char * NAME() { return "MPI_COMM_WORLD"; }
351
352 // global process group token
353 uint32_t global_token;
354
355 } worldComm;
356
357 //
358 // sub-scope for MPI_COMM_SELFs
359 //
360 struct SelfCommsS
361 {
362 // name (prefix) of final process groups
363 static const char * NAME() { return "MPI_COMM_SELF"; }
364
365 } selfComms;
366
367 //
368 // sub-scope for user created MPI communicators and groups
369 //
370 struct CommsAndGroupsS
371 {
372 CommsAndGroupsS() : comm_seqno( 0 ), group_seqno( 0 ) {}
373
374 // name (prefix) of final process groups
375 //
376 static const char * COMM_NAME() { return "MPI Communicator"; }
377 static const char * GROUP_NAME() { return "MPI Group"; }
378
379 // communicator/group sequential number (=name suffix)
380 //
381 uint32_t comm_seqno;
382 uint32_t group_seqno;
383
384 // map process/membersid <-> count
385 std::map<std::pair<uint32_t, uint32_t>, uint32_t> counts;
386
387 // map membersid/count <-> global token
388 std::map<std::pair<uint32_t, uint32_t>, uint32_t> global_tokens;
389
390 } commsAndGroups;
391
392 } m_mpi;
393
394 //
395 // scope for communicators of user communication
396 //
397 struct UserComS
398 {
399 //
400 // structure for user communicators
401 //
402 struct CommS
403 {
404 CommS() : global_token( 0 ) {}
405
406 uint32_t global_token; // global comm. token
407 std::set<uint32_t, ProcCmpS> members; // member process ids
408
409 };
410
411 // add member process id to certain user communicator
412 void addCommMember( const uint32_t & comm, const uint32_t & member )
413 {
414 std::map<uint32_t, CommS*>::iterator it =
415 globTk2Comm.find( comm );
416 assert( it != globTk2Comm.end() );
417
418 it->second->members.insert( member );
419 }
420
421 // map name <-> communicator
422 std::map<std::string, CommS*> name2Comm;
423
424 // map global token <-> communicator
425 std::map<uint32_t, CommS*> globTk2Comm;
426
427 } m_userCom;
428
429 //
430 // scope for other process groups (e.g. nodes, GPU comms./groups)
431 //
432 struct OtherS
433 {
434 // name of final process group containing all processes
435 static const char * ALL_NAME() { return "All"; }
436
437 //
438 // structure for other process groups
439 //
440 struct GroupS
441 {
442 GroupS() : global_token( 0 ) {}
443
444 uint32_t global_token; // global process group token
445 std::set<uint32_t, ProcCmpS> members; // member process ids
446
447 };
448
449 // map name <-> process group
450 std::map<std::string, GroupS> name2Group;
451
452 } m_other;
453
454 // map hash <-> unique group members array(s)
455 std::multimap<uint32_t, UniqueMembersS*> m_hash2UniqueMembers;
456
457 // vector of unique group member arrays
458 std::vector<UniqueMembersS*> m_uniqueMembers;
459
460 // reference to parent class instance
461 DefinitionsC & m_defs;
462
463 };
464
465 // instance of class DefinitionsC
466 extern DefinitionsC * theDefinitions;
467
468 #endif // _VT_UNIFY_DEFS_H_
DefRec_DefCreatorS
Definition: vt_unify_defs_recs.h:165
DefRec_DefCommentS
Definition: vt_unify_defs_recs.h:109
DefinitionsC::ProcessGroupsC::MpiS::CommsAndGroupsS
Definition: vt_unify_defs.h:370
DefinitionsC::ProcessGroupsC::MpiS::WorldCommS
Definition: vt_unify_defs.h:345
DefinitionsC::GroupCountersC
Definition: vt_unify_defs.h:131
DefinitionsC::ProcessGroupsC::UserComS::CommS
Definition: vt_unify_defs.h:402
DefinitionsC::ProcessGroupsC::OtherS::GroupS
Definition: vt_unify_defs.h:440
DefRec_DefTimeRangeS
Definition: vt_unify_defs_recs.h:212
DefRec_DefProcessGroupS
Definition: vt_unify_defs_recs.h:291
DefRec_DefTimerResolutionS
Definition: vt_unify_defs_recs.h:188
DefinitionsC::ProcessGroupsC
Definition: vt_unify_defs.h:255
DefinitionsC
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_unify_defs.h:33
DefinitionsC::CommentsC
Definition: vt_unify_defs.h:217
DefinitionsC::ProcessGroupsC::MpiS::SelfCommsS
Definition: vt_unify_defs.h:360