include/util/gsum64ext.h

Go to the documentation of this file.
00001 // PAB
00002 
00003 #ifndef _GSUM64_EXT_H_
00004 #define _GSUM64_EXT_H_
00005 
00006 #include <config.h>
00007 
00008 #include <qcdocos.h>
00009 #include <qcdocos/gsum64.h>
00010 
00011 enum GsumReduceType { SumReduce, MinReduce,  MaxReduce };
00012 
00013 
00014 template <class Tp> 
00015 class TypeSafeReducer {   // always assume  sizeof(Tp) < sizeof(double) = 8
00016  public:
00017   Tp  result;
00018 
00019   inline void convert(double * tgt,  Tp * src)      {  *(Tp*)tgt = *src;       }
00020   inline void convert(Tp * tgt, const double * src) {  *tgt = *(const Tp*)src; }
00021 
00022   inline Tp Reduce(double ** buf, int size, GsumReduceType type) {
00023     switch(type) {
00024     case SumReduce:
00025       Sum(buf,size);
00026       break;
00027     case MinReduce:
00028       Min(buf,size);
00029       break;
00030     case MaxReduce:
00031       Max(buf,size);
00032       break;
00033     }
00034     return result;
00035   }
00036 
00037   inline Tp Sum(double ** buf, int size) {
00038     Tp res, dat;
00039     convert(&res, buf[0]);
00040     for(int i=1;i<size;i++)  {
00041       convert(&dat, buf[i]);
00042       res += dat;
00043     }
00044     return (result = res);
00045   }
00046 
00047   inline Tp Max(double ** buf, int size) {
00048     Tp res, dat;
00049     convert(&res,buf[0]);
00050     for(int i=1;i<size;i++)  {
00051       convert(&dat, buf[i]);
00052       res = (res>dat?res:dat);
00053     }
00054     return (result = res);
00055   }
00056 
00057   inline Tp Min(double ** buf, int size) {
00058     Tp res, dat;
00059     convert(&res,buf[0]);
00060     for(int i=1;i<size;i++)  {
00061       convert(&dat, buf[i]);
00062       res = (res<dat?res:dat);
00063     }
00064     return (result = res);
00065   }
00066 };
00067 
00068 
00069 
00070 class Gsum64Ext{
00071   // this class sums int and unsigned int, with the buffer as type double *
00072   // it requires that Passthru class always send raw 64 bits from the buffer 
00073 
00074 protected:
00075 
00076   //  enum ReduceType { SumReduce, MinReduce,  MaxReduce };
00077 
00078   static const int Ndim = 6;
00079   static const int Ndir = 12;
00080   static const int MAX_NODE_DIM=32;
00081 
00082   static int Gnodes[Ndim];
00083   static int GCoord[Ndim];
00084 
00085   /*
00086    * Constant definitions
00087    */
00088 
00089   static const SCUDir  sdir[];
00090 
00091   static const SCUDir  rdir[];
00092 
00093   static const SCUAxis axis[];
00094 
00095 
00096   /*
00097    * No two gsums can be in progress concurrently, so can share these 
00098    */
00099   static double MyVal;
00100   static double *GsumArrayFW;
00101   static double *GsumArrayBW;
00102 
00103   /*
00104    * Potentially will want concurrent 1d,2d,3d, 4d, 5d Gsum instances however, so 
00105    * want to make lookup local to this Gsum64Ext instance.
00106    */
00107   double *Lookup[Ndim][MAX_NODE_DIM]; /*Look table for getting right sum order*/
00108 
00109   int ReduceDims[Ndim];
00110   int SndForward[Ndim];
00111   int SndBackward[Ndim];
00112 
00113 
00114   PassThru PassForward [Ndim];
00115   PassThru PassBackward[Ndim];
00116 
00117   void Prepare(SCUAxis axis);
00118   void Comm   (SCUAxis axis);
00119 
00120   //  double ReduceAll(double,ReduceType);
00121   void ReduceAll(GsumReduceType);
00122 
00123   void Reduce (SCUAxis axis,GsumReduceType);
00124 
00125   enum VAL_TYPE { VAL_DOUBLE, VAL_INT, VAL_UINT }  gsumValType;
00126 
00127 public:
00128 
00129   Gsum64Ext() { Init() ; };
00130 
00131   Gsum64Ext(const SCUAxis *axp,int nd) { Init(axp,nd) ; };
00132 
00133   ~Gsum64Ext() {};
00134 
00135   void Init(const SCUAxis *axis_p = axis ,int Nd = 6);
00136 
00137   double Sum(double);
00138   double Min(double);
00139   double Max(double);
00140 
00141   int Sum(int);
00142   int Min(int);
00143   int Max(int);
00144 
00145   unsigned int Sum(unsigned int);
00146   unsigned int Min(unsigned int);
00147   unsigned int Max(unsigned int);
00148 
00149 };
00150 
00151 #endif

Generated on Tue Mar 6 10:57:12 2007 for Columbia Physics System by  doxygen 1.4.6