modified the registration of the converse handlers for propagate and propagate_frag.
[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 myPe;
31     int routerID;
32
33     int doneHandle;    //Array strategy done handle
34     int myDoneHandle;   //my own done handle, which will inturn call
35                        //array strategy done handle
36  
37    int doneFlag, bufferedDoneInserting;
38
39     void setReverseMap();
40
41  public:
42     //constructor
43     //stratid = which topology to use ? (Mesh?, Grid?, Hypercube ?)
44     //npes = number of processors in the all to all operation
45     //pelist = list of processors
46     RouterStrategy(int stratid, int handle, int npes, int *pelist);
47     RouterStrategy(CkMigrateMessage *m): Strategy(m){}
48
49     //Insert messages
50     void insertMessage(MessageHolder *msg);
51     //Finished inserting
52     void doneInserting();
53
54     //Call Krishnan's router functions
55     void RecvManyMsg(char *msg);
56     void ProcManyMsg(char *msg);
57     void DummyEP(DummyMsg *m);
58     
59     void Done(DummyMsg *m);
60
61     int * getProcMap() {return procMap;}
62
63     virtual void pup(PUP::er &p);
64     PUPable_decl(RouterStrategy);
65 };
66
67
68 //Call the router functions
69 inline void RouterStrategy::RecvManyMsg(char *msg) {
70
71     //comID new_id;
72     int new_refno =0;
73
74     //FOO BAR when structure of comid changes this will break !!!!!
75     ComlibPrintf("In RecvManyMsg at %d\n", CkMyPe());
76     //memcpy(&new_id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
77     //ComlibPrintf("REFNO = %d, %d\n", new_id.refno, id.refno);
78     
79     //First int in comid is refno
80     memcpy(&new_refno, (char*) msg + CmiReservedHeaderSize + sizeof(int), 
81            sizeof(int)); 
82
83     if(new_refno != id.refno)
84         recvQ.push(msg);
85     else
86         router->RecvManyMsg(id, msg);
87 }
88
89 inline void RouterStrategy::ProcManyMsg(char *msg) {    
90
91     //comID new_id;
92     int new_refno =0;
93     ComlibPrintf("In ProcManyMsg at %d\n", CkMyPe());
94     //memcpy(&new_id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
95     //First int in comid is refno
96     memcpy(&new_refno, (char*) msg + CmiReservedHeaderSize + sizeof(int), 
97            sizeof(int)); 
98     
99     if(new_refno != id.refno)
100         procQ.push(msg);
101     else
102         router->ProcManyMsg(id, msg);
103 }
104
105 inline void RouterStrategy::DummyEP(DummyMsg *m) {
106
107     if(id.refno != m->id.refno)
108         dummyQ.push(m);
109     else {
110         router->DummyEP(m->id, m->magic);
111         CmiFree(m);
112     }
113 }
114
115 #endif