Skip to content
Snippets Groups Projects
Event.cpp 3.33 KiB
Newer Older
  • Learn to ignore specific revisions
  • #include <iostream>
    
    #ifdef INCLUDE_OPEN_MP
        #include <omp.h>
    #endif
    
    
    数学の武士's avatar
    数学の武士 committed
    #include "Event.h"
    
    #include "Jikan.h"
    
    数学の武士's avatar
    数学の武士 committed
    
    using namespace std;
    
    
    EventData::EventData()
    {
        this->double_start = 0.0;
        this->start = chrono::steady_clock::now();
        this->elapsed_time = 0.0; 
        this->count = 0;
        this->ifCUDA = 0;
        this->event_name = "Unnamed";
        this->ifStart = false, this->ifEnd = false;
        this->if_mode_set = false;
    
        this->time_series = vector<double>();
        this->mode = vector<bool>();
        
        #ifdef INCLUDE_GPU_TIMER
            this->InitEventsCUDA();
        #else
            this->ifCUDAinit = false;
        #endif
    }
    
    数学の武士's avatar
    数学の武士 committed
    
    EventData::~EventData()
    {
    
        #pragma omp master
        {
            this->time_series.clear();
            this->mode.clear();
    
            #ifdef INCLUDE_GPU_TIMER
                this->DeinitEventsCUDA();
            #endif
        }
    
    数学の武士's avatar
    数学の武士 committed
    }
    
    EventData::EventData(const string& name)
    {
    
        this->double_start = 0.0;
    
    数学の武士's avatar
    数学の武士 committed
        this->start = chrono::steady_clock::now();
        this->elapsed_time = 0.0; 
        this->count = 0;
        this->ifCUDA = 0;
        this->event_name = name;
        this->ifStart = false, this->ifEnd = false;
    
        this->if_mode_set = false;
    
        this->time_series = vector<double>();
        this->mode = vector<bool>();
    
        #ifdef INCLUDE_GPU_TIMER
            this->InitEventsCUDA();
        #else
            this->ifCUDAinit = false;
        #endif
    
    数学の武士's avatar
    数学の武士 committed
    }
    
    EventData& EventData::operator=(const EventData& src)
    {
    
        this->double_start = src.double_start;
    
    数学の武士's avatar
    数学の武士 committed
        this->start = src.start;
        this->elapsed_time = 0.0; 
        this->count = 0;
        this->ifCUDA = 0;
        this->event_name = src.event_name;
        this->ifStart = false, this->ifEnd = false;
    
        this->if_mode_set = src.if_mode_set;
        this->ifCUDAinit = src.ifCUDAinit;
    
        this->time_series = src.time_series;
        this->mode = src.mode;
    
        #ifdef INCLUDE_GPU_TIMER
            this->gpu_start = src.gpu_start;
            this->gpu_end   = src.gpu_end;
        #endif
    
    数学の武士's avatar
    数学の武士 committed
    
        return *this;
    }
    
    double EventData::GetMeanElapsedTime()
    {
        return this->elapsed_time / this->count;
    }
    
    
    void EventData::GetModeVals(const int& mode)
    {   
        if((mode == TimerMode::MPI_mode)    || (mode == TimerMode::MPI_OpenMP) || (mode == TimerMode::MPI_CUDA)    || (mode == TimerMode::MPI_OpenMP_CUDA))
            this->mode.push_back(true);
        else
            this->mode.push_back(false);
    
        if((mode == TimerMode::OpenMP_mode) || (mode == TimerMode::MPI_OpenMP) || (mode == TimerMode::OpenMP_CUDA) || (mode == TimerMode::MPI_OpenMP_CUDA))
            this->mode.push_back(true);
        else
            this->mode.push_back(false);
    
        this->if_mode_set = true;
        
        if((mode == TimerMode::CUDA_mode)   || (mode == TimerMode::MPI_CUDA)   || (mode == TimerMode::OpenMP_CUDA) || (mode == TimerMode::MPI_OpenMP_CUDA))
            this->mode.push_back(true);
        else
            this->mode.push_back(false);
    }
    
    string EventData::GetEventModeName()
    {
        bool ifMPI = this->mode[0], ifOpenMP = this->mode[1], ifCUDA = this->mode[2]; 
        int flag = 0;
    
        string EventModeName = "";
    
        if(ifMPI)
        {
            EventModeName += "MPI";
            flag = 1;
        }
        if(ifOpenMP)
        {
            if(flag == 1)
                EventModeName += "_";
    
            EventModeName += "OpenMP";
            flag = 1;
        }
        if(ifCUDA)
        {
            if(flag == 1)
                EventModeName += "_";
    
            EventModeName += "CUDA";
        }
        if(!ifMPI && !ifOpenMP && !ifCUDA)
            EventModeName += "Asynchronous";
    
        return EventModeName;
    }