Merge branch 'charm' into virtualDebug
[charm.git] / src / ck-core / middle-blue.h
1 /*****************************************************************************
2           Blue Gene Middle Layer for Charm++ program
3 *****************************************************************************/
4
5 #ifndef _MIDDLE_BLUE_H_
6 #define _MIDDLE_BLUE_H_
7
8 #include <memory.h>
9 #include "converse.h"
10 #include "blue.h"
11
12 #undef CkMyPe
13 #undef CkNumPes
14 #undef CkMyRank
15 #undef CkMyNode
16 #undef CkNumNodes
17 #undef CkMyNodeSize
18
19 #undef CmiSyncSend
20 #undef CmiSyncSendAndFree
21 #undef CmiSyncBroadcast
22 #undef CmiSyncBroadcastAndFree
23 #undef CmiSyncBroadcastAll
24 #undef CmiSyncBroadcastAllAndFree
25
26 #undef CmiSyncNodeSend
27 #undef CmiSyncNodeSendAndFree
28 #undef CmiSyncNodeBroadcast
29 #undef CmiSyncNodeBroadcastAndFree
30 #undef CmiSyncNodeBroadcastAll
31 #undef CmiSyncNodeBroadcastAllAndFree
32
33
34 #undef CkWallTimer
35 #undef CkCpuTimer
36 #define CkWallTimer     BgGetTime
37 #define CkCpuTimer      BgGetTime
38 #define CkVTimer        BgGetTime
39 #define CkElapse   BgElapse
40
41 #define CkRegisterHandler(x)        BgRegisterHandler((BgHandler)(x))
42 #define CkNumberHandler(n, x)       BgNumberHandler(n, (BgHandler)(x))
43 #define CkNumberHandlerEx(n, x, p)  BgNumberHandlerEx(n, (BgHandlerEx)(x), p)
44
45 #define ConverseExit             BgCharmExit
46
47 /**
48   This version Blue Gene Charm++ use a whole Blue Gene node as 
49   a Charm PE.
50 */
51 #if CMK_BLUEGENE_NODE
52
53 #define CkpvDeclare     BnvDeclare
54 #define CkpvExtern      BnvExtern
55 #define CkpvStaticDeclare  BnvStaticDeclare
56 #define CkpvInitialize  BnvInitialize
57 #define CkpvInitialized BnvInitialized
58 #define CkpvAccess      BnvAccess
59 #define CkpvAccessOther BnvAccessOther
60
61 namespace BGConverse {
62
63 inline int CkMyPe() { return BgMyNode(); }
64 inline int CkNumPes() { int x,y,z; BgGetSize(&x, &y, &z); return (x*y*z); }
65 inline int CkMyRank() { return 0; }
66 inline int BgNodeRank() { return BgMyRank(); }
67 inline int CkMyNodeSize() { return 1; }
68
69 #if 0
70 static inline void CmiSyncSend(int pe, int nb, char *m) 
71 {
72   int x,y,z;
73   char *dupm = (char *)CmiAlloc(nb);
74
75 //CmiPrintf("[%d] CmiSyncSend handle:%d\n", CkMyPe(), CmiGetHandler(m));
76   memcpy(dupm, m, nb);
77   BgGetXYZ(pe, &x, &y, &z);
78   BgSendPacket(x,y,z, ANYTHREAD, CmiGetHandler(m), LARGE_WORK, nb, dupm);
79 }
80
81 static inline void CmiSyncSendAndFree(int pe, int nb, char *m)
82 {
83   int x,y,z;
84 //CmiPrintf("[%d] CmiSyncSendAndFree handle:%d\n", CkMyPe(), CmiGetHandler(m));
85   BgGetXYZ(pe, &x, &y, &z);
86   BgSendPacket(x,y,z, ANYTHREAD, CmiGetHandler(m), LARGE_WORK, nb, m);
87 }
88
89 static inline void CmiSyncBroadcast(int nb, char *m)
90 {
91   char *dupm = (char *)CmiAlloc(nb);
92 //CmiPrintf("[%d] CmiSyncBroadcast handle:%d\n", CkMyPe(), CmiGetHandler(m));
93   memcpy(dupm, m, nb);
94   BgBroadcastPacketExcept(CkMyPe(), ANYTHREAD, CmiGetHandler(m), LARGE_WORK, nb, dupm);
95 }
96
97 static inline void CmiSyncBroadcastAndFree(int nb, char *m)
98 {
99 //CmiPrintf("CmiSyncBroadcastAndFree handle:%d\n", CmiGetHandler(m));
100   BgBroadcastPacketExcept(CkMyPe(), ANYTHREAD, CmiGetHandler(m), LARGE_WORK, nb, m);
101 }
102
103 static inline void CmiSyncBroadcastAll(int nb, char *m)
104 {
105   char *dupm = (char *)CmiAlloc(nb);
106 //CmiPrintf("CmiSyncBroadcastAll: handle:%d\n", CmiGetHandler(m));
107   memcpy(dupm, m, nb);
108   BgBroadcastAllPacket(CmiGetHandler(m), LARGE_WORK, nb, dupm);
109 }
110
111 static inline void CmiSyncBroadcastAllAndFree(int nb, char *m)
112 {
113 //CmiPrintf("CmiSyncBroadcastAllAndFree: handle:%d\n", CmiGetHandler(m));
114   /* broadcast to all nodes */
115   BgBroadcastAllPacket(CmiGetHandler(m), LARGE_WORK, nb, m);
116 }
117 #endif
118
119 }  /* end of namespace */
120
121
122 #else   /* end if CMK_BLUEGENE_NODE */
123
124 /**
125   This version of Blue Gene Charm++ use a Blue Gene thread as 
126   a Charm PE.
127 */
128
129 #define CkpvDeclare        BpvDeclare
130 #define CkpvExtern         BpvExtern
131 #define CkpvStaticDeclare  BpvStaticDeclare
132 #define CkpvInitialize     BpvInitialize
133 #define CkpvInitialized    BpvInitialized
134 #define CkpvAccess         BpvAccess
135 #define CkpvAccessOther    BpvAccessOther
136
137 #define CksvDeclare        BnvDeclare
138 #define CksvExtern         BnvExtern
139 #define CksvStaticDeclare  BnvStaticDeclare
140 #define CksvInitialize     BnvInitialize
141 #define CksvAccess         BnvAccess
142
143 namespace BGConverse {
144
145 static inline int CkMyPe() { return BgGetGlobalWorkerThreadID(); }
146 static inline int CkNumPes() { return BgNumNodes()*BgGetNumWorkThread(); }
147 static inline int CkMyRank() { return BgGetThreadID(); }
148 static inline int BgNodeRank() { return BgMyRank()*BgGetNumWorkThread()+BgGetThreadID(); }
149 static inline int CkMyNode() { return BgMyNode(); }
150 static inline int CkNumNodes() { return BgNumNodes(); }
151 static inline int CkMyNodeSize() { return BgGetNumWorkThread(); }
152
153 static inline void CksdScheduler(int ret) { BgScheduler(ret); }
154 static inline void CksdExitScheduler() { BgExitScheduler(); }
155 static inline void CkDeliverMsgs(int nmsg)      { BgDeliverMsgs(nmsg); }
156
157 void CkReduce(void *msg, int size, CmiReduceMergeFn mergeFn);
158
159 }  /* end of namespace */
160
161 #endif
162
163 #define CmiSyncSend                     BgSyncSend
164 #define CmiSyncSendAndFree              BgSyncSendAndFree
165 #define CmiSyncBroadcast                BgSyncBroadcast
166 #define CmiSyncBroadcastAndFree         BgSyncBroadcastAndFree
167 #define CmiSyncBroadcastAll             BgSyncBroadcastAll
168 #define CmiSyncBroadcastAllAndFree      BgSyncBroadcastAllAndFree
169
170 #define CmiSyncNodeSend                 BgSyncNodeSend
171 #define CmiSyncNodeSendAndFree          BgSyncNodeSendAndFree
172 #define CmiSyncNodeBroadcast            BgSyncNodeBroadcast
173 #define CmiSyncNodeBroadcastAndFree     BgSyncNodeBroadcastAndFree
174 #define CmiSyncNodeBroadcastAll         BgSyncNodeBroadcastAll
175 #define CmiSyncNodeBroadcastAllAndFree  BgSyncNodeBroadcastAllAndFree
176
177 #undef CmiSyncListSendAndFree
178 #define CmiSyncListSendAndFree          BgSyncListSendAndFree
179
180 #define CmiMultipleSend                 BgMultipleSend
181
182 #undef CsdEnqueueLifo
183 //#define CsdEnqueueLifo(m)  CmiSyncSendAndFree(CkMyPe(),((envelope*)m)->getTotalsize(), (char*)(m));
184 #define CsdEnqueueLifo(m)               BgEnqueue((char*)m)
185
186 #undef CmiNodeAllBarrier
187 #define CmiNodeAllBarrier()
188
189 /** common functions for two versions */
190 namespace BGConverse {
191
192 static inline void BgCharmExit()
193 {
194 //  traceCharmClose();
195   if (CkMyPe() == 0)  BgShutdown();
196 }
197
198 }
199
200
201 #endif