00001 #include "converse.h"
00002 #include "queueing.h"
00003 #include "cldb.h"
00004 #include <stdlib.h>
00005
00006 void LoadNotifyFn(int l)
00007 {
00008 }
00009
00010 const char *CldGetStrategy(void)
00011 {
00012 return "rand";
00013 }
00014
00015 void CldHandler(char *msg)
00016 {
00017 int len, queueing, priobits;
00018 unsigned int *prioptr; CldInfoFn ifn; CldPackFn pfn;
00019 CldRestoreHandler(msg);
00020 ifn = (CldInfoFn)CmiHandlerToFunction(CmiGetInfo(msg));
00021 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00022 CsdEnqueueGeneral(msg, queueing, priobits, prioptr);
00023 }
00024
00025 void CldNodeHandler(char *msg)
00026 {
00027 int len, queueing, priobits;
00028 unsigned int *prioptr; CldInfoFn ifn; CldPackFn pfn;
00029 CldRestoreHandler(msg);
00030 ifn = (CldInfoFn)CmiHandlerToFunction(CmiGetInfo(msg));
00031 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00032 CsdNodeEnqueueGeneral(msg, queueing, priobits, prioptr);
00033 }
00034
00035 void CldEnqueueGroup(CmiGroup grp, void *msg, int infofn)
00036 {
00037 int len, queueing, priobits,i; unsigned int *prioptr;
00038 CldInfoFn ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
00039 CldPackFn pfn;
00040 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00041 if (pfn) {
00042 pfn(&msg);
00043 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00044 }
00045 CldSwitchHandler((char *)msg, CpvAccess(CldHandlerIndex));
00046 CmiSetInfo(msg,infofn);
00047
00048 CmiSyncMulticastAndFree(grp, len, msg);
00049 }
00050
00051 void CldEnqueueMulti(int npes, const int *pes, void *msg, int infofn)
00052 {
00053 int len, queueing, priobits,i; unsigned int *prioptr;
00054 CldInfoFn ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
00055 CldPackFn pfn;
00056 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00057 if (pfn) {
00058 pfn(&msg);
00059 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00060 }
00061 CldSwitchHandler((char *)msg, CpvAccess(CldHandlerIndex));
00062 CmiSetInfo(msg,infofn);
00063
00064
00065
00066
00067
00068
00069
00070
00071 CmiSyncListSendAndFree(npes, pes, len, msg);
00072 }
00073
00074 void CldEnqueue(int pe, void *msg, int infofn)
00075 {
00076 int len, queueing, priobits; unsigned int *prioptr;
00077 CldInfoFn ifn;
00078 CldPackFn pfn;
00079 if (pe == CLD_ANYWHERE) {
00080 pe = (((CrnRand()+CmiMyPe())&0x7FFFFFFF)%CmiNumPes());
00081
00082 #if CMK_NODE_QUEUE_AVAILABLE
00083 if (CmiNodeOf(pe) == CmiMyNode()) {
00084 CldNodeEnqueue(CmiMyNode(), msg, infofn);
00085 return;
00086 }
00087 #endif
00088 if (pe != CmiMyPe())
00089 CpvAccess(CldRelocatedMessages)++;
00090 }
00091 ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
00092 if (pe == CmiMyPe() && !CmiImmIsRunning()) {
00093 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00094
00095
00096 CsdEnqueueGeneral(msg, queueing, priobits, prioptr);
00097 } else {
00098 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00099 if (pfn && CmiNodeOf(pe) != CmiMyNode()) {
00100 pfn(&msg);
00101 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00102 }
00103 CldSwitchHandler((char *)msg, CpvAccess(CldHandlerIndex));
00104 CmiSetInfo(msg,infofn);
00105 if (pe==CLD_BROADCAST) { CmiSyncBroadcastAndFree(len, msg); }
00106 else if (pe==CLD_BROADCAST_ALL) { CmiSyncBroadcastAllAndFree(len, msg); }
00107 else {
00108
00109 CmiSyncSendAndFree(pe, len, msg);
00110 }
00111 }
00112 }
00113
00114 void CldNodeEnqueue(int node, void *msg, int infofn)
00115 {
00116 int len, queueing, priobits; unsigned int *prioptr;
00117 CldInfoFn ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
00118 CldPackFn pfn;
00119 if (node == CLD_ANYWHERE) {
00120 node = (((CrnRand()+CmiMyNode())&0x7FFFFFFF)%CmiNumNodes());
00121 if (node != CmiMyNode())
00122 CpvAccess(CldRelocatedMessages)++;
00123 }
00124 if (node == CmiMyNode() && !CmiImmIsRunning()) {
00125 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00126 CsdNodeEnqueueGeneral(msg, queueing, priobits, prioptr);
00127 } else {
00128 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00129 if (pfn) {
00130 pfn(&msg);
00131 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
00132 }
00133 CldSwitchHandler((char *)msg, CpvAccess(CldNodeHandlerIndex));
00134 CmiSetInfo(msg,infofn);
00135 if (node==CLD_BROADCAST) { CmiSyncNodeBroadcastAndFree(len, msg); }
00136 else if (node==CLD_BROADCAST_ALL){CmiSyncNodeBroadcastAllAndFree(len,msg);}
00137 else CmiSyncNodeSendAndFree(node, len, msg);
00138 }
00139 }
00140
00141 void CldModuleInit(char **argv)
00142 {
00143 CpvInitialize(int, CldHandlerIndex);
00144 CpvAccess(CldHandlerIndex) = CmiRegisterHandler((CmiHandler)CldHandler);
00145 CpvInitialize(int, CldNodeHandlerIndex);
00146 CpvAccess(CldNodeHandlerIndex) = CmiRegisterHandler((CmiHandler)CldNodeHandler);
00147 CpvInitialize(int, CldRelocatedMessages);
00148 CpvInitialize(int, CldLoadBalanceMessages);
00149 CpvInitialize(int, CldMessageChunks);
00150 CpvAccess(CldRelocatedMessages) = CpvAccess(CldLoadBalanceMessages) =
00151 CpvAccess(CldMessageChunks) = 0;
00152 CldModuleGeneralInit(argv);
00153 }
00154
00155 void CldCallback(void)
00156 {}