/*
  Class : MPI_Time

  Goal   : Measure and print elapsed and cpu times                     

  Usage  : 

#include "MPI_Time.h"

main(int argc, char *argv[]) {
  ...
  MPI_Init(&argc, &argv) ;
  ...
  MPI_Time timer;
  // Set elapse and CPU times
  timer.begin();
  ...
  ... Instruction block to instrument ...
  ...
  // Measure and print elapse and CPU times
  timer.end();
  ...
  MPI_Finalize();

}

   Notes   : 1) timer function is collective over all processes 
                of MPI_COMM_WORLD communicator.                   
             2) User must be aware that, on some machines, default
                CPU time includes also MPI communication time.    

   Output   : At normal termination, MPI process of rank 0 prints       
              on stderr the elapses and cpu times of all processes. 

   Author : Jalel Chergui, Jean-Michel Dupays

Permission is garanted to copy and distribute this file or modified
versions of this file for no fee, provided the copyright notice and
this permission notice are preserved on all copies.                

(C) April 2002, jean-michel.dupays@idris.fr, CNRS/IDRIS, France.   
*/

//------------------------------------------------------------------------------
class MPI_Time {
//------------------------------------------------------------------------------

public:
       MPI_Time();
       ~MPI_Time();
  void begin();
  void end();

private:
  double        Eoverhead;
  unsigned long Coverhead;
  double        Etime[2];
  unsigned long Ctime[2];
  double        CEtime;
  time_t        date[2];
  double        *All_Etime;
  unsigned long *All_Ctime;
  double        *All_CEtime;
  int           nb_procs;
  int           rank;
  enum          {master_rank=0};

  void print();

};
//------------------------------------------------------------------------------

template <class T> T sum(T *array, int n);
template <class T> T max(T *array, int n);
template <class T> T min(T *array, int n);

