New version which reduces the number of virtual function calls
[charm.git] / src / conv-com / routerstrategy.h
1
2 /* Class that calls Krishnan's routers from the new Comlib.
3    Developed to be called from Converse
4    Sameer Kumar 05/14/04
5 */
6    
7
8 #ifndef ROUTER_STRATEGY
9 #define ROUTER_STRATEGY
10
11 #include "convcomlibmanager.h"
12
13 #include "gridrouter.h"
14 #include "graphrouter.h"
15 #include "de.h"
16 #include "treerouter.h"
17 #include "3dgridrouter.h"
18
19 class RouterStrategy : public Strategy {
20
21     Router * router;
22     CkQ<MessageHolder *> msgQ;
23     CkQ<char *> recvQ, procQ;
24     CkQ<DummyMsg *> dummyQ;
25
26     comID id;
27     int *pelist;
28     int npes;
29     int *procMap;
30     int *bcast_pemap;
31     int myPe;
32     int routerID;
33
34     int doneHandle;    //Array strategy done handle
35     int myDoneHandle;   //my own done handle, which will inturn call
36                        //array strategy done handle
37  
38    int doneFlag, bufferedDoneInserting;
39
40     void setReverseMap();
41
42  public:
43     //constructor
44     //stratid = which topology to use ? (Mesh?, Grid?, Hypercube ?)
45     //npes = number of processors in the all to all operation
46     //pelist = list of processors
47     RouterStrategy(int stratid, int handle, int npes, int *pelist);
48     RouterStrategy(CkMigrateMessage *m): Strategy(m){}
49     
50     ~RouterStrategy();
51
52     //Insert messages
53     void insertMessage(MessageHolder *msg);
54     //Finished inserting
55     void doneInserting();
56
57     //Call Krishnan's router functions
58     void RecvManyMsg(char *msg);
59     void ProcManyMsg(char *msg);
60     void DummyEP(DummyMsg *m);
61     
62     void Done(DummyMsg *m);
63
64     int * getProcMap() {return procMap;}
65
66     virtual void pup(PUP::er &p);
67     PUPable_decl(RouterStrategy);
68 };
69
70
71 //Call the router functions
72 inline void RouterStrategy::RecvManyMsg(char *msg) {
73
74     //comID new_id;
75     int new_refno =0;
76
77     //FOO BAR when structure of comid changes this will break !!!!!
78     ComlibPrintf("In RecvManyMsg at %d\n", CkMyPe());
79     //memcpy(&new_id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
80     //ComlibPrintf("REFNO = %d, %d\n", new_id.refno, id.refno);
81     
82     //First int in comid is refno
83     memcpy(&new_refno, (char*) msg + CmiReservedHeaderSize + sizeof(int), 
84            sizeof(int)); 
85
86     if(new_refno != id.refno)
87         recvQ.push(msg);
88     else
89         router->RecvManyMsg(id, msg);
90 }
91
92 inline void RouterStrategy::ProcManyMsg(char *msg) {    
93
94     //comID new_id;
95     int new_refno =0;
96     ComlibPrintf("In ProcManyMsg at %d\n", CkMyPe());
97     //memcpy(&new_id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
98     //First int in comid is refno
99     memcpy(&new_refno, (char*) msg + CmiReservedHeaderSize + sizeof(int), 
100            sizeof(int)); 
101     
102     if(new_refno != id.refno)
103         procQ.push(msg);
104     else
105         router->ProcManyMsg(id, msg);
106 }
107
108 inline void RouterStrategy::DummyEP(DummyMsg *m) {
109
110     if(id.refno != m->id.refno)
111         dummyQ.push(m);
112     else {
113         router->DummyEP(m->id, m->magic);
114         CmiFree(m);
115     }
116 }
117
118 #endif