-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_trace.cpp
1442 lines (1254 loc) · 49.9 KB
/
process_trace.cpp
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
/*
* Copyright (c) 2009 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
*
* Author(s): Torsten Hoefler <[email protected]>
* Timo Schneider <[email protected]>
*
*/
#include "trace_reader.hpp"
#include <assert.h>
#include <map>
#include <math.h>
#include <stdexcept>
int MAKE_TAG(int comm, int tag) {
if (comm > 256)
fprintf(stderr, "comm too big\n");
if (tag > (1 << 23))
fprintf(stderr, "tag too big\n");
comm = comm << 24;
tag = comm | tag;
return tag;
}
// TODO: dangerous
static const int req_size = 8;
static const int mpi_any_source = -1;
static const int collsbase = 1000000;
static const int MAX_STRLEN = 4096;
// print debug (overridden by cmdline argument)
static int print = 0;
// arrays of MPI functions to match, may not contain '\0' or ':' in function
// name!
static const char *mpifuncs[] = {
"MPI_Allreduce", "MPI_Iallreduce", "MPI_Alltoall", "MPI_Bcast",
"MPI_Barrier", "MPI_Init", "MPI_Finalize", "MPI_Alltoallv",
"MPI_Scatter", "MPI_Scatterv", "MPI_Gather", "MPI_Gatherv",
"MPI_Allgather", "MPI_Allgatherv", "MPI_Reduce", "MPI_Irecv",
"MPI_Send", "MPI_Recv", "MPI_Comm_rank", "MPI_Comm_size",
"MPI_Isend", "MPI_Wait", "MPI_Waitall", "MPI_Iprobe",
"MPI_Testall", "MPI_Test", "MPI_Scan", "MPI_Exscan",
"MPI_Get_count", "MPI_Sendrecv", "MPI_Rsend", /* end marker */ "\0"};
class htorMatcher;
class htorMatch;
class htorParser {
private:
char *line;
char *elements;
public:
int hashlength;
std::map<int, int> hash2pos;
int hashFunc(char *string, int chars) {
int hash = 0;
// hash function name up to minchars
for (int pos = 0; pos < chars; ++pos) {
// chars was too long - ran over end of string!
if (string[pos] == '\0')
break;
if (string[pos] == ':')
break;
hash += (pos + 1) * (string[pos] >> 1);
}
return hash;
}
htorParser() {
/* simple hash function - sum (char at pos i * i)
* check if it is collision-free */
/* find maximum lengh string in mpifuncs */
int maxlen = 0;
for (int func = 0; mpifuncs[func][0] != '\0';
func++) { // iterate over all function names
if ((int)strlen(mpifuncs[func]) > maxlen)
maxlen = strlen(mpifuncs[func]);
}
int minchars;
for (minchars = 1; minchars <= maxlen;
minchars++) { // minimal needed number of chars to distinguish all
// functions!
bool found = false;
hash2pos.clear();
for (int func = 0; mpifuncs[func][0] != '\0';
func++) { // iterate over all function names
int hash = hashFunc((char *)mpifuncs[func], minchars);
// if(hash == -1) break;
// std::cout << mpifuncs[func] << " hash (" << minchars << "): " << hash
// << "\n";
// see if we already had this hash
std::map<int, int>::iterator iter = hash2pos.find(hash);
if (iter != hash2pos.end()) {
found = true;
break;
}
hash2pos[hash] = func;
}
// check if all values in "hashes" are unique
// I know, this is O(n^2), but the input is constant!
if (found == false)
break;
}
if (minchars <= maxlen) {
if (print)
std::cout << "initialized hash-searcher to " << minchars << "\n";
hashlength = minchars;
} else {
std::cerr << "failed to initialized hash-searcher (" << minchars
<< ") - change hash algorithm or check mpifuncs for doubles!\n";
throw(130);
}
}
// matches a string and returns the number of elements that has been found
bool match(const class htorMatcher *matcher, int hash, char *line,
class htorMatch *match);
bool match(const class htorMatcher *matcher, char *line, class htorMatch *m) {
// get hast for line
int hash = hashFunc(line, hashlength);
return match(matcher, hash, line, m);
}
};
/* this is to statically precompute all hashes! */
class htorMatcher {
public:
int myhash;
int len;
htorMatcher(class htorParser *parser, const char *str) {
len = strlen(str);
// assert(len >= parser->hashlength);
myhash = parser->hashFunc((char *)str, parser->hashlength);
assert(myhash != -1);
std::map<int, int>::iterator iter = parser->hash2pos.find(myhash);
if (iter == parser->hash2pos.end()) {
std::cerr << "func with hash '" << myhash
<< "' not found! Check mpifuncs array!\n";
throw(130);
}
}
};
class htorMatch {
public:
std::vector<int> offsets;
char *line;
char saved;
// this is evil! This changes the next delimiter symbol to '\0' if
// init == 1 and changes it back to the saved value if init == 0
void prepOffsets(int pos, int init) {
if (init == 1) {
saved = offsets[pos + 1];
line[offsets[pos + 1]] = '\0';
} else {
line[offsets[pos + 1]] = saved;
}
}
void get(int pos, int *y) {
pos--; // compatibility to boost::regexp
prepOffsets(pos, 1);
sscanf(&line[offsets[pos]] + 1, "%i", y);
prepOffsets(pos, 0);
// printf("%i\n", *y);
}
void get(int pos, unsigned long *y) {
pos--; // compatibility to boost::regexp
prepOffsets(pos, 1);
sscanf(&line[offsets[pos]] + 1, "%lu", y);
prepOffsets(pos, 0);
// printf("%i\n", *y);
}
void get(int pos, double *y) {
pos--; // compatibility to boost::regexp
prepOffsets(pos, 1);
sscanf(&line[offsets[pos]] + 1, "%lf", y);
prepOffsets(pos, 0);
// printf("%f\n", *y);
}
};
bool htorParser::match(const class htorMatcher *matcher, int hash, char *line,
class htorMatch *match) {
// std::cout << hash << " " << line << "\n";
if (hash == matcher->myhash) {
if (strncmp("MPI_", line, 4) != 0) {
fprintf(stderr,
"line [%s] does not start with MPI_, this might lead to errors\n",
line);
exit(-1);
}
// std::cout << "matched: ";
// std::cout << line << "\n";
match->offsets.clear();
match->line = line;
// start at later pos
int pos = 0;
while (line[pos] != '\0') {
if (line[pos] == ':') {
// std::cout << "found : at: " << pos << "\n";
match->offsets.push_back(pos);
}
if (line[pos] == ',') {
// std::cout << "found , at: " << pos << "\n";
match->offsets.push_back(pos);
}
pos++;
// std::cout << ">" << line[pos] << "<\n";
}
match->offsets.push_back(pos);
return true;
}
return false;
}
void LocOp::NextOp(double time, double end) {
time -= this->start;
if (time < 0) {
std::cout << "negative operation time (time=" << time
<< " this->start=" << this->start << " end=" << end << ")"
<< std::endl;
}
if (print)
printf(" loclop: %llu\n", (unsigned long long)(round(time * time_mult)));
int op = this->goal->Exec(
"comp", (unsigned long long)(round(time * time_mult)), this->cpu);
// operations that depend on me
std::vector<std::pair<Goal::t_id, t_type>>::iterator it;
for (it = this->next.begin(); it != this->next.end(); it++) {
if (it->first != Goal::NO_ID) {
if (it->second == REQU)
this->goal->Requires(it->first, op);
else
this->goal->Irequires(it->first, op);
}
}
// operations that I depend on
for (it = this->prev.begin(); it != this->prev.end(); it++) {
if (it->first != Goal::NO_ID) {
if (it->second == REQU)
this->goal->Requires(op, it->first);
else
this->goal->Irequires(op, it->first);
}
}
this->prev.clear();
this->next.clear();
// start new locop
// this->start=this->start+time;
this->start = end;
}
// get \ceil log_base(i) \ceil with integer arithmetic
int logi(int base, int x) {
int log = 0;
int y = 1;
while (y <= x) {
log++;
y *= base;
}
return log;
}
// pretty print numbers in buffer (add 0's to fill up to max)
int pprint(char *buf, int len, int x, int max) {
int log10x = logi(10, x);
if (x == 0)
log10x = 1; // log_x(0) is undefined but has a single digit ;)
int log10max = logi(10, max);
int i;
for (i = 0; i < log10max - log10x; ++i) {
*buf = '0';
buf++;
len--;
}
snprintf(buf, len, "%i", x);
return log10max - log10x;
}
void change_zero_to_host(char *mask, char *buffer, int host) {
char *substr = strstr(mask, "-0");
if (substr == NULL) {
std::cerr << "tracefile-name did not contain '-0' - exiting\n";
throw(130);
}
substr = strstr(substr + 1, "-0");
if (substr != NULL) {
std::cerr << "tracefile-name did contain more than one '-0' - exiting\n";
throw(130);
}
char str_start[MAX_STRLEN];
char str_end[MAX_STRLEN];
// extract everything before the 0
strcpy(str_start, mask);
substr = strstr(str_start, "-0");
substr++; // go over '-'
*substr = '\0';
// extract everything after the 0
strcpy(str_end, mask);
substr = strstr(str_end, "-0");
substr++; // go over '-'
while (*substr == '0')
substr++;
strcpy(str_end, substr);
sprintf(buffer, "%s%i%s", str_start, host, str_end);
}
static inline Goal::t_id
finish_coll(std::string collname /* the op id */,
std::pair<Goal::locop, Goal::locop> ops /* dependent operations */,
double tstart, double tend, int nbcify, LocOp *curlocop,
Goal *goal) {
Goal::locop::iterator it;
Goal::t_id collop = goal->Exec(collname.c_str(), 0);
// an operation represents the time *before* the current collective
// it is initialized with curlocop->time with the finishing time of
// the last one (or 0 respectively)
// the collop depends on all last guys from the collective
// this operation represents the whole collective!
for (it = ops.second.begin(); it != ops.second.end(); it++) {
goal->Requires(collop, it->first);
}
// the independent ops in the collective must all depend on the
// current localop (we could also introduce a virtual dependency here)
for (it = ops.first.begin(); it != ops.first.end(); it++) {
curlocop->next.push_back(*it);
}
// shorten the last localop
double virtstart = tstart - nbcify;
if (virtstart - curlocop->start < 0) {
virtstart = curlocop->start;
if (print)
std::cout << "nbcify shortened from " << nbcify << " to "
<< tstart - virtstart << "\n";
nbcify = tstart - virtstart;
}
// create new NBC localop
Goal::t_id nbcop = Goal::NO_ID;
if (nbcify) {
nbcop = goal->Exec("nbcify", nbcify, curlocop->cpu);
goal->Irequires(nbcop, collop);
}
// finish last localop
curlocop->NextOp(virtstart, tend);
// this is for the next localop! (which can only happen after the
// current collective ends
curlocop->prev = make_vector(std::make_pair(collop, LocOp::REQU));
return collop;
}
void process_trace(gengetopt_args_info *args_info) {
if (!args_info->traces_given) {
std::cout << "please give me tracefiles ;)" << std::endl;
return;
}
// iterate over all possible hosts
int host = -1;
print = args_info->traces_print_arg;
std::cout << "using file mask: " << args_info->traces_arg << std::endl;
std::string fptrn(args_info->traces_arg);
/* get the number of files (hosts) - same as below - this just counts the
* commsize */
while (1) {
char buffer[MAX_STRLEN];
change_zero_to_host(args_info->traces_arg, buffer, ++host);
assert(strlen(buffer) < MAX_STRLEN);
std::ifstream trace(buffer, std::ios::in);
if (!trace.is_open())
break;
}
int hosts = host;
int nbcify = args_info->traces_nbcify_arg;
int extrhosts = args_info->traces_extr_arg;
std::cout << "found " << hosts << " hosts, extrapolating to "
<< extrhosts * hosts << std::endl;
std::cout << "timebase: " << args_info->timemult_arg << "; using CPU "
<< args_info->cpu_arg << " for computation\n";
if (nbcify)
std::cout << "nbcify propost: " << nbcify << "\n";
Goal goal(args_info, hosts * extrhosts);
/* see if we have a file with start lines for the trace files - one
* line-index per line and >hosts< lines */
std::vector<int> istartpos, startpos;
std::vector<double> istarttimes, starttimes;
if (args_info->traces_start_given) {
std::ifstream startfile(args_info->traces_start_arg, std::ios::in);
if (!startfile.is_open()) {
std::cout << "couldn't open file with start-times - starting with zero"
<< std::endl;
for (int i = 0; i < hosts; i++) {
startpos.push_back(0);
starttimes.push_back(0);
}
} else {
for (int i = 0; i < hosts; i++) {
char buffer[MAX_STRLEN];
// class conv_line conv;
startfile.getline(buffer, MAX_STRLEN);
// boost::cmatch m;
// static const boost::regex e_nr("^([\\d]+) (.+)$");
// if(regex_match(buffer, m, e_nr)) {
int line; // conv.read_string(m,1,&line);
double starttime; // conv.read_string(m,2,&starttime);
sscanf(buffer, "%i %lf", &line, &starttime);
startpos.push_back(line);
starttimes.push_back(starttime);
//}
}
// nope, no better error ...
if ((int)starttimes.size() < hosts) {
std::cout << "input file format wrong - exiting" << std::endl;
return;
}
}
// std::cout << " hosts " << hosts << " " << starttimes.size() << "\n";
assert(hosts == (int)starttimes.size());
assert(hosts == (int)startpos.size());
}
istartpos = startpos;
istarttimes = starttimes;
// loop over extrapolation parameter
for (int extrhost = 0; extrhost < extrhosts; ++extrhost) {
std::cout << "extrapolation round " << extrhost << "\n";
// restore environment as at the beginning
host = -1;
startpos = istartpos;
starttimes = istarttimes;
while (1) {
char buffer[MAX_STRLEN];
change_zero_to_host(args_info->traces_arg, buffer, ++host);
assert(strlen(buffer) < MAX_STRLEN);
TraceReader trcrd(buffer);
if (!trcrd.is_open())
break;
if (print)
std::cout << "# parsing: " << buffer << std::endl;
double tracestart; // MPI start time of the trace
LocOp curlocop(&goal, args_info->timemult_arg, args_info->cpu_arg);
// the map of all open LocOp::REQUests - a request in a trace is
// identified by an integer - this map saves the identifier of the
// nonblocking operation associated with the LocOp::REQU. in order to make
// it dependent to the item after the wait{all,some,any} - D'oh, what do
// we do with wait{any,some}???
std::map<unsigned long, Goal::t_id> reqs;
goal.StartRank(host + hosts * extrhost);
// boost::cmatch m;
int found_eof = 0; // flag to indicate when to stop
int nops = 0;
int lineno = 0;
char line[MAX_STRLEN];
htorParser pars;
htorMatch match;
while (!found_eof) {
// read next line
found_eof = trcrd.getline(line, MAX_STRLEN);
lineno++;
// fast forward to line number from startpos if provided
if ((int)startpos.size() > 0 && lineno == 1) {
trcrd.seekg(startpos[host]);
curlocop.start = starttimes[host];
if (print)
std::cout << "rank " << host << " starting at line " << lineno
<< " with time " << std::setprecision(30)
<< curlocop.start << "\n";
}
/**** start */
if (strstr(line, "# Init clockdiff: ") != NULL) {
sscanf(line, "# Init clockdiff: %lf", &tracestart);
// std::cout << "start: " << tracestart << " at line " << lineno <<
// "\n";
}
// this is just done to speed things up - hash MPI function name
// once at the beginning and only search function with hash :)
int funchash = pars.hashFunc(line, pars.hashlength);
/**** Init */
static const htorMatcher e_init(&pars, "MPI_Init");
if (pars.match(&e_init, funchash, line, &match)) {
double inittime;
match.get(4, &inittime);
tracestart = inittime;
if (print)
std::cout << "starttime host " << host << " = " << tracestart
<< std::endl;
assert(curlocop.start == 0);
curlocop.start = tracestart;
curlocop.prev = make_vector(std::make_pair(Goal::NO_ID, LocOp::REQU));
goto endloop;
}
static const htorMatcher e_rank(&pars, "MPI_Comm_rank");
static const htorMatcher e_size(&pars, "MPI_Comm_size");
static const htorMatcher e_getcount(&pars, "MPI_Get_count");
static const htorMatcher e_probe(&pars, "MPI_Iprobe");
static const htorMatcher e_testall(&pars, "MPI_Testall");
static const htorMatcher e_test(&pars, "MPI_Test");
if (pars.match(&e_rank, funchash, line, &match) ||
pars.match(&e_probe, funchash, line, &match) ||
pars.match(&e_testall, funchash, line, &match) ||
pars.match(&e_test, funchash, line, &match) ||
pars.match(&e_getcount, funchash, line, &match) ||
pars.match(&e_size, funchash, line, &match))
goto endloop;
static const htorMatcher e_irecv(&pars, "MPI_Irecv");
static const htorMatcher e_recv(&pars, "MPI_Recv");
static const htorMatcher e_isend(&pars, "MPI_Isend");
static const htorMatcher e_send(&pars, "MPI_Send");
static const htorMatcher e_rsend(&pars, "MPI_Rsend");
static const htorMatcher e_sendrecv(&pars, "MPI_Sendrecv");
static const htorMatcher e_wait(&pars, "MPI_Wait");
static const htorMatcher e_waitall(&pars, "MPI_Waitall");
if (args_info->traces_nop2p_given) {
if (pars.match(&e_irecv, funchash, line, &match) ||
pars.match(&e_isend, funchash, line, &match) ||
pars.match(&e_recv, funchash, line, &match) ||
pars.match(&e_send, funchash, line, &match) ||
pars.match(&e_rsend, funchash, line, &match) ||
pars.match(&e_sendrecv, funchash, line, &match) ||
pars.match(&e_wait, funchash, line, &match) ||
pars.match(&e_waitall, funchash, line, &match))
goto endloop;
} else {
// MPI_Recv( void *buf, int count, MPI_Datatype datatype, int source,
// int tag, MPI_Comm comm, MPI_Status *status)
// MPI_Recv : 1237666053021692.000000 : 11287888 : 4500 : 11,8,8 : 2 :
// 24000 : 0,0,4 : 140737488340112 : 1237666053022005.000000
if (pars.match(&e_recv, funchash, line, &match)) {
double tstart;
match.get(1, &tstart);
int size;
match.get(5, &size);
int count;
match.get(3, &count);
int tag;
match.get(8, &tag);
int dest;
match.get(7, &dest);
int comm;
match.get(9, &comm);
double tend;
match.get(13, &tend);
if (print)
std::cout << " recv from " << dest << " time: " << tend - tstart
<< " size: " << size * count << " tag: " << tag
<< std::endl;
if (print)
goal.Comment("Recv begin");
goal.SetTag(MAKE_TAG(comm, tag));
if (dest != -1 /* MPI_ANY_SOURCE */)
dest += hosts * extrhost;
Goal::t_id id = goal.Recv(size * count, dest);
if (print)
goal.Comment("Recv end");
curlocop.next = make_vector(std::make_pair(id, LocOp::REQU));
curlocop.NextOp(tstart, tend);
curlocop.prev = make_vector(std::make_pair(id, LocOp::REQU));
// nops++; only count colls here
goto endloop;
}
// MPI_Irecv( void *buf, int count, MPI_Datatype datatype, int source,
// int tag, MPI_Comm comm, MPI_Request *request ) MPI_Irecv :
// 1225038833071959.000000 : 14744192 : 36864 : 13,1,1 : -1 : 76 :
// 5641280,0,4 : 14118576 : 1225038833071964.000000
if (pars.match(&e_irecv, funchash, line, &match)) {
double tstart;
match.get(1, &tstart);
int size;
match.get(5, &size);
int count;
match.get(3, &count);
int tag;
match.get(8, &tag);
int dest;
match.get(7, &dest);
int comm;
match.get(9, &comm);
unsigned long req;
match.get(12, &req);
double tend;
match.get(13, &tend);
if (print)
std::cout << " irecv from " << dest << " time: " << tend - tstart
<< " size: " << size * count << " tag: " << tag
<< " req " << req << std::endl;
if (print)
goal.Comment("Irecv begin");
goal.SetTag(MAKE_TAG(comm, tag));
if (dest != -1 /* MPI_ANY_SOURCE */)
dest += hosts * extrhost;
Goal::t_id id = goal.Recv(size * count, dest);
reqs[req] = id;
if (print)
goal.Comment("Irecv end");
curlocop.next = make_vector(std::make_pair(id, LocOp::REQU));
curlocop.NextOp(tstart, tend);
curlocop.prev = make_vector(std::make_pair(id, LocOp::IREQU));
// nops++; only count colls here
goto endloop;
}
// MPI_Send( void *buf, int count, MPI_Datatype datatype, int dest,
// int tag, MPI_Comm comm ) MPI_Send : 1237666053149864.000000 :
// 11251872 : 4500 : 11,8,8 : 1 : 7000 : 0,0,4 :
// 1237666053150082.000000
if (pars.match(&e_send, funchash, line, &match)) {
double tstart;
match.get(1, &tstart);
int size;
match.get(5, &size);
int count;
match.get(3, &count);
int tag;
match.get(8, &tag);
int dest;
match.get(7, &dest);
double tend;
match.get(12, &tend);
int comm;
match.get(9, &comm);
if (print)
std::cout << " send to " << dest << " time: " << tend - tstart
<< " size: " << size * count << " tag: " << tag
<< std::endl;
if (print)
goal.Comment("Send begin");
goal.SetTag(MAKE_TAG(comm, tag));
Goal::t_id id = goal.Send(size * count, dest + hosts * extrhost);
if (print)
goal.Comment("Send end");
curlocop.next = make_vector(std::make_pair(id, LocOp::REQU));
curlocop.NextOp(tstart, tend);
curlocop.prev = make_vector(std::make_pair(id, LocOp::REQU));
// nops++; only count colls here
goto endloop;
}
// MPI_Rsend( void *buf, int count, MPI_Datatype datatype, int dest,
// int tag, MPI_Comm comm ) MPI_Rsend : 1237844044868539.000000 :
// 332631168 : 24955 : 10,8,8 : 0 : 0 : 7152208,3,4 :
// 1237844044868842.000000
if (pars.match(&e_rsend, funchash, line, &match)) {
double tstart;
match.get(1, &tstart);
int size;
match.get(5, &size);
int count;
match.get(3, &count);
int tag;
match.get(8, &tag);
int dest;
match.get(7, &dest);
double tend;
match.get(12, &tend);
int comm;
match.get(9, &comm);
if (print)
std::cout << " rsend to " << dest << " time: " << tend - tstart
<< " size: " << size * count << " tag: " << tag
<< std::endl;
if (print)
goal.Comment("Rsend begin");
goal.SetTag(MAKE_TAG(comm, tag));
Goal::t_id id = goal.Send(size * count, dest + hosts * extrhost);
if (print)
goal.Comment("Rsend end");
curlocop.next = make_vector(std::make_pair(id, LocOp::REQU));
curlocop.NextOp(tstart, tend);
curlocop.prev = make_vector(std::make_pair(id, LocOp::REQU));
// nops++; only count colls here
goto endloop;
}
// MPI_Isend( void *buf, int count, MPI_Datatype datatype, int dest,
// int tag, MPI_Comm comm, MPI_Request *request ) MPI_Isend :
// 1225038833277018.000000 : 14781072 : 36864 : 13,1,1 : 1 : 204 :
// 5641280,0,4 : 7104000 : 1225038833277029.000000
if (pars.match(&e_isend, funchash, line, &match)) {
double tstart;
match.get(1, &tstart);
int size;
match.get(5, &size);
int count;
match.get(3, &count);
int tag;
match.get(8, &tag);
int comm;
match.get(9, &comm);
int dest;
match.get(7, &dest);
unsigned long req;
match.get(12, &req);
double tend;
match.get(13, &tend);
if (print)
std::cout << " isend to " << dest << " time: " << tend - tstart
<< " size: " << size * count << " tag: " << tag
<< " req " << req << std::endl;
if (print)
goal.Comment("Isend begin");
goal.SetTag(MAKE_TAG(comm, tag));
Goal::t_id id = goal.Send(size * count, dest + hosts * extrhost);
reqs[req] = id;
if (print)
goal.Comment("Isend end");
curlocop.next = make_vector(std::make_pair(id, LocOp::REQU));
curlocop.NextOp(tstart, tend);
curlocop.prev = make_vector(std::make_pair(id, LocOp::IREQU));
// nops++; only count colls here
goto endloop;
}
/**** Wait */
// MPI_Wait ( MPI_Request *request, MPI_Status *status)
// MPI_Wait : 1225038833273694.000000 : 7104000 : 140734714680384 :
// 1225038833273749.000000
if (pars.match(&e_wait, funchash, line, &match)) {
unsigned long req;
match.get(2, &req);
double tstart;
match.get(1, &tstart);
double tend;
match.get(4, &tend);
// if we cannot find the request, i.e., because its a wait on a
// MPI_REQUEST_NULL, don't do anything
if (reqs.find(req) != reqs.end()) {
// std::cout << line << std::endl;
if (print)
std::cout << " wait "
<< " time " << tend - tstart << " req: " << req
<< std::endl;
if (print)
goal.Comment("wait");
Goal::t_id id = goal.Exec("wait", 0);
try {
Goal::t_id req_id = reqs.at(req);
// curlocop.prev.push_back(std::make_pair(req_id,LocOp::REQU));
goal.Requires(id, req_id);
} catch (std::out_of_range const &) {
// MPI_Wait will just set the handle to MPI_REQUEST_NULL, its
// perfectly legal to call again, actually liballprof does not
// have sufficient info in this case
// std::cerr << "request " << req << " not found -
// there is something wrong with the trace!" <<
// std::endl; return;
}
reqs.erase(req);
curlocop.next = make_vector(std::make_pair(id, LocOp::REQU));
curlocop.NextOp(tstart, tend);
curlocop.prev = make_vector(std::make_pair(id, LocOp::REQU));
}
goto endloop;
}
/**** Waitall */
// MPI_Waitall( int count, MPI_Request array_of_requests[], MPI_Status
// array_of_statuses[] ) MPI_Waitall : 1237759886409182.000000 : 3 :
// 6166720 : 5839040 : 1237759886411243.000000
if (pars.match(&e_waitall, funchash, line, &match)) {
int nreq;
match.get(2, &nreq);
unsigned long req;
match.get(3, &req);
double tstart;
match.get(1, &tstart);
double tend;
match.get(5, &tend);
if (print)
std::cout << " waitall "
<< " time " << tend - tstart << " req: " << req
<< " nreqs: " << nreq << std::endl;
Goal::t_id id = goal.Exec("waitall", 0);
try {
for (unsigned long i = req; i < req + nreq * req_size;
i += req_size) {
if (reqs.find(i) != reqs.end()) {
if (print)
std::cout << " resolving req " << i << std::endl;
Goal::t_id req_id = reqs.at(i);
goal.Requires(id, req_id);
}
}
} catch (std::out_of_range const &) {
// this is bs, doing to MPI_Waits on the same req handle will lead
// to an error in schedgen, but is perfectly legal, since the
// first wait will turn the request into an req_null
std::cerr << "request " << req
<< " not found - there is something wrong with the "
"trace! (try adjusting req_size = "
<< req_size << ")" << std::endl;
return;
}
reqs.erase(req);
curlocop.next = make_vector(std::make_pair(id, LocOp::REQU));
curlocop.NextOp(tstart, tend);
curlocop.prev = make_vector(std::make_pair(id, LocOp::REQU));
goto endloop;
}
// int MPI_Sendrecv( void *sendbuf, int sendcount, MPI_Datatype
// sendtype, int dest, int sendtag, void *recvbuf, int recvcount,
// MPI_Datatype recvtype, int source, int recvtag, MPI_Comm comm,
// MPI_Status *status)
// MPI_Sendrecv : 1237844041868441.000000 : 140735182514476 : 1 :
// 1,4,4 : 2 : 0 : 140735182514472 : 1 : 1,4,4 : 2 : 0 : 7152208,0,4 :
// 140735182514432 : 1237844041868457.000000
if (pars.match(&e_sendrecv, funchash, line, &match)) {
double tstart;
match.get(1, &tstart);
int scount;
match.get(3, &scount);
int ssize;
match.get(5, &ssize);
int stag;
match.get(8, &stag);
int sdest;
match.get(7, &sdest);
int rcount;
match.get(10, &rcount);
int rsize;
match.get(12, &rsize);
int rsource;
match.get(14, &rsource);
int rtag;
match.get(15, &rtag);
int comm;
match.get(16, &comm);
double tend;
match.get(20, &tend);
if (print)
std::cout << " sendrecv - send to " << sdest
<< " size: " << ssize * scount << " tag: " << stag
<< "; recv from " << rsource
<< " size: " << rsize * rcount << " tag: " << rtag
<< "; time: " << tend - tstart << std::endl;
if (print)
goal.Comment("Sendrecv begin");
goal.SetTag(MAKE_TAG(comm, stag));
Goal::t_id sid =
goal.Send(ssize * scount, sdest + hosts * extrhost);
goal.SetTag(MAKE_TAG(comm, stag));
Goal::t_id rid =
goal.Recv(rsize * rcount, rsource + hosts * extrhost);
if (print)
goal.Comment("Sendrecv end");
curlocop.next.push_back(std::make_pair(sid, LocOp::REQU));
curlocop.next.push_back(std::make_pair(rid, LocOp::REQU));
curlocop.NextOp(tstart, tend);
curlocop.prev.push_back(std::make_pair(sid, LocOp::REQU));
curlocop.prev.push_back(std::make_pair(rid, LocOp::REQU));
// nops++; only count colls here
goto endloop;
}
} // p2p communication end
static const htorMatcher e_barr(&pars, "MPI_Barrier");
static const htorMatcher e_allred(&pars, "MPI_Allreduce");
static const htorMatcher e_iallred(&pars, "MPI_Iallreduce");
static const htorMatcher e_bcast(&pars, "MPI_Bcast");
static const htorMatcher e_allgather(&pars, "MPI_Allgather");
static const htorMatcher e_allgatherv(&pars, "MPI_Allgatherv");
static const htorMatcher e_gatherv(&pars, "MPI_Gatherv");
static const htorMatcher e_gather(&pars, "MPI_Gather");
static const htorMatcher e_exscan(&pars, "MPI_Exscan");
static const htorMatcher e_scatterv(&pars, "MPI_Scatterv");
static const htorMatcher e_scatter(&pars, "MPI_Scatter");
static const htorMatcher e_alltoallv(&pars, "MPI_Alltoallv");
static const htorMatcher e_alltoall(&pars, "MPI_Alltoall");
static const htorMatcher e_scan(&pars, "MPI_Scan");
static const htorMatcher e_reduce(&pars, "MPI_Reduce");
if (args_info->traces_nocolls_given) {
/* TODO: this is a hack to enable the AMG run to work correctly --
* this does only increase nops if it would have increased it
* with colls enabled !! */
// if(pars.match(&e_barr, funchash, line, &match) ||
// pars.match(&e_allred, funchash, line, &match) ||
// pars.match(&e_bcast, funchash, line, &match) ||
// pars.match(&e_allgather, funchash, line, &match))
// nops++;
if (pars.match(&e_barr, funchash, line, &match) ||
pars.match(&e_allred, funchash, line, &match) ||
pars.match(&e_bcast, funchash, line, &match) ||
pars.match(&e_allgather, funchash, line, &match) ||
pars.match(&e_allgatherv, funchash, line, &match) ||
pars.match(&e_gatherv, funchash, line, &match) ||
pars.match(&e_gather, funchash, line, &match) ||
pars.match(&e_exscan, funchash, line, &match) ||
pars.match(&e_scatterv, funchash, line, &match) ||
pars.match(&e_scatter, funchash, line, &match) ||
pars.match(&e_alltoallv, funchash, line, &match) ||
pars.match(&e_alltoall, funchash, line, &match) ||
pars.match(&e_scan, funchash, line, &match) ||
pars.match(&e_reduce, funchash, line, &match))
goto endloop;
} else {
/**********************************************************************
* Collective Communication start *
**********************************************************************/
/**** Barrier */
// MPI_Barrier:1225632903083161.000000:3,0,32:1225632903083192.000000
// MPI_Barrier(comm);