 namespace dg
 {
 /*! @brief Very simple tool for performance measuring
- * 
+ *
  * @code
    dg::Timer t;
    t.tic();

{
  public:
    Timer(){
        cudaEventCreate( &start); 
        cudaEventCreate( &stop);
    }
    /**
    * @brief Start timer using cudaEventRecord
    *
    * @param stream the stream in which the Event is placed
    */
    void tic( cudaStream_t stream = 0){ cudaEventRecord( start, stream);}
    /**
    * @brief Stop timer using cudaEventRecord and Synchronize
    *
    * @param stream the stream in which the Event is placed
    */
    void toc( cudaStream_t stream = 0){ 
        cudaEventRecord( stop, stream);
        cudaEventSynchronize( stop);
    }
    float diff(){ 
        float time; 
        cudaEventElapsedTime( &time, start, stop);
        return time/1000.;
    }

class Timer //GPU MPI
{
  public:
    Timer(){ }
    void tic( MPI_Comm comm = MPI_COMM_WORLD ){
        cudaDeviceSynchronize();
        MPI_Barrier(comm);
        start = MPI_Wtime();
    }
    void toc( MPI_Comm comm = MPI_COMM_WORLD ){
        cudaDeviceSynchronize();
        MPI_Barrier(comm); //sync other cpus
        stop = MPI_Wtime();
    }
    double diff(){ return stop - start; }
  private:
    double start, stop;
};
}//namespace dg

