@@ -133,16 +133,6 @@ Reporter::Reporter(std::string fileName, std::string outputFormat) : _outputForm
133133 if (isMainThread ()) {
134134 _out = std::ofstream (fileName, std::ios_base::out);
135135 _outputValid = true ;
136- if (_outputFormat == " csv" ) {
137- _out << " numCycle, " ;
138- _out << " collective, " ;
139- #ifdef MPI_SUPPORT
140- _out << " ranks, rankspernode, gpusperrank, " ;
141- #else
142- _out << " gpus, " ;
143- #endif
144- _out << " size, type, redop, inplace, time, algbw, busbw, #wrong\n " ;
145- }
146136 }
147137 }
148138}
@@ -184,27 +174,54 @@ void Reporter::addResult(int gpusPerRank, int ranksPerNode, int totalRanks, size
184174 outputValuesKeys.push_back (makeValueKeyPair (busBw, " busBw" ));
185175 outputValuesKeys.push_back (makeValueKeyPair (wrongEltsStr, " wrong" ));
186176
187- for (auto iter = outputValuesKeys.begin (); iter != outputValuesKeys.end (); ++iter) {
188- if (_outputFormat == " csv" ) {
189- _out << iter->first ;
190- if (std::next (iter) != outputValuesKeys.end ()) {
191- _out << " , " ;
177+ _outputData.push_back (outputValuesKeys);
178+ }
179+
180+ void Reporter::writeFile () {
181+ if (!isMainThread () || !_outputValid)
182+ return ;
183+
184+ if (_outputFormat == " csv" ) {
185+ _out << " numCycle," ;
186+ _out << " collective," ;
187+ #ifdef MPI_SUPPORT
188+ _out << " ranks,rankspernode,gpusperrank," ;
189+ #else
190+ _out << " gpus," ;
191+ #endif
192+ _out << " size,type,redop,inplace,time,algbw,busbw,#wrong\n " ;
193+ for (auto iterEntries = _outputData.begin (); iterEntries != _outputData.end (); ++iterEntries) {
194+ for (auto iterVals = (*iterEntries).begin (); iterVals != (*iterEntries).end (); ++iterVals) {
195+ _out << iterVals->first ;
196+ if (std::next (iterVals) != (*iterEntries).end ()) {
197+ _out << " ," ;
198+ }
192199 }
193- } else { // json
194- if (iter == outputValuesKeys.begin ()) {
195- _out << " {" ;
200+ _out << std::endl;
201+ }
202+ } else { // json
203+ _out << " [" << std::endl;
204+ for (auto iterEntries = _outputData.begin (); iterEntries != _outputData.end (); ++iterEntries) {
205+ for (auto iterVals = (*iterEntries).begin (); iterVals != (*iterEntries).end (); ++iterVals) {
206+ if (iterVals == (*iterEntries).begin ()) {
207+ _out << " {" ;
208+ }
209+ _out << " \" " << iterVals->second << " \" :" << iterVals->first ;
210+ if (std::next (iterVals) != (*iterEntries).end ()) {
211+ _out << " , " ;
212+ }
196213 }
197- _out << " \" " << iter->second << " \" :" << iter->first ;
198- if (std::next (iter) != outputValuesKeys.end ()) {
199- _out << " , " ;
214+ if (std::next (iterEntries) != _outputData.end ()) {
215+ _out << " }," << std::endl;
200216 } else {
201- _out << " }" ;
217+ _out << " }" << std::endl ;
202218 }
203219 }
220+ _out << " ]" << std::endl;
204221 }
205- _out << std::endl;
206222}
207223
224+
208225bool Reporter::isMainThread () { return is_main_thread == 1 ; }
209226
210227#define NUM_BLOCKS 32
@@ -1711,6 +1728,8 @@ testResult_t run() {
17111728 MPI_Finalize ();
17121729#endif
17131730
1731+ reporter.writeFile ();
1732+
17141733 // 'cuda-memcheck --leak-check full' requires this
17151734 PRINT (" %s\n " , ncclGetLastError (NULL ));
17161735 cudaDeviceReset ();
0 commit comments