00001
00002
00003
00004
00005
00006 #include "converse.h"
00007 #include "blue.h"
00008 #include "cldb.h"
00009 #include "queueing.h"
00010 #include <stdlib.h>
00011
00012 #define DEBUGF(x)
00013
00014 #if CMK_BIGSIM_CHARM
00015
00016 extern int CldPresentPE(int pe);
00017
00018 void LoadNotifyFn(int l)
00019 {
00020 }
00021
00022 const char *CldGetStrategy(void)
00023 {
00024 return "rand";
00025 }
00026
00027 void CldBalanceHandler(void *msg)
00028 {
00029 CldRestoreHandler((char *)msg);
00030 CldPutToken((char *)msg);
00031 }
00032
00033 void CldHandler(char *msg)
00034 {
00035 int len, queueing, priobits;
00036 unsigned int *prioptr;
00037 CldInfoFn ifn; CldPackFn pfn;
00038
00039 CldRestoreHandler(msg);
00040 ifn = (CldInfoFn)CmiHandlerToFunction(CmiGetInfo(msg));
00041 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00042 CsdEnqueueGeneral(msg, queueing, priobits, prioptr);
00043 }
00044
00045 #if CMK_BIGSIM_NODE
00046 static int BgMyPe() { return BgMyNode(); }
00047 static int BgNumPes() { int x,y,z; BgGetSize(&x, &y, &z); return (x*y*z); }
00048 # define BGSENDPE(pe, msg, len) { \
00049 int x,y,z; \
00050 BgGetXYZ(pe, &x, &y, &z); \
00051 DEBUGF(("send to: (%d %d %d, %d) handle:%d\n", x,y,z,t, CmiGetHandler(msg))); \
00052 BgSendPacket(x,y,z, ANYTHREAD, CmiGetHandler(msg), LARGE_WORK, \
00053 len, (char *)msg); \
00054 }
00055 # define BGBDCASTALL(len, msg) \
00056 BgBroadcastAllPacket(CmiGetHandler(msg), LARGE_WORK, len, msg);
00057 # define BGBDCAST(len, msg) \
00058 BgBroadcastPacketExcept(BgMyNode(), ANYTHREAD, CmiGetHandler(msg), \
00059 LARGE_WORK, len, msg);
00060
00061 #elif CMK_BIGSIM_THREAD
00062 static int BgMyPe() { return BgGetGlobalWorkerThreadID(); }
00063 static int BgNumPes() { return BgNumNodes()*BgGetNumWorkThread(); }
00064 # define BGSENDPE(pe, msg, len) { \
00065 int x,y,z,t; \
00066 t = (pe)%BgGetNumWorkThread(); \
00067 pe = (pe)/BgGetNumWorkThread(); \
00068 BgGetXYZ(pe, &x, &y, &z); \
00069 DEBUGF(("send to: (%d %d %d, %d) handle:%d\n", x,y,z,t, CmiGetHandler(msg))); \
00070 BgSendPacket(x,y,z, t, CmiGetHandler(msg), LARGE_WORK, len, (char *)msg); \
00071 }
00072 # define BGBDCASTALL(len, msg) \
00073 BgThreadBroadcastAllPacket(CmiGetHandler(msg), LARGE_WORK, len, msg);
00074 # define BGBDCAST(len, msg) \
00075 BgThreadBroadcastPacketExcept(BgMyNode(), BgGetThreadID(), \
00076 CmiGetHandler(msg), LARGE_WORK, len, msg);
00077 # define BGSENDNODE(node, msg, len) { \
00078 int x,y,z; \
00079 BgGetXYZ(node, &x, &y, &z); \
00080 DEBUGF(("send to: (%d %d %d) handle:%d\n", x,y,z, CmiGetHandler(msg))); \
00081 BgSendPacket(x,y,z, ANYTHREAD, CmiGetHandler(msg), LARGE_WORK, len, (char *)msg); \
00082 }
00083 # define BGNODEBDCASTALL(len, msg) \
00084 BgBroadcastAllPacket(CmiGetHandler(msg), LARGE_WORK, len, msg);
00085 # define BGNODEBDCAST(len, msg) \
00086 BgBroadcastPacketExcept(BgMyNode(), ANYTHREAD,\
00087 CmiGetHandler(msg), LARGE_WORK, len, msg);
00088 #endif
00089
00090 void CldEnqueueGroup(CmiGroup grp, void *msg, int infofn)
00091 {
00092 CmiAbort("CldEnqueueGroup not supported!");
00093 }
00094
00095 void CldEnqueueMulti(int npes, const int *pes, void *msg, int infofn)
00096 {
00097 int len, queueing, priobits,i; unsigned int *prioptr;
00098 CldInfoFn ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
00099 CldPackFn pfn;
00100 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00101 if (pfn) {
00102 pfn(&msg);
00103 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00104 }
00105
00106
00107
00108
00109 BgSyncListSend(npes, pes, CmiGetHandler(msg), LARGE_WORK, len, (char *)msg);
00110 }
00111
00112 void CldEnqueue(int pe, void *msg, int infofn)
00113 {
00114 int len, queueing, priobits; unsigned int *prioptr;
00115 CldInfoFn ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
00116 CldPackFn pfn;
00117
00118 DEBUGF(("[%d>] CldEnqueue pe: %d infofn:%d\n", BgMyNode(), pe, infofn));
00119 if (pe == CLD_ANYWHERE) {
00120 pe = (((CrnRand()+BgMyPe())&0x7FFFFFFF)%BgNumPes());
00121
00122
00123
00124
00125 if (pe != BgMyPe())
00126 CpvAccess(CldRelocatedMessages)++;
00127 if (pe == BgMyPe()) {
00128 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00129 CmiSetInfo(msg,infofn);
00130 DEBUGF(("CldEnqueue CLD_ANYWHERE (pe == BgMyPe)\n"));
00131
00132
00133
00134 BGSENDPE(pe, msg, len);
00135 }
00136 else {
00137 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00138 if (pfn) {
00139 pfn(&msg);
00140 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00141 }
00142 DEBUGF(("CldEnqueue at 2 pe=%d\n", pe));
00143
00144
00145
00146
00147
00148 BGSENDPE(pe, msg, len);
00149 }
00150 }
00151 else if ((pe == BgMyPe()) || (BgNumPes() == 1)) {
00152 DEBUGF(("CldEnqueue pe == CmiMyPe()\n"));
00153 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00154 CmiSetInfo(msg,infofn);
00155
00156
00157
00158 pe = BgMyPe();
00159 BGSENDPE(pe, msg, len);
00160 }
00161 else {
00162 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00163 if (pfn) {
00164 pfn(&msg);
00165 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00166 }
00167
00168
00169
00170 CmiSetInfo(msg,infofn);
00171 DEBUGF(("CldEnqueue pe=%d\n", pe));
00172 if (pe==CLD_BROADCAST) {
00173 CmiPrintf("CldEnqueue pe=%d\n", pe); CmiAbort("");
00174
00175
00176
00177 BGBDCAST(len, (char *)msg);
00178 }
00179 else if (pe==CLD_BROADCAST_ALL) {
00180
00181
00182
00183 BGBDCASTALL(len, (char *)msg);
00184 }
00185 else {
00186
00187
00188
00189 BGSENDPE(pe, msg, len);
00190 }
00191 }
00192 }
00193
00194 void CldNodeEnqueue(int node, void *msg, int infofn)
00195 {
00196 int len, queueing, priobits; unsigned int *prioptr;
00197 CldInfoFn ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
00198 CldPackFn pfn;
00199 if (node == CLD_ANYWHERE) {
00200
00201 node = (((CrnRand()+BgMyNode())&0x7FFFFFFF)%BgNumNodes());
00202 if (node != BgMyNode())
00203 CpvAccess(CldRelocatedMessages)++;
00204 }
00205 if (node == BgMyNode()) {
00206 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00207
00208
00209
00210 BGSENDNODE(node, msg, len);
00211 }
00212 else {
00213 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00214 if (pfn) {
00215 pfn(&msg);
00216 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00217 }
00218
00219
00220
00221 CmiSetInfo(msg,infofn);
00222 if (node==CLD_BROADCAST) {
00223
00224 BGNODEBDCAST(len, (char *)msg);
00225 }
00226 else if (node==CLD_BROADCAST_ALL){
00227
00228 BGNODEBDCASTALL(len, (char *)msg);
00229 }
00230 else {
00231
00232 BGSENDNODE(node, msg, len);
00233 }
00234 }
00235 }
00236
00237 void CldModuleInit(char **argv)
00238 {
00239 CpvInitialize(int, CldHandlerIndex);
00240 CpvInitialize(int, CldBalanceHandlerIndex);
00241 CpvAccess(CldHandlerIndex) = CmiRegisterHandler((CmiHandler)CldHandler);
00242 CpvAccess(CldBalanceHandlerIndex) = CmiRegisterHandler(CldBalanceHandler);
00243 CpvInitialize(int, CldRelocatedMessages);
00244 CpvInitialize(int, CldLoadBalanceMessages);
00245 CpvInitialize(int, CldMessageChunks);
00246 CpvAccess(CldRelocatedMessages) = CpvAccess(CldLoadBalanceMessages) =
00247 CpvAccess(CldMessageChunks) = 0;
00248 CldModuleGeneralInit(argv);
00249 }
00250
00251 void CldCallback(void){}
00252
00253 #endif