Newer
Older
#include "JikanDepths.h"
#include "ToJSON.h"
#include <iostream>
#include <map>
#include <string>
#ifdef INCLUDE_OPEN_MP
#include <omp.h>
#endif
this->EventType["Synchronous events"] = set<string>();
this->EventType["Asynchronous events"] = set<string>();
this->JSONname = OUTPUT_NAME + string(".json");
this->JSONdata = "";
this->Error = "";
};
#ifdef INCLUDE_MPI
bool Jikan::ifWriteProc(MPI_Comm comm, int id)
{
bool if_write = false;
int init_flag, fin_flag, iproc;
MPI_Initialized(&init_flag);
MPI_Finalized(&fin_flag);
bool if_MPI = (init_flag) && (!fin_flag);
if(if_MPI)
{
MPI_Comm_rank(comm, &iproc);
if( iproc == id)
if_write = true;
}
else
if_write = true;
return if_write;
}
#endif
bool Jikan::ifWriteProc()
{
return true;
}
this->Events.clear();
map<string, set<string> >::iterator it;
for(it = this->EventType.begin(); it!=this->EventType.end(); ++it)
it->second.clear();
}
bool Jikan::ifContains(const string& Name)
{
map<string, EventData>::iterator it;
it = this->Events.find(Name);
if (it == this->Events.end())
return false;
return true;
}
void Jikan::JikanStart(const string& name, const int& mode)
(this->Events)[name] = EventData(name);
(this->Events)[name].GetModeVals(mode);
ifMPI = (this->Events)[name].mode[0], ifOpenMP = (this->Events)[name].mode[1];
if(!ExistFlag)
{
string EventTypeName;
if(mode == TimerMode::NO_SYNC)
EventTypeName = "Asynchronous events";
else
EventTypeName = "Synchronous events";
this->EventType[EventTypeName].insert(name);
}
//--------------------------- MPI synchronization ---------------------------------------
if(ifMPI)
this->BarrierMPI();
//---------------------------------------------------------------------------------------
//--------------------------- OpenMP synchronization --------------------------------
if(ifOpenMP)
//-----------------------------------------------------------------------------------
ExistFlag = this->ifContains(name);
ifStart = (this->Events)[name].ifStart;
if((!ExistFlag) || (!ifStart))
return;
ifMPI = (this->Events)[name].mode[0], ifOpenMP = (this->Events)[name].mode[1], ifCUDA = (this->Events)[name].mode[2];
if((ifCUDA) && (!ifMPI) && (!ifOpenMP))
{
#ifdef INCLUDE_GPU_TIMER
//--------------------------- OpenMP synchronization --------------------------------
if(ifOpenMP)
{
}
//-----------------------------------------------------------------------------------
//--------------------------- MPI synchronization ---------------------------------------
//---------------------------------------------------------------------------------------
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
}
void Jikan::GenerateTypedOutputData(const string& EventType, string& EventTypeString)
{
const int n = this->EventType[EventType].size();
EventTypeString = JSON::StartTypedBlock(EventType);
if(n == 0)
{
EventTypeString += "\n\t}";
return;
}
string Row;
string Name;
set<string>::iterator it;
set<string>::iterator end_m = this->EventType[EventType].end();
--end_m;
for (it = this->EventType[EventType].begin(); it != end_m; ++it)
{
Name = *it;
JSON::GenerateRow(this->Events[Name], Row, JSON::SeparateRows);
EventTypeString += Row;
}
Name = *end_m;
JSON::GenerateRow(this->Events[Name], Row, JSON::FinishRows);
EventTypeString += Row;
}
void Jikan::GenerateOutputData()
{
map<string, set<string> >::iterator it;
map<string, set<string> >::iterator end_m = this->EventType.end();
--end_m;
string Name;
string Out = "{ ";
string TypedOutput;
for(it = this->EventType.begin(); it!=end_m; ++it)
{
Name = it->first;
TypedOutput = "";
this->GenerateTypedOutputData(Name, TypedOutput);
Out += TypedOutput + ",\n";
}
Name = end_m->first;
TypedOutput = "";
this->GenerateTypedOutputData(Name, TypedOutput);
Out += TypedOutput + "\n}";
this->JSONdata = Out;
bool OutputRes = JSON::WriteOutput(this->JSONname, this->JSONdata);
if(OutputRes != true)
{
this->Error = JSON::Error;
}
void Jikan::SetDumpFilename(const string& name)
{
this->JSONname = name;
}
{
bool ifMPI = (this->Events)[name].mode[0], ifOpenMP = (this->Events)[name].mode[1], ifCUDA = (this->Events)[name].mode[2];
if((ifCUDA))
{
#ifdef INCLUDE_GPU_TIMER
#endif
}
#ifdef INCLUDE_OPEN_MP
else if( (!ifMPI) && (ifOpenMP) )
(this->Events)[name].double_start = omp_get_wtime();
else
(this->Events)[name].start = chrono::steady_clock::now();
bool ifMPI = (this->Events)[name].mode[0], ifOpenMP = (this->Events)[name].mode[1], ifCUDA = (this->Events)[name].mode[2];
if((ifCUDA))
{
#ifdef INCLUDE_GPU_TIMER
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
#endif
}
#ifdef INCLUDE_OPEN_MP
else if( (!ifMPI) && (ifOpenMP))
{
double end = omp_get_wtime();
double main_elapsed = end - (this->Events)[name].double_start;
(this->Events)[name].elapsed_time += main_elapsed;
(this->Events)[name].count ++;
#ifdef SAVE_TIME_SERIES
(this->Events)[name].time_series.push_back(main_elapsed);
#endif
}
#endif
else
{
chrono_time_type end = chrono::steady_clock::now();
chrono_time_type start = (this->Events)[name].start;
double main_elapsed = chrono::duration_cast<chrono::nanoseconds>(end - start).count() * 1e-9;
(this->Events)[name].elapsed_time += main_elapsed;
(this->Events)[name].count ++;
#ifdef SAVE_TIME_SERIES
(this->Events)[name].time_series.push_back(main_elapsed);
#endif
}
}
void Jikan::BarrierMPI()
{
#ifdef INCLUDE_MPI
int init_flag, fin_flag;
MPI_Initialized(&init_flag);
MPI_Finalized(&fin_flag);
if((!fin_flag) && init_flag)
MPI_Barrier(MPI_COMM_WORLD);
#endif
}
class Jikan Timer;