From 5f69a514e6fc5375ec477be1bced12a81fba3934 Mon Sep 17 00:00:00 2001 From: Jan Huwald Date: Thu, 28 Feb 2013 12:10:27 +0100 Subject: add parallel execution diff --git a/Makefile b/Makefile index 010c76d..221f015 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CXX=g++ -std=c++0x -O3 -Wall -Wextra -Werror +CXX=g++ -std=c++0x -O3 -Wall -Wextra -Werror -lpthread all: cacount diff --git a/cacount.cpp b/cacount.cpp index bd8f1a6..1ef159b 100644 --- a/cacount.cpp +++ b/cacount.cpp @@ -6,8 +6,10 @@ #include #include #include +#include #include #include +#include #include @@ -31,36 +33,45 @@ State update(State s) { typedef array Trans; -void iterState(function f) { - for (State s=0; s f, int numThreads=1) { + list tasks; + for (int t=0; tjoin(), delete tasks.front(), tasks.pop_front()); } -void iterTrans(int times, function f, bool verbose=false) { - if (verbose) cerr << times << " left\r"; +void iterTrans(int times, function f, char *msg = nullptr) { + if (msg) cerr << msg << times << " left\r"; while (times--) { iterState(f); - if (verbose) cerr << times << " left\r"; + if (msg) cerr << msg << times << " left\r"; } - if (verbose) cerr << " \r"; + if (msg) cerr << " \r"; } void init(Trans &t) { - iterState([&](int s) { - t[s] = update(s); }); + iterState([&](int s) { + t[s] = update(s); }, + thread::hardware_concurrency()); } void findCycle(Trans &t, Trans &c) { // forward to t=maxState; now every state is in a cycle iterTrans(logState, [&](int s) { - t[s] = t[t[s]]; }, true); + t[s] = t[t[s]]; }, (char*) "fwd time: "); // compute loop id (lowest occuring state no): go through the loop again and // record the lowest occuring state number iterState([&](int s) { c[s] = t[s]; }); iterTrans(logState, [&](int s) { c[s] = min(c[s], c[t[s]]); - t[s] = t[t[s]]; }, true); + t[s] = t[t[s]]; }, (char*) "cycles: "); } void cycleStat(Trans &c) { -- cgit v0.10.1