Bug #1062: Fix linking errors by moving definition of userDrivenMode to machine-commo...
[charm.git] / src / conv-ldb / cldb.test.c
blob7a44c0926f4d900f1f2dbc794f6aba4845aa75b1
1 #include "converse.h"
2 #include "cldb.h"
3 #include "queueing.h"
4 #include <stdlib.h>
6 void LoadNotifyFn(int l)
10 char *CldGetStrategy(void)
12 return "rand";
15 void CldBalanceHandler(void *msg)
17 CldRestoreHandler(msg);
18 CldPutToken(msg);
21 void CldHandler(char *msg)
23 int len, queueing, priobits;
24 unsigned int *prioptr;
25 CldInfoFn ifn; CldPackFn pfn;
27 CldRestoreHandler(msg);
28 ifn = (CldInfoFn)CmiHandlerToFunction(CmiGetInfo(msg));
29 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
30 CsdEnqueueGeneral(msg, queueing, priobits, prioptr);
33 void CldEnqueueMulti(int npes, int *pes, void *msg, int infofn)
35 int len, queueing, priobits,i; unsigned int *prioptr;
36 CldInfoFn ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
37 CldPackFn pfn;
38 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
39 if (pfn) {
40 pfn(&msg);
41 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
43 CldSwitchHandler(msg, CpvAccess(CldHandlerIndex));
44 CmiSetInfo(msg,infofn);
45 for(i=0;i<npes;i++) {
46 CmiSyncSend(pes[i], len, msg);
48 CmiFree(msg);
51 void CldEnqueue(int pe, void *msg, int infofn)
53 int len, queueing, priobits; unsigned int *prioptr;
54 CldInfoFn ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
55 CldPackFn pfn;
57 if (pe == CLD_ANYWHERE) {
58 pe = (((CrnRand()+CmiMyPe())&0x7FFFFFFF)%CmiNumPes());
59 while (!CldPresentPE(pe))
60 pe = (((CrnRand()+CmiMyPe())&0x7FFFFFFF)%CmiNumPes());
61 if (pe != CmiMyPe())
62 CpvAccess(CldRelocatedMessages)++;
63 if (pe == CmiMyPe()) {
64 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
65 CmiSetInfo(msg,infofn);
66 CldPutToken(msg);
68 else {
69 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
70 if (pfn) {
71 pfn(&msg);
72 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
74 CldSwitchHandler(msg, CpvAccess(CldBalanceHandlerIndex));
75 CmiSetInfo(msg,infofn);
76 CmiSyncSendAndFree(pe, len, msg);
79 else if ((pe == CmiMyPe()) || (CmiNumPes() == 1)) {
80 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
81 CmiSetInfo(msg,infofn);
82 CsdEnqueueGeneral(msg, CQS_QUEUEING_LIFO, priobits, prioptr);
84 else {
85 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
86 if (pfn) {
87 pfn(&msg);
88 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
90 CldSwitchHandler(msg, CpvAccess(CldHandlerIndex));
91 CmiSetInfo(msg,infofn);
92 if (pe==CLD_BROADCAST) { CmiSyncBroadcastAndFree(len, msg); }
93 else if (pe==CLD_BROADCAST_ALL) { CmiSyncBroadcastAllAndFree(len, msg); }
94 else CmiSyncSendAndFree(pe, len, msg);
98 void CldNodeEnqueue(int node, void *msg, int infofn)
100 int len, queueing, priobits; unsigned int *prioptr;
101 CldInfoFn ifn = (CldInfoFn)CmiHandlerToFunction(infofn);
102 CldPackFn pfn;
103 if (node == CLD_ANYWHERE) {
104 /* node = (((rand()+CmiMyNode())&0x7FFFFFFF)%CmiNumNodes()); */
105 node = (((CrnRand()+CmiMyNode())&0x7FFFFFFF)%CmiNumNodes());
106 if (node != CmiMyNode())
107 CpvAccess(CldRelocatedMessages)++;
109 if (node == CmiMyNode()) {
110 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
111 CsdNodeEnqueueGeneral(msg, queueing, priobits, prioptr);
113 else {
114 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
115 if (pfn) {
116 pfn(&msg);
117 ifn(msg, &pfn, &len, &queueing, &priobits, &prioptr);
119 CldSwitchHandler(msg, CpvAccess(CldHandlerIndex));
120 CmiSetInfo(msg,infofn);
121 if (node==CLD_BROADCAST) { CmiSyncNodeBroadcastAndFree(len, msg); }
122 else if (node==CLD_BROADCAST_ALL){CmiSyncNodeBroadcastAllAndFree(len,msg);}
123 else CmiSyncNodeSendAndFree(node, len, msg);
127 void CldModuleInit(char **argv)
129 CpvInitialize(int, CldHandlerIndex);
130 CpvInitialize(int, CldBalanceHandlerIndex);
131 CpvAccess(CldHandlerIndex) = CmiRegisterHandler((CmiHandler)CldHandler);
132 CpvAccess(CldBalanceHandlerIndex) = CmiRegisterHandler(CldBalanceHandler);
133 CpvInitialize(int, CldRelocatedMessages);
134 CpvInitialize(int, CldLoadBalanceMessages);
135 CpvInitialize(int, CldMessageChunks);
136 CpvAccess(CldRelocatedMessages) = CpvAccess(CldLoadBalanceMessages) =
137 CpvAccess(CldMessageChunks) = 0;
138 CldModuleGeneralInit(argv);