00001
00024 #ifndef AVI_UNORDERED_NO_LOCK_H_
00025 #define AVI_UNORDERED_NO_LOCK_H_
00026
00027
00028 #include "Galois/Graphs/Graph.h"
00029 #include "Galois/Galois.h"
00030
00031
00032 #include "Galois/Graphs/Serialize.h"
00033 #include "Galois/Graphs/FileGraph.h"
00034 #include "Galois/Runtime/PerCPU.h"
00035 #include "Galois/util/Atomic.h"
00036
00037 #include "Lonestar/Banner.h"
00038 #include "Lonestar/CommandLine.h"
00039
00040 #include <string>
00041 #include <sstream>
00042 #include <limits>
00043 #include <iostream>
00044 #include <fstream>
00045 #include <set>
00046
00047 #include <cassert>
00048
00049 #include "AuxDefs.h"
00050 #include "AVI.h"
00051 #include "Element.h"
00052
00053 #include "AVIabstractMain.h"
00054 #include "AVIunordered.h"
00055
00060 class AVIunorderedNoLock: public AVIunordered {
00061 typedef Galois::GAtomic<int> AtomicInteger;
00062
00063 protected:
00064
00065 virtual const std::string getVersion () const {
00066 return "Parallel Unordered, no abstract locks";
00067 }
00068
00072 struct process {
00073
00074 Graph& graph;
00075 std::vector<AtomicInteger>& inDegVec;
00076 MeshInit& meshInit;
00077 GlobalVec& g;
00078 GaloisRuntime::PerCPU<LocalVec>& perIterLocalVec;
00079 GaloisRuntime::PerCPU< std::vector<GNode> >& perIterAddList;
00080 const AVIComparator& aviCmp;
00081 bool createSyncFiles;
00082 IterCounter& iter;
00083
00084 process (
00085 Graph& graph,
00086 std::vector<AtomicInteger>& inDegVec,
00087 MeshInit& meshInit,
00088 GlobalVec& g,
00089 GaloisRuntime::PerCPU<LocalVec>& perIterLocalVec,
00090 GaloisRuntime::PerCPU< std::vector<GNode> >& perIterAddList,
00091 const AVIComparator& aviCmp,
00092 bool createSyncFiles,
00093 IterCounter& iter):
00094
00095 graph (graph),
00096 inDegVec (inDegVec),
00097 meshInit (meshInit),
00098 g (g),
00099 perIterLocalVec (perIterLocalVec),
00100 perIterAddList (perIterAddList),
00101 aviCmp (aviCmp),
00102 createSyncFiles (createSyncFiles),
00103 iter (iter) {}
00104
00105
00106 process (const process& that):
00107 graph (that.graph),
00108 inDegVec (that.inDegVec),
00109 meshInit (that.meshInit),
00110 g (that.g),
00111 perIterLocalVec (that.perIterLocalVec),
00112 perIterAddList (that.perIterAddList),
00113 aviCmp (that.aviCmp),
00114 createSyncFiles (that.createSyncFiles),
00115 iter (that.iter) {}
00116
00117
00136 template <typename ContextTy>
00137 void operator () (const GNode& src, ContextTy& lwl) {
00138 AVI* srcAVI = graph.getData (src, Galois::NONE);
00139
00140 int inDeg = (int)inDegVec[srcAVI->getGlobalIndex ()];
00141
00142
00143
00144
00145
00146 assert (inDeg == 0);
00147
00148 LocalVec& l = perIterLocalVec.get();
00149
00150 AVIabstractMain::simulate(srcAVI, meshInit, g, l, createSyncFiles);
00151
00152
00153
00154
00155
00156 int addAmt = 0;
00157
00158 for (Graph::neighbor_iterator j = graph.neighbor_begin (src, Galois::NONE), ej = graph.neighbor_end (src, Galois::NONE);
00159 j != ej; ++j) {
00160
00161 AVI* dstAVI = graph.getData (*j, Galois::NONE);
00162
00163 if (aviCmp.compare (srcAVI, dstAVI) > 0) {
00164 ++addAmt;
00165 }
00166
00167 }
00168
00169
00170
00171
00172 if (addAmt == 0) {
00173 if (srcAVI->getNextTimeStamp () < meshInit.getSimEndTime ()) {
00174 lwl.push (src);
00175 }
00176 }
00177 else {
00178 inDegVec[srcAVI->getGlobalIndex ()] += addAmt;
00179
00180 std::vector<GNode> toAdd = perIterAddList.get ();
00181 toAdd.clear ();
00182
00183 for (Graph::neighbor_iterator j = graph.neighbor_begin (src, Galois::NONE), ej = graph.neighbor_end(src, Galois::NONE);
00184 j != ej; ++j) {
00185
00186 const GNode& dst = *j;
00187 AVI* dstAVI = graph.getData (dst, Galois::NONE);
00188
00189 if (aviCmp.compare (srcAVI, dstAVI) > 0) {
00190 int din = --inDegVec[dstAVI->getGlobalIndex ()];
00191
00192 assert (din >= 0);
00193
00194 if (din == 0) {
00195 if (dstAVI->getNextTimeStamp () < meshInit.getSimEndTime ()) {
00196 toAdd.push_back (dst);
00197
00198
00199
00200 }
00201 }
00202 }
00203
00204 }
00205
00206
00207 for (std::vector<GNode>::const_iterator i = toAdd.begin (), ei = toAdd.end (); i != ei; ++i) {
00208 const GNode& gn = (*i);
00209 lwl.push (gn);
00210 }
00211
00212 }
00213
00214
00215
00216 ++(iter.get ());
00217
00218
00219 }
00220 };
00221
00222 public:
00223
00229 virtual void runLoop (MeshInit& meshInit, GlobalVec& g, bool createSyncFiles) {
00231
00233 std::vector<AtomicInteger> inDegVec(meshInit.getNumElements (), AtomicInteger (0));
00234 std::vector<GNode> initWl;
00235
00236 AVIComparator aviCmp;
00237
00238 for (Graph::active_iterator i = graph.active_begin (), e = graph.active_end (); i != e; ++i) {
00239 const GNode& src = *i;
00240 AVI* srcAVI = graph.getData (src, Galois::NONE);
00241
00242
00243 for (Graph::neighbor_iterator n = graph.neighbor_begin (src, Galois::NONE),
00244 en= graph.neighbor_end (src, Galois::NONE); n != en; ++n) {
00245
00246 AVI* dstAVI = graph.getData (*n, Galois::NONE);
00247 if (aviCmp.compare (srcAVI, dstAVI) > 0) {
00248 ++inDegVec[srcAVI->getGlobalIndex ()];
00249 }
00250 }
00251
00252
00253 if ((int)inDegVec[srcAVI->getGlobalIndex ()] == 0) {
00254 initWl.push_back (src);
00255 }
00256 }
00257
00258
00259
00260 printf ("Initial worklist contains %zd elements\n", initWl.size ());
00261
00262
00263
00264
00265
00266
00267
00268
00270
00272
00273
00274 size_t nrows = meshInit.getSpatialDim ();
00275 size_t ncols = meshInit.getNodesPerElem();
00276
00277 LocalVec l(nrows, ncols);
00278
00279 GaloisRuntime::PerCPU<LocalVec> perIterLocalVec (l);
00280
00281
00282 GaloisRuntime::PerCPU< std::vector<GNode> > perIterAddList;
00283
00284
00285
00286
00287 IterCounter iter(0);
00288
00289
00290 process p( graph, inDegVec, meshInit, g, perIterLocalVec, perIterAddList, aviCmp, createSyncFiles, iter);
00291
00292
00293 Galois::for_each< AVIWorkList >(initWl.begin (), initWl.end (), p);
00294
00295
00296 printf ("iterations = %d\n", iter.get ());
00297
00298 }
00299
00300
00301
00302 };
00303
00304 #endif
00305