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