forked from abduld/libwb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wbExit.cpp
119 lines (98 loc) · 2.99 KB
/
wbExit.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
#include "wb.h"
enum {
wbMPI_timerTag = 2,
wbMPI_loggerTag = 4,
wbMPI_solutionExistsTag = 8,
wbMPI_solutionTag = 16
};
void wb_atExit(void) {
using std::cout;
using std::endl;
#ifdef WB_USE_CUDA
// cudaDeviceSynchronize();
#endif /* WB_USE_CUDA */
int nranks = rankCount();
if (nranks > 1) {
#ifdef WB_USE_MPI
if (isMasterQ) {
#ifdef wbLogger_printOnExit
cout << "==$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
cout << "{\n";
cout << wbString_quote("timer") << ":";
cout << "[\n";
for (int ii = 0; ii < nranks; ii++) {
if (ii == 0) {
cout << wbTimer_toJSON();
} else {
const char *msg = wbMPI_getStringFromRank(ii, wbMPI_timerTag);
if (msg != nullptr && strlen(msg) != 0) {
cout << ",\n";
cout << msg;
// free(msg);
}
}
}
cout << "]" << endl; // close timer
cout << "," << endl; // start logger
cout << wbString_quote("logger") << ":";
cout << "[\n";
for (int ii = 0; ii < nranks; ii++) {
if (ii == 0) {
cout << wbLogger_toJSON();
} else {
const char *msg = wbMPI_getStringFromRank(ii, wbMPI_loggerTag);
if (msg != nullptr && strlen(msg) != 0) {
cout << ",\n";
cout << msg;
// free(msg);
}
}
}
cout << "]" << endl; // close logger
cout << "," << endl; // start solutionExists
cout << wbString_quote("cuda_memory") << ":" << _cudaMallocSize
<< ",\n";
if (solutionJSON) {
cout << wbString_quote("solution_exists") << ": true,\n";
cout << wbString_quote("solution") << ":" << solutionJSON << "\n";
} else {
cout << wbString_quote("solution_exists") << ": false\n";
}
cout << "}" << endl; // close json
} else {
wbMPI_sendStringToMaster(wbTimer_toJSON().c_str(), wbMPI_timerTag);
wbMPI_sendStringToMaster(wbLogger_toJSON().c_str(), wbMPI_loggerTag);
}
#endif /* wbLogger_printOnExit */
#endif /* WB_USE_MPI */
} else {
#ifdef wbLogger_printOnExit
cout << "==$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
cout << "{\n" << wbString_quote("timer") << ":[" << wbTimer_toJSON()
<< "],\n" << wbString_quote("logger") << ":[" << wbLogger_toJSON()
<< "],\n";
#ifdef WB_USE_CUDA
cout << wbString_quote("cuda_memory") << ":" << _cudaMallocSize
<< ",\n";
#endif /* WB_USE_CUDA */
if (solutionJSON) {
cout << wbString_quote("solution_exists") << ": true,\n";
cout << wbString_quote("solution") << ":" << solutionJSON << "\n";
} else {
cout << wbString_quote("solution_exists") << ": false\n";
}
cout << "}" << endl;
#endif /* wbLogger_printOnExit */
}
// wbTimer_delete(_timer);
// wbLogger_delete(_logger);
_timer = nullptr;
_logger = nullptr;
// wbFile_atExit();
#ifdef WB_USE_CUDA
cudaDeviceReset();
#endif
exit(0);
// assert(0);
return;
}