00001
00008
00009
00010
00011
00012 #if !defined(WIN32) || defined(__CYGWIN__)
00013 #include <unistd.h>
00014 #endif
00015 #include <stdio.h>
00016
00017 #include "InfoStream.h"
00018 #include "Patch.h"
00019 #include "PatchMap.h"
00020 #include "ProxyMgr.h"
00021 #include "Compute.h"
00022 #include "ComputeMap.h"
00023
00024 #include "Sync.h"
00025
00026 #define MIN_DEBUG_LEVEL 3
00027
00028 #include "Debug.h"
00029
00030
00031
00032 int useSync = 1;
00033
00034
00035
00036
00037
00038
00039 int useProxySync = 0;
00040
00041 Sync::Sync(): INCREASE(600), step(0), counter(0), homeReady(0)
00042 {
00043 if (CkpvAccess(Sync_instance) == NULL) {
00044 CkpvAccess(Sync_instance) = this;
00045 } else {
00046 iout << iFILE << iERROR << iPE
00047 << "Sync instanced twice on same processor!" << endi;
00048 CkExit();
00049 }
00050 capacity = INCREASE;
00051 clist = new _clist[capacity];
00052 cnum = 0;
00053 nPatcheReady = 0;
00054 numPatches = -1;
00055 }
00056
00057 Sync::~Sync()
00058 {
00059 delete [] clist;
00060 }
00061
00062 void Sync::openSync(void)
00063 {
00064 if (useSync) {
00065
00066 if (!useProxySync && (proxySendSpanning || proxyRecvSpanning)) {
00067 #if !CMK_IMMEDIATE_MSG
00068
00069 if (CkMyPe() == 0)
00070 CmiPrintf("[%d] useProxySync is turned on. \n", CkMyPe());
00071
00072
00073 #if !CMK_BLUEGENEP
00074
00075 useProxySync = 1;
00076 #endif
00077 #endif
00078 }
00079
00080 if (useProxySync && ProxyMgr::Object()->numProxies() == 0) {
00081
00082 useProxySync = 0;
00083 }
00084
00085 if (!useProxySync && PatchMap::Object()->numHomePatches() == 0) useSync = 0;
00086 }
00087 if(CkMyPe() == 0)
00088 iout << iINFO << "useSync: " << useSync << " useProxySync: " << useProxySync << "\n" << endi;
00089 }
00090
00091
00092 int Sync::holdComputes(PatchID pid, ComputeIDListIter cid, int doneMigration)
00093 {
00094 if (!useProxySync) {
00095
00096 PatchMap *patchMap = PatchMap::Object();
00097 if (homeReady) {
00098 triggerCompute();
00099 return 0;
00100 }
00101 }
00102
00103 int slot = 0;
00104 for (; slot < cnum; slot++)
00105 if (clist[slot].pid == -1) break;
00106 if (slot == cnum) {
00107 cnum++;
00108
00109 if (cnum == capacity) {
00110 capacity += INCREASE;
00111 struct _clist *tmp = new _clist[capacity];
00112 memcpy(tmp, clist, cnum*sizeof(_clist));
00113 delete [] clist;
00114 clist = tmp;
00115
00116 }
00117 }
00118
00119 clist[slot].cid = cid;
00120 clist[slot].pid = pid;
00121 clist[slot].doneMigration = doneMigration;
00122 clist[slot].step = PatchMap::Object()->patch(pid)->flags.sequence;
00123
00124
00125
00126 if (clist[slot].step == step) {
00127 nPatcheReady++;
00128 triggerCompute();
00129 }
00130 return 1;
00131 }
00132
00133
00134 void Sync::PatchReady(void)
00135 {
00136 counter ++;
00137 triggerCompute();
00138 }
00139
00140 void Sync::releaseComputes()
00141 {
00142 PatchMap *patchMap = PatchMap::Object();
00143 ComputeMap *computeMap = ComputeMap::Object();
00144
00145 nPatcheReady = 0;
00146 for (int i= 0; i<cnum; i++) {
00147 int &pid = clist[i].pid;
00148 if (pid == -1) continue;
00149 if (clist[i].step != step) {
00150
00151 if (clist[i].step == step + 1) nPatcheReady++;
00152 continue;
00153 }
00154
00155
00156
00157
00158 ComputeIDListIter cid = clist[i].cid;
00159
00160 int compute_count = 0;
00161 for(cid = cid.begin(); cid != cid.end(); cid++) {
00162 compute_count++;
00163 computeMap->compute(*cid)->patchReady(pid,clist[i].doneMigration,step);
00164 }
00165 if (compute_count == 0 && patchMap->node(pid) != CkMyPe()) {
00166 iout << iINFO << "PATCH_COUNT-Sync step " << step
00167 << "]: Patch " << pid << " on PE "
00168 << CkMyPe() <<" home patch "
00169 << patchMap->node(pid) << " does not have any computes\n"
00170 << endi;
00171 }
00172 pid = -1;
00173 }
00174
00175 }
00176
00177 void Sync::triggerCompute()
00178 {
00179 PatchMap *patchMap = PatchMap::Object();
00180
00181 if (numPatches == -1)
00182 numPatches = ProxyMgr::Object()->numProxies() + patchMap->numHomePatches();
00183
00184
00185
00186 if (homeReady == 0 && counter == patchMap->numHomePatches()) {
00187 homeReady = 1;
00188 if (!useProxySync) releaseComputes();
00189 }
00190
00191 if (homeReady && nPatcheReady == numPatches)
00192 {
00193
00194 if (useProxySync) releaseComputes();
00195
00196
00197 counter = 0;
00198 numPatches = -1;
00199 step++;
00200 homeReady = 0;
00201 }
00202 }
00203
00204
00205 #if 0
00206
00207
00208 void *frightenCompilerIntoInstantiatingHack(void) {
00209 return new ArrayElementT<int>;
00210 }
00211 #endif
00212
00213
00214 #include "Sync.def.h"