-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpiPi.c
1368 lines (1141 loc) · 36.4 KB
/
mpiPi.c
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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- C -*-
mpiP MPI Profiler ( http://llnl.github.io/mpiP )
Please see COPYRIGHT AND LICENSE information at the end of this file.
-----
mpiPi.c -- main mpiP internal functions
*/
#ifndef lint
static char *svnid = "$Id$";
#endif
#include <string.h>
#include <float.h>
#include <unistd.h>
#include "mpiPi.h"
static int
mpiPi_callsite_stats_pc_hashkey (const void *p)
{
int res = 0;
int i;
callsite_stats_t *csp = (callsite_stats_t *) p;
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp);
for (i = 0; i < MPIP_CALLSITE_STACK_DEPTH; i++)
{
res ^= (unsigned) (long) csp->pc[i];
}
return 52271 ^ csp->op ^ res ^ csp->rank;
}
static int
mpiPi_callsite_stats_pc_comparator (const void *p1, const void *p2)
{
int i;
callsite_stats_t *csp_1 = (callsite_stats_t *) p1;
callsite_stats_t *csp_2 = (callsite_stats_t *) p2;
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp_1);
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp_2);
#define express(f) {if ((csp_1->f) > (csp_2->f)) {return 1;} if ((csp_1->f) < (csp_2->f)) {return -1;}}
express (op);
express (rank);
for (i = 0; i < MPIP_CALLSITE_STACK_DEPTH; i++)
{
express (pc[i]);
}
#undef express
return 0;
}
static int
mpiPi_callsite_stats_src_hashkey (const void *p)
{
int res = 0;
callsite_stats_t *csp = (callsite_stats_t *) p;
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp);
return 52271 ^ csp->op ^ res ^ csp->rank ^ csp->csid;
}
static int
mpiPi_callsite_stats_src_comparator (const void *p1, const void *p2)
{
callsite_stats_t *csp_1 = (callsite_stats_t *) p1;
callsite_stats_t *csp_2 = (callsite_stats_t *) p2;
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp_1);
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp_2);
#define express(f) {if ((csp_1->f) > (csp_2->f)) {return 1;} if ((csp_1->f) < (csp_2->f)) {return -1;}}
express (op);
express (csid);
express (rank);
#undef express
return 0;
}
static int
mpiPi_callsite_stats_MPI_id_hashkey (const void *p)
{
callsite_stats_t *csp = (callsite_stats_t *) p;
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp);
return 52271 ^ csp->op;
}
static int
mpiPi_callsite_stats_src_id_hashkey (const void *p)
{
int res = 0;
callsite_stats_t *csp = (callsite_stats_t *) p;
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp);
return 52271 ^ csp->op ^ res ^ csp->csid;
}
static int
mpiPi_callsite_stats_src_id_comparator (const void *p1, const void *p2)
{
callsite_stats_t *csp_1 = (callsite_stats_t *) p1;
callsite_stats_t *csp_2 = (callsite_stats_t *) p2;
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp_1);
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp_2);
#define express(f) {if ((csp_1->f) > (csp_2->f)) {return 1;} if ((csp_1->f) < (csp_2->f)) {return -1;}}
express (op);
express (csid);
#undef express
return 0;
}
#ifndef ENABLE_API_ONLY /* { */
/* task level init
- executed by each MPI task only once immediately after MPI_Init
*/
void
init_histogram (mpiPi_histogram_t * h, int first_bin_max, int size,
int *intervals)
{
h->first_bin_max = first_bin_max;
h->hist_size = size;
h->bin_intervals = intervals;
}
void
mpiPi_init (char *appName)
{
if (time (&mpiPi.start_timeofday) == (time_t) - 1)
{
mpiPi_msg_warn ("Could not get time of day from time()\n");
}
mpiPi.toolname = "mpiP";
mpiPi.comm = MPI_COMM_WORLD;
mpiPi.tag = 9821;
mpiPi.procID = getpid ();
mpiPi.appName = strdup (appName);
PMPI_Comm_rank (mpiPi.comm, &mpiPi.rank);
PMPI_Comm_size (mpiPi.comm, &mpiPi.size);
PMPI_Get_processor_name (mpiPi.hostname, &mpiPi.hostnamelen);
mpiPi.stdout_ = stdout;
mpiPi.stderr_ = stderr;
mpiPi.lookup = mpiPi_lookup;
mpiPi.enabled = 1;
mpiPi.enabledCount = 1;
mpiPi.cumulativeTime = 0.0;
mpiPi.global_app_time = 0.0;
mpiPi.global_mpi_time = 0.0;
mpiPi.global_mpi_size = 0.0;
mpiPi.global_mpi_io = 0.0;
mpiPi.global_mpi_rma = 0.0;
mpiPi.global_mpi_msize_threshold_count = 0;
mpiPi.global_mpi_sent_count = 0;
mpiPi.global_time_callsite_count = 0;
mpiPi.global_task_hostnames = NULL;
mpiPi.global_task_app_time = NULL;
mpiPi.global_task_mpi_time = NULL;
/* set some defaults values */
mpiPi.collectorRank = 0;
mpiPi.tableSize = 256;
mpiPi.reportPrintThreshold = 0.0;
mpiPi.baseNames = 0;
mpiPi.reportFormat = MPIP_REPORT_SCI_FORMAT;
mpiPi.calcCOV = 1;
mpiPi.inAPIrtb = 0;
mpiPi.do_lookup = 1;
mpiPi.messageCountThreshold = -1;
if (DEFAULT_REPORT_FORMAT == mpiPi_style_concise)
{
mpiPi.report_style = mpiPi_style_concise;
mpiPi.stackDepth = 0;
mpiPi.print_callsite_detail = 0;
}
else // verbose default
{
mpiPi.report_style = mpiPi_style_verbose;
mpiPi.stackDepth = 1;
mpiPi.print_callsite_detail = 1;
}
#ifdef COLLECTIVE_REPORT_DEFAULT
mpiPi.collective_report = 1;
#else
mpiPi.collective_report = 0;
#endif
mpiPi.disable_finalize_report = 0;
mpiPi.do_collective_stats_report = 0;
mpiPi.do_pt2pt_stats_report = 0;
#ifdef SO_LOOKUP
mpiPi.so_info = NULL;
#endif
mpiPi_getenv ();
mpiPi.task_callsite_stats =
h_open (mpiPi.tableSize, mpiPi_callsite_stats_pc_hashkey,
mpiPi_callsite_stats_pc_comparator);
if (mpiPi.do_collective_stats_report == 1)
{
init_histogram (&mpiPi.coll_comm_histogram, 7, 32, NULL);
init_histogram (&mpiPi.coll_size_histogram, 7, 32, NULL);
}
if (mpiPi.do_pt2pt_stats_report == 1)
{
init_histogram (&mpiPi.pt2pt_comm_histogram, 7, 32, NULL);
init_histogram (&mpiPi.pt2pt_size_histogram, 7, 32, NULL);
}
/* -- welcome msg only collector */
if (mpiPi.collectorRank == mpiPi.rank)
{
mpiPi_msg ("");
mpiPi_msg ("%s V%d.%d.%d (Build %s/%s)\n", mpiPi.toolname, mpiPi_vmajor,
mpiPi_vminor, mpiPi_vpatch, mpiPi_vdate, mpiPi_vtime);
mpiPi_msg ("Direct questions and errors to %s\n", MPIP_HELP_LIST);
mpiPi_msg ("\n");
}
mpiPi_msg_debug ("appName is %s\n", appName);
mpiPi_msg_debug ("sizeof(callsite_stats_t) is %d\n",
sizeof (callsite_stats_t));
mpiPi_msg_debug ("successful init on %d, %s\n", mpiPi.rank, mpiPi.hostname);
if (mpiPi.enabled)
{
mpiPi_GETTIME (&mpiPi.startTime);
}
return;
}
#endif /* } ifndef ENABLE_API_ONLY */
typedef struct callsite_cache_entry_t
{
void *pc;
char *filename;
char *functname;
int line;
}
callsite_pc_cache_entry_t;
h_t *callsite_pc_cache = NULL;
static int
callsite_pc_cache_comparator (const void *p1, const void *p2)
{
callsite_pc_cache_entry_t *cs1 = (callsite_pc_cache_entry_t *) p1;
callsite_pc_cache_entry_t *cs2 = (callsite_pc_cache_entry_t *) p2;
if ((long) cs1->pc > (long) cs2->pc)
{
return 1;
}
if ((long) cs1->pc < (long) cs2->pc)
{
return -1;
}
return 0;
}
static int
callsite_pc_cache_hashkey (const void *p1)
{
callsite_pc_cache_entry_t *cs1 = (callsite_pc_cache_entry_t *) p1;
return 662917 ^ ((long) cs1->pc);
}
int
mpiPi_query_pc (void *pc, char **filename, char **functname, int *lineno)
{
int rc = 0;
callsite_pc_cache_entry_t key;
callsite_pc_cache_entry_t *csp;
char addr_buf[24];
key.pc = pc;
/* do we have a cache entry for this pc? If so, use entry */
if (h_search (callsite_pc_cache, &key, (void **) &csp) == NULL)
{
/* no cache entry: create, lookup, and insert */
csp =
(callsite_pc_cache_entry_t *)
malloc (sizeof (callsite_pc_cache_entry_t));
csp->pc = pc;
#if defined(ENABLE_BFD) || defined(USE_LIBDWARF)
if (mpiP_find_src_loc (pc, filename, lineno, functname) == 0)
{
if (*filename == NULL || strcmp (*filename, "??") == 0)
*filename = "[unknown]";
if (*functname == NULL)
*functname = "[unknown]";
mpiPi_msg_debug
("Successful Source lookup for [%s]: %s, %d, %s\n",
mpiP_format_address (pc, addr_buf), *filename, *lineno,
*functname);
csp->filename = strdup (*filename);
csp->functname = strdup (*functname);
csp->line = *lineno;
}
else
{
mpiPi_msg_debug ("Unsuccessful Source lookup for [%s]\n",
mpiP_format_address (pc, addr_buf));
csp->filename = strdup ("[unknown]");
csp->functname = strdup ("[unknown]");
csp->line = 0;
}
#else /* ! ENABLE_BFD || USE_LIBDWARF */
csp->filename = strdup ("[unknown]");
csp->functname = strdup ("[unknown]");
csp->line = 0;
#endif
h_insert (callsite_pc_cache, csp);
}
*filename = csp->filename;
*functname = csp->functname;
*lineno = csp->line;
if (*lineno == 0)
rc = 1; /* use this value to indicate a failed lookup */
return rc;
}
h_t *callsite_src_id_cache = NULL;
int callsite_src_id_counter = 1;
static int
callsite_src_id_cache_comparator (const void *p1, const void *p2)
{
int i;
callsite_src_id_cache_entry_t *csp_1 = (callsite_src_id_cache_entry_t *) p1;
callsite_src_id_cache_entry_t *csp_2 = (callsite_src_id_cache_entry_t *) p2;
#define express(f) {if ((csp_1->f) > (csp_2->f)) {return 1;} if ((csp_1->f) < (csp_2->f)) {return -1;}}
if (mpiPi.stackDepth == 0)
{
express (id); /* In cases where the call stack depth is 0, the only unique info may be the id */
return 0;
}
else
{
for (i = 0; i < MPIP_CALLSITE_STACK_DEPTH; i++)
{
if (csp_1->filename[i] != NULL && csp_2->filename[i] != NULL)
{
if (strcmp (csp_1->filename[i], csp_2->filename[i]) > 0)
{
return 1;
}
if (strcmp (csp_1->filename[i], csp_2->filename[i]) < 0)
{
return -1;
}
express (line[i]);
if (strcmp (csp_1->functname[i], csp_2->functname[i]) > 0)
{
return 1;
}
if (strcmp (csp_1->functname[i], csp_2->functname[i]) < 0)
{
return -1;
}
}
express (pc[i]);
}
}
#undef express
return 0;
}
static int
callsite_src_id_cache_hashkey (const void *p1)
{
int i, j;
int res = 0;
callsite_src_id_cache_entry_t *cs1 = (callsite_src_id_cache_entry_t *) p1;
for (i = 0; i < MPIP_CALLSITE_STACK_DEPTH; i++)
{
if (cs1->filename[i] != NULL)
{
for (j = 0; cs1->filename[i][j] != '\0'; j++)
{
res ^= (unsigned) cs1->filename[i][j];
}
for (j = 0; cs1->functname[i][j] != '\0'; j++)
{
res ^= (unsigned) cs1->functname[i][j];
}
}
res ^= cs1->line[i];
}
return 662917 ^ res;
}
/* take a callstats record (the pc) and determine src file, line, if
possible and assign a callsite id.
*/
int
mpiPi_query_src (callsite_stats_t * p)
{
int i;
callsite_src_id_cache_entry_t key;
callsite_src_id_cache_entry_t *csp;
assert (p);
/* Because multiple pcs can map to the same source line, we must
check that mapping here. If we got unknown, then we assign
different ids */
bzero (&key, sizeof (callsite_src_id_cache_entry_t));
for (i = 0; (i < MPIP_CALLSITE_STACK_DEPTH) && (p->pc[i] != NULL); i++)
{
if (mpiPi.do_lookup == 1)
mpiPi_query_pc (p->pc[i], &(p->filename[i]), &(p->functname[i]),
&(p->lineno[i]));
else
{
p->filename[i] = strdup ("[unknown]");
p->functname[i] = strdup ("[unknown]");
p->lineno[i] = 0;
}
key.filename[i] = p->filename[i];
key.functname[i] = p->functname[i];
key.line[i] = p->lineno[i];
key.pc[i] = p->pc[i];
}
/* MPI ID is compared when stack depth is 0 */
key.id = p->op - mpiPi_BASE;
/* lookup/generate an ID based on the callstack, not just the callsite pc */
if (h_search (callsite_src_id_cache, &key, (void **) &csp) == NULL)
{
/* create a new entry, and assign an id based on callstack */
csp =
(callsite_src_id_cache_entry_t *)
malloc (sizeof (callsite_src_id_cache_entry_t));
bzero (csp, sizeof (callsite_src_id_cache_entry_t));
for (i = 0; (i < MPIP_CALLSITE_STACK_DEPTH) && (p->pc[i] != NULL); i++)
{
csp->filename[i] = strdup (key.filename[i]);
csp->functname[i] = strdup (key.functname[i]);
csp->line[i] = key.line[i];
csp->pc[i] = p->pc[i];
}
csp->op = p->op;
if (mpiPi.stackDepth == 0)
csp->id = csp->op - mpiPi_BASE;
else
csp->id = callsite_src_id_counter++;
h_insert (callsite_src_id_cache, csp);
}
/* assign ID to this record */
p->csid = csp->id;
return p->csid;
}
static void
mpiPi_merge_individual_callsite_records (callsite_stats_t * a,
callsite_stats_t * b)
{
a->count += b->count;
a->cumulativeTime += b->cumulativeTime;
assert (a->cumulativeTime >= 0);
a->cumulativeTimeSquared += b->cumulativeTimeSquared;
assert (a->cumulativeTimeSquared >= 0);
a->maxDur = max (a->maxDur, b->maxDur);
a->minDur = min (a->minDur, b->minDur);
a->maxDataSent = max (a->maxDataSent, b->maxDataSent);
a->minDataSent = min (a->minDataSent, b->minDataSent);
a->cumulativeDataSent += b->cumulativeDataSent;
a->maxIO = max (a->maxIO, b->maxIO);
a->minIO = min (a->minIO, b->minIO);
a->cumulativeIO += b->cumulativeIO;
a->cumulativeRMA += b->cumulativeRMA;
a->arbitraryMessageCount += b->arbitraryMessageCount;
}
static int
mpiPi_insert_callsite_records (callsite_stats_t * p)
{
callsite_stats_t *csp = NULL;
mpiPi_query_src (p); /* sets the file/line in p */
/* If exists, accumulate, otherwise insert. This is
specifically for optimizations that have multiple PCs for
one src line. We aggregate across rank after this.
The collective_report reporting approach does not aggregate individual
process callsite information at the collector process.
*/
if (mpiPi.collective_report == 0)
{
if (NULL == h_search (mpiPi.global_callsite_stats, p, (void **) &csp))
{
callsite_stats_t *newp = NULL;
newp = (callsite_stats_t *) malloc (sizeof (callsite_stats_t));
memcpy (newp, p, sizeof (callsite_stats_t));
/* insert new record into global */
h_insert (mpiPi.global_callsite_stats, newp);
}
else
mpiPi_merge_individual_callsite_records (csp, p);
}
/* Collect aggregate callsite summary information indpendent of rank. */
if (NULL == h_search (mpiPi.global_callsite_stats_agg, p, (void **) &csp))
{
callsite_stats_t *newp = NULL;
newp = (callsite_stats_t *) malloc (sizeof (callsite_stats_t));
memcpy (newp, p, sizeof (callsite_stats_t));
newp->rank = -1;
if (mpiPi.calcCOV)
{
newp->siteData = (double *) malloc (mpiPi.size * sizeof (double));
newp->siteData[0] = p->cumulativeTime;
newp->siteDataIdx = 1;
}
/* insert new record into global */
h_insert (mpiPi.global_callsite_stats_agg, newp);
}
else
{
mpiPi_merge_individual_callsite_records (csp, p);
if (mpiPi.calcCOV)
{
csp->siteData[csp->siteDataIdx] = p->cumulativeTime;
csp->siteDataIdx += 1;
}
}
/* Do global accumulation while we are iterating through individual callsites */
mpiPi.global_task_mpi_time[p->rank] += p->cumulativeTime;
mpiPi.global_mpi_time += p->cumulativeTime;
assert (mpiPi.global_mpi_time >= 0);
mpiPi.global_mpi_size += p->cumulativeDataSent;
mpiPi.global_mpi_io += p->cumulativeIO;
mpiPi.global_mpi_rma += p->cumulativeRMA;
if (p->cumulativeTime > 0)
mpiPi.global_time_callsite_count++;
if (p->cumulativeDataSent > 0)
{
mpiPi.global_mpi_msize_threshold_count += p->arbitraryMessageCount;
mpiPi.global_mpi_sent_count += p->count;
}
return 1;
}
static int
callsite_sort_by_MPI_op (const void *a, const void *b)
{
callsite_stats_t **a1 = (callsite_stats_t **) a;
callsite_stats_t **b1 = (callsite_stats_t **) b;
/* NOTE: want descending sort, so compares are reveresed */
if ((*a1)->op < (*b1)->op)
{
return 1;
}
if ((*a1)->op > (*b1)->op)
{
return -1;
}
return 0;
}
static int
mpiPi_callsite_stats_op_comparator (const void *p1, const void *p2)
{
callsite_stats_t *csp_1 = (callsite_stats_t *) p1;
callsite_stats_t *csp_2 = (callsite_stats_t *) p2;
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp_1);
MPIP_CALLSITE_STATS_COOKIE_ASSERT (csp_2);
#define express(f) {if ((csp_1->f) > (csp_2->f)) {return 1;} if ((csp_1->f) < (csp_2->f)) {return -1;}}
express (op);
#undef express
return 0;
}
/* Aggregate individual MPI call data by iterating through call sites. */
static int
mpiPi_insert_MPI_records ()
{
callsite_stats_t *csp = NULL;
int i, ac;
callsite_stats_t **av;
callsite_stats_t *p;
if (mpiPi.rank == mpiPi.collectorRank)
{
/* Open hash table for MPI call data. */
mpiPi.global_MPI_stats_agg = h_open (mpiPi.tableSize,
mpiPi_callsite_stats_MPI_id_hashkey,
mpiPi_callsite_stats_op_comparator);
/* Get individual call data. */
h_gather_data (mpiPi.global_callsite_stats_agg, &ac, (void ***) &av);
/* Sort by MPI op. */
qsort (av, ac, sizeof (void *), callsite_sort_by_MPI_op);
/* For each call site, add call site info to hash table entry for MPI op, independent of rank. */
for (i = 0; i < ac; i++)
{
p = av[i];
/* Check if there is already an entry for the MPI op. */
if (NULL ==
h_search (mpiPi.global_MPI_stats_agg, p, (void **) &csp))
{
callsite_stats_t *newp = NULL;
newp = (callsite_stats_t *) malloc (sizeof (callsite_stats_t));
memcpy (newp, p, sizeof (callsite_stats_t));
newp->rank = -1;
newp->csid = p->op - mpiPi_BASE;
/* insert new record into global */
h_insert (mpiPi.global_MPI_stats_agg, newp);
}
else
{
mpiPi_merge_individual_callsite_records (csp, p);
}
}
}
return 1;
}
#ifndef ENABLE_API_ONLY /* { */
static int
mpiPi_mergeResults ()
{
int ac;
callsite_stats_t **av;
int totalCount = 0;
int maxCount = 0;
int retval = 1, sendval;
/* gather local task data */
h_gather_data (mpiPi.task_callsite_stats, &ac, (void ***) &av);
/* determine size of space necessary on collector */
PMPI_Allreduce (&ac, &totalCount, 1, MPI_INT, MPI_SUM, mpiPi.comm);
PMPI_Reduce (&ac, &maxCount, 1, MPI_INT, MPI_MAX, mpiPi.collectorRank,
mpiPi.comm);
if (totalCount < 1)
{
if (mpiPi.rank == mpiPi.collectorRank)
mpiPi_msg_warn
("Collector found no records to merge. Omitting report.\n");
return 0;
}
/* gather global data at collector */
if (mpiPi.rank == mpiPi.collectorRank)
{
int i;
int ndx = 0;
#ifdef ENABLE_BFD
if (mpiPi.appFullName != NULL)
{
if (open_bfd_executable (mpiPi.appFullName) == 0)
mpiPi.do_lookup = 0;
}
#elif defined(USE_LIBDWARF)
if (mpiPi.appFullName != NULL)
{
if (open_dwarf_executable (mpiPi.appFullName) == 0)
mpiPi.do_lookup = 0;
}
#endif
#if defined(ENABLE_BFD) || defined(USE_LIBDWARF)
else
{
mpiPi_msg_warn
("Failed to open executable. The mpiP -x runtime flag may address this issue.\n");
mpiPi.do_lookup = 0;
}
#endif
/* Open call site hash tables. */
mpiPi.global_callsite_stats = h_open (mpiPi.tableSize,
mpiPi_callsite_stats_src_hashkey,
mpiPi_callsite_stats_src_comparator);
mpiPi.global_callsite_stats_agg = h_open (mpiPi.tableSize,
mpiPi_callsite_stats_src_id_hashkey,
mpiPi_callsite_stats_src_id_comparator);
if (callsite_pc_cache == NULL)
{
callsite_pc_cache = h_open (mpiPi.tableSize,
callsite_pc_cache_hashkey,
callsite_pc_cache_comparator);
}
if (callsite_src_id_cache == NULL)
{
callsite_src_id_cache = h_open (mpiPi.tableSize,
callsite_src_id_cache_hashkey,
callsite_src_id_cache_comparator);
}
/* Try to allocate space for max count of callsite info from all tasks */
mpiPi.rawCallsiteData =
(callsite_stats_t *) calloc (maxCount, sizeof (callsite_stats_t));
if (mpiPi.rawCallsiteData == NULL)
{
mpiPi_msg_warn
("Failed to allocate memory to collect callsite info");
retval = 0;
}
/* Clear global_mpi_time and global_mpi_size before accumulation in mpiPi_insert_callsite_records */
mpiPi.global_mpi_time = 0.0;
mpiPi.global_mpi_size = 0.0;
if (retval == 1)
{
/* Insert collector callsite data into global and task-specific hash tables */
for (ndx = 0; ndx < ac; ndx++)
{
mpiPi_insert_callsite_records (av[ndx]);
}
ndx = 0;
for (i = 1; i < mpiPi.size; i++) /* n-1 */
{
MPI_Status status;
int count;
int j;
/* okay in any order */
PMPI_Probe (MPI_ANY_SOURCE, mpiPi.tag, mpiPi.comm, &status);
PMPI_Get_count (&status, MPI_CHAR, &count);
PMPI_Recv (&(mpiPi.rawCallsiteData[ndx]), count, MPI_CHAR,
status.MPI_SOURCE, mpiPi.tag, mpiPi.comm, &status);
count /= sizeof (callsite_stats_t);
for (j = 0; j < count; j++)
{
mpiPi_insert_callsite_records (&(mpiPi.rawCallsiteData[j]));
}
}
free (mpiPi.rawCallsiteData);
}
}
else
{
int ndx;
char *sbuf = (char *) malloc (ac * sizeof (callsite_stats_t));
for (ndx = 0; ndx < ac; ndx++)
{
bcopy (av[ndx],
&(sbuf[ndx * sizeof (callsite_stats_t)]),
sizeof (callsite_stats_t));
}
PMPI_Send (sbuf, ac * sizeof (callsite_stats_t),
MPI_CHAR, mpiPi.collectorRank, mpiPi.tag, mpiPi.comm);
free (sbuf);
}
if (mpiPi.rank == mpiPi.collectorRank && retval == 1)
{
if (mpiPi.collective_report == 0)
mpiPi_msg_debug
("MEMORY : Allocated for global_callsite_stats : %13ld\n",
h_count (mpiPi.global_callsite_stats) * sizeof (callsite_stats_t));
mpiPi_msg_debug
("MEMORY : Allocated for global_callsite_stats_agg : %13ld\n",
h_count (mpiPi.global_callsite_stats_agg) *
sizeof (callsite_stats_t));
}
/* TODO: need to free all these pointers as well. */
free (av);
if (mpiPi.rank == mpiPi.collectorRank)
{
if (mpiPi.do_lookup == 1)
{
#ifdef ENABLE_BFD
/* clean up */
close_bfd_executable ();
#elif defined(USE_LIBDWARF)
close_dwarf_executable ();
#endif
}
}
/* Quadrics MPI does not appear to support MPI_IN_PLACE */
sendval = retval;
PMPI_Allreduce (&sendval, &retval, 1, MPI_INT, MPI_MIN, mpiPi.comm);
return retval;
}
static int
mpiPi_mergeCollectiveStats ()
{
int matrix_size;
int all_call_count;
double *coll_time_results, *coll_time_local;
int i, x, y, z;
if (mpiPi.do_collective_stats_report)
{
all_call_count = mpiPi_DEF_END - mpiPi_BASE + 1;
matrix_size =
all_call_count * mpiPi.coll_comm_histogram.hist_size *
mpiPi.coll_size_histogram.hist_size;
mpiPi_msg_debug ("matrix_size is %d, histogram data is %d\n",
matrix_size, sizeof (mpiPi.coll_time_stats));
coll_time_local = (double *) malloc (matrix_size * sizeof (double));
coll_time_results = (double *) malloc (matrix_size * sizeof (double));
i = 0;
for (x = 0; x < mpiPi_DEF_END - mpiPi_BASE; x++)
for (y = 0; y < 32; y++)
for (z = 0; z < 32; z++)
coll_time_local[i++] = mpiPi.coll_time_stats[x][y][z];
/* Collect Collective statistic data were used */
PMPI_Reduce (coll_time_local, coll_time_results, matrix_size,
MPI_DOUBLE, MPI_SUM, mpiPi.collectorRank, mpiPi.comm);
i = 0;
for (x = 0; x < mpiPi_DEF_END - mpiPi_BASE; x++)
for (y = 0; y < 32; y++)
for (z = 0; z < 32; z++)
mpiPi.coll_time_stats[x][y][z] = coll_time_results[i++];
free (coll_time_local);
free (coll_time_results);
}
return 1;
}
static int
mpiPi_mergept2ptStats ()
{
int matrix_size;
int all_call_count;
double *pt2pt_send_results, *pt2pt_send_local;
int i, x, y, z;
if (mpiPi.do_pt2pt_stats_report)
{
all_call_count = mpiPi_DEF_END - mpiPi_BASE + 1;
matrix_size =
all_call_count * mpiPi.pt2pt_comm_histogram.hist_size *
mpiPi.pt2pt_size_histogram.hist_size;
mpiPi_msg_debug ("matrix_size is %d, histogram data is %d\n",
matrix_size, sizeof (mpiPi.pt2pt_send_stats));
pt2pt_send_local = (double *) malloc (matrix_size * sizeof (double));
pt2pt_send_results = (double *) malloc (matrix_size * sizeof (double));
i = 0;
for (x = 0; x < mpiPi_DEF_END - mpiPi_BASE; x++)
for (y = 0; y < 32; y++)
for (z = 0; z < 32; z++)
pt2pt_send_local[i++] = mpiPi.pt2pt_send_stats[x][y][z];
/* Collect Collective statistic data were used */
PMPI_Reduce (pt2pt_send_local, pt2pt_send_results, matrix_size,
MPI_DOUBLE, MPI_SUM, mpiPi.collectorRank, mpiPi.comm);
i = 0;
for (x = 0; x < mpiPi_DEF_END - mpiPi_BASE; x++)
for (y = 0; y < 32; y++)
for (z = 0; z < 32; z++)
mpiPi.pt2pt_send_stats[x][y][z] = pt2pt_send_results[i++];
free (pt2pt_send_local);
free (pt2pt_send_results);
}
return 1;
}
static void
mpiPi_publishResults (int report_style)
{
FILE *fp = NULL;
static int printCount = 0;
if (mpiPi.collectorRank == mpiPi.rank)
{
/* Generate output filename, and open */
do
{
printCount++;
snprintf (mpiPi.oFilename, 256, "%s/%s.%d.%d.%d.mpiP",
mpiPi.outputDir, mpiPi.appName, mpiPi.size, mpiPi.procID,
printCount);
}
while (access (mpiPi.oFilename, F_OK) == 0);
fp = fopen (mpiPi.oFilename, "w");
if (fp == NULL)
{
mpiPi_msg_warn ("Could not open [%s], writing to stdout\n",
mpiPi.oFilename);
fp = stdout;
}
else
{
mpiPi_msg ("\n");
mpiPi_msg ("Storing mpiP output in [%s].\n", mpiPi.oFilename);
mpiPi_msg ("\n");
}
}
mpiPi_profile_print (fp, report_style);
PMPI_Barrier (mpiPi.comm);
if (fp != stdout && fp != NULL)
{
fclose (fp);
}
}
/*
* mpiPi_collect_basics() - all tasks send their basic info to the
* collectorRank.
*/
static void
mpiPi_collect_basics (int report_style)
{
mpiPi_msg_debug ("Collect Basics\n");
if (mpiPi.rank == mpiPi.collectorRank)
{
/* In the case where multiple reports are generated per run,
only allocate memory for global_task_info once */
if (mpiPi.global_task_app_time == NULL)
{
mpiPi.global_task_app_time =
(double *) calloc (mpiPi.size, sizeof (double));
if (mpiPi.global_task_app_time == NULL)
mpiPi_abort
("Failed to allocate memory for global_task_app_time");
mpiPi_msg_debug
("MEMORY : Allocated for global_task_app_time : %13ld\n",
mpiPi.size * sizeof (double));
}
bzero (mpiPi.global_task_app_time, mpiPi.size * sizeof (double));
if (mpiPi.global_task_mpi_time == NULL)
{
mpiPi.global_task_mpi_time =
(double *) calloc (mpiPi.size, sizeof (double));
if (mpiPi.global_task_mpi_time == NULL)
mpiPi_abort
("Failed to allocate memory for global_task_mpi_time");