From 61c3439b7ff12b824ffe4460eac31e7ef0489c49 Mon Sep 17 00:00:00 2001 From: Jan Huwald Date: Thu, 28 Feb 2013 10:18:56 +0100 Subject: get memory via mmap, try huge tables and prepopulation diff --git a/cacount.cpp b/cacount.cpp index 210d9b8..bd8f1a6 100644 --- a/cacount.cpp +++ b/cacount.cpp @@ -9,6 +9,8 @@ #include #include +#include + using namespace std; typedef uint32_t State; @@ -48,19 +50,17 @@ void init(Trans &t) { t[s] = update(s); }); } -Trans* findCycle(Trans &t) { +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); // compute loop id (lowest occuring state no): go through the loop again and // record the lowest occuring state number - Trans &c(*new Trans()); 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); - return &c; } void cycleStat(Trans &c) { @@ -120,6 +120,16 @@ void printTraj(State s, int count) { } } +template +T* mmalloc() { + void *p = MAP_FAILED; + for (auto flag : {MAP_POPULATE | MAP_HUGETLB, MAP_POPULATE, 0}) + if (p == MAP_FAILED) + p = mmap(NULL, sizeof(Trans), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | flag, -1, 0); + assert(p != MAP_FAILED); + return (T*) p; +} + int main(int argc, char **argv) { assert(argc >= 2); rule = atoi(argv[1]); @@ -128,10 +138,11 @@ int main(int argc, char **argv) { printTraj(atoi(argv[3]), atoi(argv[4])); } if (!strcmp(argv[2], "cycle")) { - Trans &t = *(new Trans); - init(t); - Trans &c(*findCycle(t)); - cycleStat(c); + Trans *t = mmalloc(), + *c = mmalloc(); + init(*t); + findCycle(*t, *c); + cycleStat(*c); } return 0; } -- cgit v0.10.1