Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Tsqr_GlobalTimeStats.cpp
00001 #include <Tsqr_GlobalTimeStats.hpp>
00002 #include <Tsqr_MessengerBase.hpp>
00003 
00006 
00007 namespace TSQR {
00008 
00009   TimeStats
00010   globalTimeStats (const Teuchos::RCP< MessengerBase< double > >& comm,
00011        const TimeStats& localStats)
00012   {
00013     TimeStats globalStats;
00014 
00015     // Casting int to double is exact.
00016     const double localCount = static_cast<double> (localStats.count());
00017 
00018     // The counts on all MPI processes should be equal if we are going
00019     // to try to compare them.  We test for this by computing the min
00020     // and max counts (which should be equal) over all processes.
00021     const double minCount = comm->globalMin (localCount);
00022     const double maxCount = comm->globalMax (localCount);
00023     if (minCount != maxCount)
00024       throw std::logic_error ("Global stats don\'t make "
00025             "sense, because counts differ");
00026     // minCount == maxCount, so we can use either one of them.  The
00027     // cast back from double is exact, because the double originally
00028     // came from an int.
00029     const int newCount = static_cast<int> (minCount);
00030       
00031     // Casting int to double is exact.
00032     const double P = static_cast<double> (comm->size());
00033     const double newMin = comm->globalMin (localStats.min());
00034     const double newMax = comm->globalMax (localStats.max());
00035     const double newMean = comm->globalSum (localStats.mean() / P);
00036 
00037     // Note that this is not the sum of the totals of all the
00038     // processes, but rather the "global total."  I've chosen to
00039     // define that as the max of the totals.
00040     const double newTotal = comm->globalMax (localStats.total());
00041 
00042     return TimeStats (newCount, newMin, newMax, newMean, newTotal);
00043   }
00044 
00045 
00046 } // namespace TSQR
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends