OpenAtom  Version1.5a
orthoHelper.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $Source$
3  * $Author$
4  * $Date$
5  * $Revision$
6  *****************************************************************************/
7 
8 /** \file orthoHelper.h
9  *
10  * Made by Eric Bohm
11  * Login <bohm@localhost.localdomain>
12  *
13  * Started on Mon Sep 11 12:12:53 2006 Eric Bohm
14  * Last update Mon Sep 11 12:12:53 2006 Eric Bohm
15  *
16  * orthoHelper is just a chare array to host the 2nd multiply of the
17  * S->T method. It should be mapped adjacent to ortho such that
18  * ortho(x,y) and orthoHelper(x,y) are on different processors which
19  * are only one away. This assumes that ortho itself is mapped with a
20  * stride greater than 1. Orthohelper should only be used if numProcs
21  * >= 2 x numOrtho chares, otherwise we expect the parallelism gains
22  * would be lost to communication overhead.
23  *
24  * OrthoHelper is triggered by being given the result of multiply 1 by
25  * Ortho. It then computes multiply 2 and returns it to the ortho
26  * chares who sent it the multiply 1 input. This is a simple point to
27  * point communication ortho(x,y) <-> orthoHelper(x,y). Ortho then
28  * proceeds as normal through the S->T process.
29  */
30 
31 #include "ortho.decl.h"
32 
33 #ifndef ORTHOHELPER_H_
34 # define ORTHOHELPER_H_
35 
36 #include "CLA_Matrix.h"
37 
38 //////////////////////////////////////////////////////////////////////////////
39 //////////////////////////////////////////////////////////////////////////////
40 //////////////////////////////////////////////////////////////////////////////
42 public:
43  internalType *A;
44  internalType *B;
45  int size;
46  double factorA;
47  double factorB;
48  double factorC;
49  void init(int insize, internalType* inA, internalType* inB, double infactorA, double infactorB, double infactorC)
50  {
51  size=insize;
52  memcpy(A,inA,size*sizeof(internalType));
53  memcpy(B,inB,size*sizeof(internalType));
54  factorA=infactorA;
55  factorB=infactorB;
56  factorC=infactorC;
57  }
58  friend class CMessage_OrthoHelperMsg;
59 };
60 //////////////////////////////////////////////////////////////////////////////
61 
62 
64 {
65  public:
66  OrthoHelper(){}
67  OrthoHelper(int _m, int _n, CLA_Matrix_interface matA2,
69  CkCallback _orthoCB):
70  m(_m), n(_n), matA (matA2), matB(matB2), matC(matC2), uponCompletion(_orthoCB)
71  {
72  C= new internalType[m*n];
73  A=NULL;
74  B=NULL;
75  trigger=NULL;
76  }
77  OrthoHelper(CkMigrateMessage *m){}
78  ~OrthoHelper(){
79  delete [] C;
80  }
81 
82  void recvAB(OrthoHelperMsg *msg)
83  {
84  trigger = msg;
85  A = trigger->A; // no sense in making extra copies
86  B = trigger->B;
87  matA.multiply(trigger->factorA, 0, A, OrthoHelper::step_cb, (void*) this,
88  thisIndex.x, thisIndex.y);
89  CmiNetworkProgress();
90  matB.multiply(trigger->factorB, 0, B, OrthoHelper::step_cb, (void*) this,
91  thisIndex.x, thisIndex.y);
92  CmiNetworkProgress();
93  matC.multiply(trigger->factorC, 0, C, OrthoHelper::step_cb, (void*) this,
94  thisIndex.x, thisIndex.y);
95  // DO NOT DELETE MSG we're using that memory in A and B
96  }
97 
98  void sendMatrix()
99  {
100  if(trigger!=NULL)
101  delete trigger;
102  uponCompletion.send(m*n, C);
103  }
104 
105 
106  virtual void pup(PUP::er &p){
107 /// CBase_Ortho::pup(p);
108  ArrayElement2D::pup(p);
109  p | m;
110  p | n;
111  if(p.isUnpacking()){
112  C = new internalType[m * n];
113  }
114  PUParray(p, C, m * n);
115  }
116  static inline void step_cb(void *obj){
117  ((OrthoHelper *) obj)->sendMatrix();
118  }
119  int m;
120  int n;
121  internalType *A, *B, *C;
122  OrthoHelperMsg *trigger;
123  CLA_Matrix_interface matA, matB, matC;
124  /// Callback to the owner ortho chare array to be used at the end of my work (step 2)
125  CkCallback uponCompletion;
126 };
127 
128 #endif /* !ORTHOHELPER_H_ */
virtual void pup(PUP::er &p)
Definition: orthoHelper.h:106
CkCallback uponCompletion
Callback to the owner ortho chare array to be used at the end of my work (step 2) ...
Definition: orthoHelper.h:125