00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00063
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;
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
00120 }
00121
00122 void sendMatrix();
00123
00124 virtual void pup(PUP::er &p){
00125
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
00185