-
Notifications
You must be signed in to change notification settings - Fork 11
/
Otf2CallStackStateProvider.java
659 lines (602 loc) · 27.5 KB
/
Otf2CallStackStateProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
/**********************************************************************
* Copyright (c) 2021 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.tracecompass.incubator.internal.otf2.core.analysis.callstack;
import java.util.Map;
import java.util.Queue;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread;
import org.eclipse.tracecompass.incubator.callstack.core.base.EdgeStateValue;
import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.InstrumentedCallStackAnalysis;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.incubator.internal.otf2.core.analysis.IOtf2Constants;
import org.eclipse.tracecompass.incubator.internal.otf2.core.analysis.IOtf2Events;
import org.eclipse.tracecompass.incubator.internal.otf2.core.analysis.IOtf2Fields;
import org.eclipse.tracecompass.incubator.internal.otf2.core.analysis.IOtf2GlobalDefinitions;
import org.eclipse.tracecompass.incubator.internal.otf2.core.mpi.AllToRootIdentifiers;
import org.eclipse.tracecompass.incubator.internal.otf2.core.mpi.MessageIdentifiers;
import org.eclipse.tracecompass.incubator.internal.otf2.core.mpi.RootToAllIdentifiers;
import org.eclipse.tracecompass.incubator.internal.otf2.core.analysis.AbstractOtf2StateProvider;
/**
* Main state provider that defines the enter/leave states
*
* @author Yoann Heitz
*/
public class Otf2CallStackStateProvider extends AbstractOtf2StateProvider {
private static final String ID = "org.eclipse.tracecompass.incubator.otf2.callstackstateprovider"; //$NON-NLS-1$
/**
* Processes attribute
*/
public static final String PROCESSES = "Processes"; //$NON-NLS-1$
/**
* Whitespace string
*/
public static final String WHITESPACE = " "; //$NON-NLS-1$
/**
* Long representing the maximum value for a 32-bits unsigned integer
*/
protected static final long MAX_UINT32 = (1L << 32) - 1;
/**
* A class representing a node from the system tree. It is used to represent
* how the different machines are distributed into a MPI cluster and how the
* MPI ranks are distributed on each node.
*
* @author Yoann Heitz
*
*/
private class SystemTreeNode {
private final long fParentId;
private final int fNameId;
private final int fClassNameId;
private int fSystemTreeNodeQuark;
public SystemTreeNode(long parentId, int nameId, int classNameId) {
fParentId = parentId;
fNameId = nameId;
fClassNameId = classNameId;
fSystemTreeNodeQuark = UNKNOWN_ID;
}
public String getFullName() {
Map<Integer, String> stringIds = getStringId();
String name = stringIds.get(fNameId);
String className = stringIds.get(fClassNameId);
return className + WHITESPACE + name;
}
/*
* The method used to initialize the quark associated to this node. If
* the node ID of the parent of this node is the maximum value for
* unsigned integer, then this node is the root of a system tree. Else,
* the parent node is usually a machine node. Its quark must be
* retrieved and initialized if it was not done before.
*/
public void initializeQuarks(ITmfStateSystemBuilder ssb) {
if (fParentId == MAX_UINT32) {
fSystemTreeNodeQuark = ssb.getQuarkAbsoluteAndAdd(PROCESSES, getFullName());
} else {
int machineQuark = getSystemTreeNodeQuark(fParentId);
if (machineQuark == UNKNOWN_ID) {
SystemTreeNode parentNode = fMapSystemTreeNode.get(fParentId);
if (parentNode == null) {
return;
}
parentNode.initializeQuarks(ssb);
machineQuark = getSystemTreeNodeQuark(fParentId);
}
if (machineQuark != UNKNOWN_ID) {
fSystemTreeNodeQuark = ssb.getQuarkRelativeAndAdd(machineQuark, getFullName());
}
}
}
public int getQuark() {
return fSystemTreeNodeQuark;
}
}
private int getSystemTreeNodeQuark(long systemTreeNodeId) {
SystemTreeNode systemTreeNode = fMapSystemTreeNode.get(systemTreeNodeId);
if (systemTreeNode == null) {
return UNKNOWN_ID;
}
return systemTreeNode.getQuark();
}
/**
* A class representing a location group. It is used to represent a MPI
* rank. The group is associated to a system tree node which is the node on
* which is running this MPI rank.
*
* @author Yoann Heitz
*
*/
private class LocationGroup {
private final long fParentId;
private final int fNameId;
private final int fType;
private int fLocationGroupQuark;
public LocationGroup(long parentId, int nameId, int type) {
fParentId = parentId;
fNameId = nameId;
fType = type;
fLocationGroupQuark = UNKNOWN_ID;
}
public String getFullName() {
String name = getStringId().get(fNameId);
if (fType == 1 && name != null) {
return name;
}
return UNKNOWN;
}
public void initializeQuarks(ITmfStateSystemBuilder ssb) {
int nodeQuark = getSystemTreeNodeQuark(fParentId);
if (nodeQuark != UNKNOWN_ID) {
fLocationGroupQuark = ssb.getQuarkRelativeAndAdd(nodeQuark, getFullName());
}
}
public int getQuark() {
return fLocationGroupQuark;
}
}
private int getLocationGroupQuark(int locationGroupId) {
LocationGroup locationGroup = fMapLocationGroup.get(locationGroupId);
if (locationGroup == null) {
return UNKNOWN_ID;
}
return locationGroup.getQuark();
}
/**
* A class representing a location. When an OTF2 event is encountered,
* methods from this class will be used to modify the state of the
* associated attributes.
*
* @author Yoann Heitz
*
*/
private class Location {
private final long fLocationId;
private final int fLocationNameId;
private final int fProcessId;
private long fCollectiveBeginTimestamp;
private int fLocationQuark;
private int fCallStackQuark;
public Location(long id, int nameId, int processId) {
fLocationId = id;
fLocationNameId = nameId;
fProcessId = processId;
fCollectiveBeginTimestamp = 0L;
fLocationQuark = UNKNOWN_ID;
fCallStackQuark = UNKNOWN_ID;
}
/*
* This method will be called by each location when all definitions have
* been read : the name of the location may be computed at this moment,
* and the corresponding quark may be created.
*/
public void initializeQuarks(ITmfStateSystemBuilder ssb) {
// Get the name of the location
String locationName = getStringFromStringId(fLocationNameId);
// Create the associated quark
int processQuark = getLocationGroupQuark(fProcessId);
fLocationQuark = ssb.getQuarkRelativeAndAdd(processQuark, locationName);
fCallStackQuark = ssb.getQuarkRelativeAndAdd(fLocationQuark, InstrumentedCallStackAnalysis.CALL_STACK);
}
// This method is called when the location enters a code region
public void enter(ITmfEvent event, ITmfStateSystemBuilder ssb) {
ITmfEventField content = event.getContent();
long timestamp = event.getTimestamp().toNanos();
ssb.updateOngoingState(TmfStateValue.newValueLong(fLocationId), fLocationQuark);
Integer regionRef = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_REGION);
if (regionRef == null) {
ssb.modifyAttribute(timestamp, null, fCallStackQuark);
return;
}
ssb.pushAttribute(timestamp, getRegionNameFromRegionId(regionRef), fCallStackQuark);
}
// This method is called when the location leaves a code region
public void leave(ITmfEvent event, ITmfStateSystemBuilder ssb) {
long timestamp = event.getTimestamp().toNanos();
ssb.popAttribute(timestamp, fCallStackQuark);
}
/*
* This method is called when a location finished to send data through a
* MPI routine (it does not mean the location exited the associated code
* region). It stores the informations about the send event in order to
* link it to the receive event when encountered.
*
*/
public void mpiSend(ITmfEvent srcEvent) {
ITmfEventField content = srcEvent.getContent();
Integer communicator = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_COMMUNICATOR);
if (communicator == null) {
return;
}
Integer srcRank = getRank(fLocationId, communicator);
Integer destRank = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_RECEIVER);
Integer messageTag = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_MESSAGE_TAG);
if (destRank == null || messageTag == null || srcRank == UNKNOWN_RANK) {
return;
}
fMsgDataEvent.put(new MessageIdentifiers(communicator, srcRank, destRank, messageTag), srcEvent);
}
/*
* This method is called when a location finished to receive data
* through a MPI routine (it does not mean the location exited the
* associated code region). It searches for the associated send event
* and draw an edge between the two events.
*
*/
public void mpiRecv(ITmfEvent destEvent, ITmfStateSystemBuilder ssb) {
ITmfEventField content = destEvent.getContent();
Integer communicator = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_COMMUNICATOR);
if (communicator == null) {
return;
}
Integer srcRank = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_SENDER);
Integer destRank = getRank(fLocationId, communicator);
Integer messageTag = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_MESSAGE_TAG);
if (srcRank == null || messageTag == null || destRank == UNKNOWN_RANK) {
return;
}
ITmfEvent srcEvent = fMsgDataEvent.remove(new MessageIdentifiers(communicator, srcRank, destRank, messageTag));
if (srcEvent == null) {
return;
}
long srcLocationId = getLocationId(srcEvent);
HostThread src = new HostThread(srcEvent.getTrace().getHostId(), (int) srcLocationId);
HostThread dest = new HostThread(destEvent.getTrace().getHostId(), (int) fLocationId);
addArrow(ssb, srcEvent.getTimestamp().toNanos(), destEvent.getTimestamp().toNanos(), messageTag, src, dest);
}
// Called when a collective routine is called by this location
public void mpiCollectiveBegin(ITmfEvent event) {
fCollectiveBeginTimestamp = event.getTimestamp().toNanos();
}
/*
* Called when a location finished an one to all MPI operation. This
* location is necessarily a destination in an exchange of data. The
* event corresponding to the root sending the data is retrieved in
* order to draw an edge
*/
public void mpiRootToAll(ITmfEvent destEvent, ITmfStateSystemBuilder ssb) {
ITmfEventField content = destEvent.getContent();
// Get the informations about the communication from the event
Integer root = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_ROOT);
Integer communicator = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_COMMUNICATOR);
Integer operationCode = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_COLLECTIVE_OPERATION);
if (root == null || communicator == null || operationCode == null) {
return;
}
long srcLocationId = getLocationIdFromRank(root, communicator);
/*
* Checks if the MPI routine for this communication has already been
* called and finished by another location
*/
RootToAllIdentifiers associatedOperation = null;
for (RootToAllIdentifiers operationProperties : fRootToAllQueue) {
if (operationProperties.isAssociatedOperation(operationCode, srcLocationId, communicator, fLocationId)) {
associatedOperation = operationProperties;
}
}
/*
* If this is the first location to end the routine, an object
* representing the state of the communication is created, also it
* means that the location where this event appeared is the root of
* the communication (the root also sends data to itself)
*/
ITmfEvent srcEvent = null;
if (associatedOperation == null) {
srcEvent = destEvent;
ArrayList<Long> members = getMembersFromCommunicatorReference(communicator);
ArrayList<Long> pendingLocations = new ArrayList<>(members);
associatedOperation = new RootToAllIdentifiers(operationCode, communicator, srcLocationId, srcEvent, pendingLocations);
fRootToAllQueue.add(associatedOperation);
}
// Update the state of the communication and draw edge
associatedOperation.locationCalledOperation(fLocationId, fCollectiveBeginTimestamp);
if (associatedOperation.isOperationDone()) {
fRootToAllQueue.remove(associatedOperation);
}
if (srcLocationId == fLocationId) {
return;
}
if (srcEvent == null) {
srcEvent = associatedOperation.getBeginEvent();
}
HostThread src = new HostThread(srcEvent.getTrace().getHostId(), (int) srcLocationId);
HostThread dest = new HostThread(destEvent.getTrace().getHostId(), (int) fLocationId);
addArrow(ssb, srcEvent.getTimestamp().toNanos(), destEvent.getTimestamp().toNanos(), root, src, dest);
}
/*
* Called when a location finished an all to one MPI operation. This
* location is necessarily a source in an exchange of data. The
* informations about the event are stored : if it is the root
* (receiver) that call this method then the communication is done and
* edges may be drawn.
*/
public void mpiAllToRoot(ITmfEvent srcEvent, ITmfStateSystemBuilder ssb) {
ITmfEventField content = srcEvent.getContent();
// Gets the informations about the communication from the event
Integer root = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_ROOT);
Integer communicator = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_COMMUNICATOR);
Integer operationCode = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_COLLECTIVE_OPERATION);
if (root == null || communicator == null || operationCode == null) {
return;
}
long destLocationId = getLocationIdFromRank(root, communicator);
/*
* Checks if the MPI routine for this communication has already been
* called and finished by another location
*/
AllToRootIdentifiers associatedOperation = null;
for (AllToRootIdentifiers operationProperties : fAllToRootQueue) {
if (operationProperties.isAssociatedOperation(operationCode, destLocationId, communicator, fLocationId)) {
associatedOperation = operationProperties;
}
}
/*
* If this is the first location to end the routine, an object
* representing the state of the communication is created
*/
if (associatedOperation == null) {
ArrayList<Long> members = getMembersFromCommunicatorReference(communicator);
ArrayList<Long> pendingLocations = new ArrayList<>(members);
associatedOperation = new AllToRootIdentifiers(operationCode, communicator, destLocationId, pendingLocations);
fAllToRootQueue.add(associatedOperation);
}
// Updates the state of the communication
associatedOperation.locationCalledOperation(fLocationId, srcEvent);
/*
* If the communication is finished (routine called by all the
* locations in communicator), then the location where this event
* appeared is the root : edges are drawn from all the other
* locations in the communicator, at the moment where they called
* the routine to this location at the time of the event
*/
if (associatedOperation.isOperationDone()) {
fAllToRootQueue.remove(associatedOperation);
Collection<ITmfEvent> sentEvents = associatedOperation.getBeginEvents();
for (ITmfEvent sentEvent : sentEvents) {
HostThread src = new HostThread(sentEvent.getTrace().getHostId(), (int) getLocationId(sentEvent));
HostThread dest = new HostThread(srcEvent.getTrace().getHostId(), (int) getLocationId(srcEvent));
addArrow(ssb, sentEvent.getTimestamp().toNanos(), srcEvent.getTimestamp().toNanos(), 0, src, dest);
}
}
}
}
/**
* Mapping tables required for this analysis
*/
private final Map<Long, SystemTreeNode> fMapSystemTreeNode = new HashMap<>();
private final Map<Integer, LocationGroup> fMapLocationGroup = new HashMap<>();
private final Map<Long, Location> fMapLocation = new HashMap<>();
private final Map<MessageIdentifiers, ITmfEvent> fMsgDataEvent = new HashMap<>();
private final Queue<RootToAllIdentifiers> fRootToAllQueue = new LinkedList<>();
private final Queue<AllToRootIdentifiers> fAllToRootQueue = new LinkedList<>();
private boolean fAllDefinitionsRead;
/**
* @param trace
* Trace to follow
*/
public Otf2CallStackStateProvider(@Nullable ITmfTrace trace) {
super(trace, ID);
fAllDefinitionsRead = false;
}
@Override
public int getVersion() {
return 2;
}
@Override
public ITmfStateProvider getNewInstance() {
return new Otf2CallStackStateProvider(getTrace());
}
@Override
protected void processGlobalDefinition(ITmfEvent event, String name) {
switch (name) {
case IOtf2GlobalDefinitions.OTF2_STRING: {
processStringDefinition(event);
break;
}
case IOtf2GlobalDefinitions.OTF2_REGION: {
processRegionDefinition(event);
break;
}
case IOtf2GlobalDefinitions.OTF2_LOCATION: {
processLocationDefinition(event);
break;
}
case IOtf2GlobalDefinitions.OTF2_LOCATION_GROUP: {
processLocationGroupDefinition(event);
break;
}
case IOtf2GlobalDefinitions.OTF2_COMM: {
processCommunicatorDefinition(event);
break;
}
case IOtf2GlobalDefinitions.OTF2_GROUP: {
processGroupDefinition(event);
break;
}
case IOtf2GlobalDefinitions.OTF2_GROUP_MEMBER: {
processGroupMemberDefinition(event);
break;
}
case IOtf2GlobalDefinitions.OTF2_SYSTEM_TREE_NODE: {
processSystemTreeNodeDefinition(event);
break;
}
default:
return;
}
}
private void processLocationDefinition(ITmfEvent event) {
ITmfEventField content = event.getContent();
Long locationReference = content.getFieldValue(Long.class, IOtf2Fields.OTF2_SELF);
Integer locationGroupReference = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_LOCATION_GROUP);
Integer stringReference = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_NAME);
if (locationReference == null || locationGroupReference == null || stringReference == null) {
return;
}
fMapLocation.put(locationReference, new Location(locationReference, stringReference, locationGroupReference));
}
private void processLocationGroupDefinition(ITmfEvent event) {
ITmfEventField content = event.getContent();
Integer locationGroupReference = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_SELF);
Integer nameReference = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_NAME);
Integer locationGroupType = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_LOCATION_GROUP_TYPE);
Long parentReference = content.getFieldValue(Long.class, IOtf2Fields.OTF2_SYSTEM_TREE_PARENT);
if (locationGroupReference == null || nameReference == null || locationGroupType == null || parentReference == null) {
return;
}
LocationGroup locationGroup = new LocationGroup(parentReference, nameReference, locationGroupType);
fMapLocationGroup.put(locationGroupReference, locationGroup);
}
private void processSystemTreeNodeDefinition(ITmfEvent event) {
ITmfEventField content = event.getContent();
Long selfReference = content.getFieldValue(Long.class, IOtf2Fields.OTF2_SELF);
Integer nameReference = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_NAME);
Integer classNameReference = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_CLASS_NAME);
Long parentReference = content.getFieldValue(Long.class, IOtf2Fields.OTF2_SYSTEM_TREE_PARENT);
if (selfReference == null || nameReference == null || classNameReference == null || parentReference == null) {
return;
}
SystemTreeNode systemTreeNode = new SystemTreeNode(parentReference, nameReference, classNameReference);
fMapSystemTreeNode.put(selfReference, systemTreeNode);
}
@Override
protected void processOtf2Event(ITmfEvent event, String name, ITmfStateSystemBuilder ssb) {
/*
* If an OTF2 event is encountered, it means all definitions were read :
* if this is the first event to be read then quarks associated to the
* locations need to be initialized
*/
if (!fAllDefinitionsRead) {
initializeQuarks(ssb);
fAllDefinitionsRead = true;
}
long locationId = getLocationId(event);
Location location = fMapLocation.get(locationId);
if (location == null) {
return;
}
switch (name) {
case IOtf2Events.OTF2_ENTER: {
location.enter(event, ssb);
break;
}
case IOtf2Events.OTF2_LEAVE: {
location.leave(event, ssb);
break;
}
case IOtf2Events.OTF2_MPI_SEND:
case IOtf2Events.OTF2_MPI_ISEND: {
location.mpiSend(event);
break;
}
case IOtf2Events.OTF2_MPI_RECV:
case IOtf2Events.OTF2_MPI_IRECV: {
location.mpiRecv(event, ssb);
break;
}
case IOtf2Events.OTF2_MPI_COLLECTIVE_BEGIN: {
location.mpiCollectiveBegin(event);
break;
}
case IOtf2Events.OTF2_MPI_COLLECTIVE_END: {
processMpiCollectiveEnd(event, ssb, location);
break;
}
default:
return;
}
}
/*
* Iterates over all the location and initializes the associated quarks
*/
private void initializeQuarks(ITmfStateSystemBuilder ssb) {
for (SystemTreeNode systemTreeNode : fMapSystemTreeNode.values()) {
systemTreeNode.initializeQuarks(ssb);
}
for (LocationGroup locationGroup : fMapLocationGroup.values()) {
locationGroup.initializeQuarks(ssb);
}
for (Location location : fMapLocation.values()) {
location.initializeQuarks(ssb);
}
}
/**
* Return the location id of a process into an MPI communicator.
*
* @param rank
* The rank of the process in the communicator
* @param communicatorReference
* The communicator id
* @return The rank of the location into the communicator
*/
protected long getLocationIdFromRank(Integer rank, Integer communicatorReference) {
ArrayList<Long> members = getMembersFromCommunicatorReference(communicatorReference);
if (rank >= members.size()) {
return UNKNOWN_RANK;
}
return members.get(rank);
}
/*
* Calls the corresponding method from the associated location given the
* type of event
*/
private static void processMpiCollectiveEnd(ITmfEvent event, ITmfStateSystemBuilder ssb, Location location) {
ITmfEventField content = event.getContent();
Integer operationCode = content.getFieldValue(Integer.class, IOtf2Fields.OTF2_COLLECTIVE_OPERATION);
if (operationCode == null) {
return;
}
switch (IOtf2Constants.getOperation(operationCode)) {
case BCAST:
case SCATTER:
case SCATTERV: {
location.mpiRootToAll(event, ssb);
return;
}
case GATHER:
case GATHERV:
case REDUCE: {
location.mpiAllToRoot(event, ssb);
return;
}
// $CASES-OMITTED$
default:
return;
}
}
private static void addArrow(ITmfStateSystemBuilder ssb, Long startTime, Long endTime, int id,
HostThread src, HostThread dest) {
int edgeQuark = getAvailableEdgeQuark(ssb, startTime);
Object edgeStateValue = new EdgeStateValue(id, src, dest);
ssb.modifyAttribute(startTime, edgeStateValue, edgeQuark);
ssb.modifyAttribute(endTime, (Object) null, edgeQuark);
}
private static int getAvailableEdgeQuark(ITmfStateSystemBuilder ssb, Long startTime) {
int edgeRoot = ssb.getQuarkAbsoluteAndAdd(IOtf2Constants.EDGES);
List<@NonNull Integer> subQuarks = ssb.getSubAttributes(edgeRoot, false);
for (int quark : subQuarks) {
long start = ssb.getOngoingStartTime(quark);
Object value = ssb.queryOngoing(quark);
if (value == null && start <= startTime) {
return quark;
}
}
return ssb.getQuarkRelativeAndAdd(edgeRoot, Integer.toString(subQuarks.size()));
}
}