00001
00025 #ifndef _DES_UNORDERED_H_
00026 #define _DES_UNORDERED_H_
00027
00028 #include "Galois/Galois.h"
00029 #include "Galois/Runtime/WorkList.h"
00030 #include "Galois/util/Accumulator.h"
00031
00032 #include "DESabstractMain.h"
00033
00034
00035 static const bool DEBUG = false;
00036
00037
00038 class DESunordered: public DESabstractMain {
00039 typedef Galois::GAccumulator<int> PerCPUcounter;
00040 typedef Galois::GReduceMax<size_t> ReduceMax;
00041
00046 struct process {
00047 Graph& graph;
00048 std::vector<unsigned int>& onWlFlags;
00049 PerCPUcounter& numEvents;
00050 PerCPUcounter& numIter;
00051 ReduceMax& maxPending;
00052
00053
00054 process (
00055 Graph& graph,
00056 std::vector<unsigned int>& onWlFlags,
00057 PerCPUcounter& numEvents,
00058 PerCPUcounter& numIter,
00059 ReduceMax& maxPending)
00060 : graph (graph), onWlFlags (onWlFlags), numEvents (numEvents), numIter (numIter), maxPending (maxPending) {}
00061
00062
00063
00073 template <typename ContextTy>
00074 void operator () (GNode& activeNode, ContextTy& lwl) {
00075 SimObject* srcObj = graph.getData (activeNode, Galois::CHECK_CONFLICT);
00076
00077
00078 for (Graph::neighbor_iterator i = graph.neighbor_begin (activeNode, Galois::CHECK_CONFLICT)
00079 , ei = graph.neighbor_end (activeNode, Galois::CHECK_CONFLICT); i != ei; ++i) {
00080
00081
00082 }
00083
00084
00085
00086
00087
00088 if (DEBUG) {
00089
00090 printf ("%d processing : %s\n", ThreadPool::getMyID (), srcObj->toString ().c_str ());
00091 }
00092
00093 maxPending.update (srcObj->numPendingEvents ());
00094
00095 int proc = srcObj->simulate(graph, activeNode);
00096 numEvents.get () += proc;
00097
00098 for (Graph::neighbor_iterator i = graph.neighbor_begin (activeNode, Galois::NONE)
00099 , ei = graph.neighbor_end (activeNode, Galois::NONE); i != ei; ++i) {
00100 const GNode& dst = *i;
00101
00102 SimObject* dstObj = graph.getData (dst, Galois::NONE);
00103
00104 dstObj->updateActive ();
00105
00106 if (dstObj->isActive ()) {
00107
00108 if (onWlFlags[dstObj->getId ()] == 0) {
00109 if (DEBUG) {
00110
00111 printf ("%d Added %d neighbor: %s\n" , ThreadPool::getMyID (), onWlFlags[dstObj->getId ()], dstObj->toString ().c_str ());
00112 }
00113 onWlFlags[dstObj->getId ()] = 1;
00114 lwl.push (dst);
00115
00116 }
00117
00118 }
00119 }
00120
00121 srcObj->updateActive();
00122
00123 if (srcObj->isActive()) {
00124 lwl.push (activeNode);
00125
00126 if (DEBUG) {
00127
00128 printf ("%d Added %d self: %s\n" , ThreadPool::getMyID (), onWlFlags[srcObj->getId ()], srcObj->toString ().c_str ());
00129 }
00130
00131 }
00132 else {
00133 onWlFlags[srcObj->getId ()] = 0;
00134 if (DEBUG) {
00135
00136 printf ("%d not adding %d self: %s\n" , ThreadPool::getMyID (), onWlFlags[srcObj->getId ()], srcObj->toString ().c_str ());
00137 }
00138 }
00139
00140 ++(numIter.get ());
00141
00142 }
00143 };
00144
00162 virtual void runLoop (const SimInit& simInit) {
00163 const std::vector<GNode>& initialActive = simInit.getInputNodes();
00164
00165
00166 std::vector<unsigned int> onWlFlags (simInit.getNumNodes (), 0);
00167
00168 for (std::vector<GNode>::const_iterator i = simInit.getInputNodes ().begin (), ei = simInit.getInputNodes ().end ();
00169 i != ei; ++i) {
00170 SimObject* srcObj = graph.getData (*i, Galois::NONE);
00171 onWlFlags[srcObj->getId ()] = 1;
00172 }
00173
00174
00175
00176 PerCPUcounter numEvents;
00177 PerCPUcounter numIter;
00178 ReduceMax maxPending;
00179
00180 process p(graph, onWlFlags, numEvents, numIter, maxPending);
00181
00182 Galois::for_each < GaloisRuntime::WorkList::FIFO<GNode> > (initialActive.begin (), initialActive.end (), p);
00183
00184 std::cout << "Number of events processed = " << numEvents.get () << std::endl;
00185 std::cout << "Number of iterations performed = " << numIter.get () << std::endl;
00186 std::cout << "Maximum size of pending events = " << maxPending.get () << std::endl;
00187 }
00188
00189 virtual bool isSerial () const { return false; }
00190 };
00191
00192
00193 #endif // _DES_UNORDERED_H_
00194