orthoHelper.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * $Source: /cvsroot/leanCP/src_charm_driver/orthog_ctrl/orthoHelper.h,v $
00003  * $Author: bhatele $
00004  * $Date: 2007/12/05 09:02:14 $
00005  * $Revision: 1.12 $
00006  *****************************************************************************/
00007 
00008 /** \file orthoHelper.h
00009  *
00010  *  Made by Eric Bohm
00011  *  Login   <bohm@localhost.localdomain>
00012  *  
00013  *  Started on  Mon Sep 11 12:12:53 2006 Eric Bohm
00014  *  Last update Mon Sep 11 12:12:53 2006 Eric Bohm
00015  *
00016  *  orthoHelper is just a chare array to host the 2nd multiply of the
00017  *  S->T method.  It should be mapped adjacent to ortho such that
00018  *  ortho(x,y) and orthoHelper(x,y) are on different processors which
00019  *  are only one away.  This assumes that ortho itself is mapped with a
00020  *  stride greater than 1. Orthohelper should only be used if numProcs
00021  *  >= 2 x numOrtho chares, otherwise we expect the parallelism gains
00022  *  would be lost to communication overhead.
00023  *
00024  *  OrthoHelper is triggered by being given the result of multiply 1 by
00025  *  Ortho.  It then computes multiply 2 and returns it to the ortho
00026  *  chares who sent it the multiply 1 input.  This is a simple point to
00027  *  point communication ortho(x,y) <-> orthoHelper(x,y).   Ortho then
00028  *  proceeds as normal through the S->T process.
00029  */
00030 
00031 #ifndef         ORTHOHELPER_H_
00032 # define        ORTHOHELPER_H_
00033 
00034 #include "CLA_Matrix.h"
00035 
00036 extern MapType2 OrthoHelperImaptable;
00037 extern CkHashtableT <intdual, int> OrthoHelpermaptable;
00038 extern bool fakeTorus;
00039 
00040 //////////////////////////////////////////////////////////////////////////////
00041 //////////////////////////////////////////////////////////////////////////////
00042 //////////////////////////////////////////////////////////////////////////////
00043 class OrthoHelperMsg : public CMessage_OrthoHelperMsg {
00044 public:
00045   double *A;
00046   double *B;
00047   int size; 
00048   double factorA;
00049   double factorB;
00050   double factorC;
00051   void init(int insize, double * inA, double * inB, double infactorA, double infactorB, double infactorC)
00052     {
00053       size=insize;
00054       memcpy(A,inA,size*sizeof(double));
00055       memcpy(B,inB,size*sizeof(double));
00056       factorA=infactorA;
00057       factorB=infactorB;
00058       factorC=infactorC;
00059     }
00060 
00061 #ifdef CMK_VERSION_BLUEGENE
00062   // if we use our own allocator we can get 16 byte alignment
00063   // to please BGL
00064 #define ALIGN16(x)        (int)((~15)&((x)+15))
00065  static  void *alloc(int msgnum, size_t sz, int *sizes, int pb) {
00066     int offsets[3];
00067     offsets[0] = ALIGN16(sz);
00068     if(sizes==0)
00069       offsets[1] = offsets[0];
00070     else
00071       offsets[1] = offsets[0] + ALIGN16(sizeof(double)*sizes[0]);
00072     if(sizes==0)
00073       offsets[2] = offsets[0];
00074     else
00075       offsets[2] = offsets[1] + ALIGN16(sizeof(double)*sizes[1]);
00076     OrthoHelperMsg *newmsg = (OrthoHelperMsg *) CkAllocMsg(msgnum, offsets[2], pb);
00077     newmsg->A = (double *) ((char *)newmsg + offsets[0]);
00078     newmsg->B = (double *) ((char *)newmsg + offsets[1]);
00079     return (void *) newmsg;
00080   }
00081 
00082 #endif
00083  friend class CMessage_OrthoHelperMsg;
00084 };
00085 //////////////////////////////////////////////////////////////////////////////
00086 
00087 
00088 class OrthoHelper : public CBase_OrthoHelper 
00089 {
00090  public:
00091   OrthoHelper(){}
00092   OrthoHelper(int _m, int _n, CLA_Matrix_interface matA2,
00093               CLA_Matrix_interface matB2, CLA_Matrix_interface matC2):
00094     m(_m), n(_n), matA (matA2), matB(matB2), matC(matC2)
00095     {
00096       C= new double[m*n];
00097       A=NULL;
00098       B=NULL;
00099       trigger=NULL;
00100     }
00101   OrthoHelper(CkMigrateMessage *m){}
00102   ~OrthoHelper(){
00103     delete [] C;
00104   }
00105 
00106   void recvAB(OrthoHelperMsg *msg)
00107     {  
00108       trigger = msg;
00109       A = trigger->A;  // no sense in making extra copies
00110       B = trigger->B;
00111       matA.multiply(trigger->factorA, 0, A, OrthoHelper::step_cb, (void*) this,
00112                      thisIndex.x, thisIndex.y);
00113       CmiNetworkProgress();
00114       matB.multiply(trigger->factorB, 0, B, OrthoHelper::step_cb, (void*) this,
00115                      thisIndex.x, thisIndex.y);
00116       CmiNetworkProgress();
00117       matC.multiply(trigger->factorC, 0, C, OrthoHelper::step_cb, (void*) this,
00118                      thisIndex.x, thisIndex.y);
00119       // DO NOT DELETE MSG we're using that memory in A and B
00120     }
00121 
00122   void sendMatrix();
00123 
00124   virtual void pup(PUP::er &p){
00125 ///    CBase_Ortho::pup(p);
00126     ArrayElement2D::pup(p);
00127     p | m;
00128     p | n;
00129     if(p.isUnpacking()){
00130       C = new double[m * n];
00131     }
00132     p(C, m * n);
00133   }
00134   static inline void step_cb(void *obj){
00135     ((OrthoHelper *) obj)->sendMatrix();
00136   }
00137   int m;
00138   int n;
00139   double *A, *B, *C;
00140   OrthoHelperMsg *trigger;
00141   CLA_Matrix_interface matA, matB, matC;
00142 };
00143 
00144 class OrthoHelperMap : public CkArrayMapTable2 {
00145   public:
00146     OrthoHelperMap()
00147     {
00148 #ifdef USE_INT_MAP
00149       maptable= &OrthoHelperImaptable;
00150 #else
00151       maptable= &OrthoHelpermaptable;
00152 #endif
00153     }
00154 
00155     ~OrthoHelperMap() { }
00156     
00157     void pup(PUP::er &p)
00158     {
00159       CkArrayMapTable2::pup(p);
00160 #ifdef USE_INT_MAP
00161       maptable= &OrthoHelperImaptable;
00162 #else
00163       maptable= &OrthoHelpermaptable;
00164 #endif
00165     }
00166     
00167     inline int procNum(int, const CkArrayIndex &iIndex)
00168     {
00169       int *index=(int *) iIndex.data();
00170       int proc;
00171 #ifdef USE_INT_MAP
00172       proc=maptable->get(index[0],index[1]);
00173 #else
00174       proc=maptable->get(intdual(index[0],index[1]));
00175 #endif
00176       if(fakeTorus)
00177         return(proc%CkNumPes());
00178       else
00179         return(proc);
00180 
00181     }
00182 };
00183 
00184 #endif      /* !ORTHOHELPER_H_ */
00185 

Generated on Thu Dec 6 18:25:31 2007 for leanCP by  doxygen 1.5.3