X-Git-Url: http://plrg.eecs.uci.edu/git/?p=junction.git;a=blobdiff_plain;f=samples%2FMapScalabilityTests%2FMapScalabilityTests.cpp;h=839656ffbb8b704cfe051a7e8fdd178bf5a2dc98;hp=6cf2e05cbbb8204c6a7ae8376b7599bc29498d0f;hb=39e02b325f8e3104b71b2fce9cc6c7a19f8dc639;hpb=e8712e58dc2b7a0e9df8c5779572be3f8c71ff8d diff --git a/samples/MapScalabilityTests/MapScalabilityTests.cpp b/samples/MapScalabilityTests/MapScalabilityTests.cpp index 6cf2e05..839656f 100644 --- a/samples/MapScalabilityTests/MapScalabilityTests.cpp +++ b/samples/MapScalabilityTests/MapScalabilityTests.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace turf::intTypes; typedef junction::extra::MapAdapter MapAdapter; @@ -40,7 +41,8 @@ struct SharedState { turf::Atomic doneFlag; SharedState(MapAdapter& adapter, ureg numKeysPerThread, ureg readsPerWrite, ureg itersPerChunk) - : adapter(adapter), map(NULL), numKeysPerThread(numKeysPerThread), readsPerWrite(readsPerWrite), itersPerChunk(itersPerChunk) { + : adapter(adapter), map(NULL), numKeysPerThread(numKeysPerThread), readsPerWrite(readsPerWrite), + itersPerChunk(itersPerChunk) { doneFlag.storeNonatomic(0); numThreads = 0; } @@ -48,7 +50,7 @@ struct SharedState { class ThreadState { public: - SharedState& m_shared; + SharedState* m_shared; MapAdapter::ThreadContext m_threadCtx; ureg m_threadIndex; u32 m_rangeLo; @@ -79,7 +81,8 @@ public: Stats m_stats; - ThreadState(SharedState& shared, ureg threadIndex, u32 rangeLo, u32 rangeHi) : m_shared(shared), m_threadCtx(shared.adapter, threadIndex) { + ThreadState(SharedState* shared, ureg threadIndex, u32 rangeLo, u32 rangeHi) + : m_shared(shared), m_threadCtx(shared->adapter, threadIndex) { m_threadIndex = threadIndex; m_rangeLo = rangeLo; m_rangeHi = rangeHi; @@ -97,38 +100,38 @@ public: void initialPopulate() { TURF_ASSERT(m_addIndex == m_removeIndex); - MapAdapter::Map *map = m_shared.map; - for (ureg i = 0; i < m_shared.numKeysPerThread; i++) { + MapAdapter::Map* map = m_shared->map; + for (ureg i = 0; i < m_shared->numKeysPerThread; i++) { u32 key = m_addIndex * Prime; if (key >= 2) - map->insert(key, (void*) uptr(key)); + map->assign(key, (void*) uptr(key)); if (++m_addIndex == m_rangeHi) m_addIndex = m_rangeLo; } } void run() { - MapAdapter::Map *map = m_shared.map; + MapAdapter::Map* map = m_shared->map; turf::CPUTimer::Converter converter; Stats stats; ureg lookupIndex = m_rangeLo; - ureg remaining = m_shared.itersPerChunk; + ureg remaining = m_shared->itersPerChunk; if (m_threadIndex == 0) - m_shared.spinKicker.kick(m_shared.numThreads - 1); + m_shared->spinKicker.kick(m_shared->numThreads - 1); else { remaining = ~u32(0); - m_shared.spinKicker.waitForKick(); + m_shared->spinKicker.waitForKick(); } // --------- turf::CPUTimer::Point start = turf::CPUTimer::get(); for (; remaining > 0; remaining--) { // Add - if (m_shared.doneFlag.load(turf::Relaxed)) + if (m_shared->doneFlag.load(turf::Relaxed)) break; u32 key = m_addIndex * Prime; if (key >= 2) { - map->insert(key, (void*) uptr(key)); + map->assign(key, (void*) uptr(key)); stats.mapOpsDone++; } if (++m_addIndex == m_rangeHi) @@ -137,8 +140,8 @@ public: // Lookup if (s32(lookupIndex - m_removeIndex) < 0) lookupIndex = m_removeIndex; - for (ureg l = 0; l < m_shared.readsPerWrite; l++) { - if (m_shared.doneFlag.load(turf::Relaxed)) + for (ureg l = 0; l < m_shared->readsPerWrite; l++) { + if (m_shared->doneFlag.load(turf::Relaxed)) break; key = lookupIndex * Prime; if (key >= 2) { @@ -153,7 +156,7 @@ public: } // Remove - if (m_shared.doneFlag.load(turf::Relaxed)) + if (m_shared->doneFlag.load(turf::Relaxed)) break; key = m_removeIndex * Prime; if (key >= 2) { @@ -166,8 +169,8 @@ public: // Lookup if (s32(lookupIndex - m_removeIndex) < 0) lookupIndex = m_removeIndex; - for (ureg l = 0; l < m_shared.readsPerWrite; l++) { - if (m_shared.doneFlag.load(turf::Relaxed)) + for (ureg l = 0; l < m_shared->readsPerWrite; l++) { + if (m_shared->doneFlag.load(turf::Relaxed)) break; key = lookupIndex * Prime; if (key >= 2) { @@ -182,7 +185,7 @@ public: } } if (m_threadIndex == 0) - m_shared.doneFlag.store(1, turf::Relaxed); + m_shared->doneFlag.store(1, turf::Relaxed); m_threadCtx.update(); turf::CPUTimer::Point end = turf::CPUTimer::get(); // --------- @@ -193,16 +196,16 @@ public: }; static const turf::extra::Option Options[] = { - { "readsPerWrite", 'r', true, "number of reads per write" }, - { "itersPerChunk", 'i', true, "number of iterations per chunk" }, - { "chunks", 'c', true, "number of chunks to execute" }, - { "keepChunkFraction", 'k', true, "threshold fraction of chunk timings to keep" }, + {"readsPerWrite", 'r', true, "number of reads per write"}, + {"itersPerChunk", 'i', true, "number of iterations per chunk"}, + {"chunks", 'c', true, "number of chunks to execute"}, + {"keepChunkFraction", 'k', true, "threshold fraction of chunk timings to keep"}, }; int main(int argc, const char** argv) { turf::extra::Options options(Options, TURF_STATIC_ARRAY_SIZE(Options)); options.parse(argc, argv); - ureg readsPerWrite = options.getInteger("readsPerWrite", DefaultReadsPerWrite); + ureg readsPerWrite = options.getInteger("readsPerWrite", DefaultReadsPerWrite); ureg itersPerChunk = options.getInteger("itersPerChunk", DefaultItersPerChunk); ureg chunks = options.getInteger("chunks", DefaultChunks); double keepChunkFraction = options.getDouble("keepChunkFraction", 1.0); @@ -219,7 +222,7 @@ int main(int argc, const char** argv) { for (ureg t = 0; t < numCores; t++) { u32 rangeLo = 0xffffffffu / numCores * t + 1; u32 rangeHi = 0xffffffffu / numCores * (t + 1) + 1; - threads.emplace_back(shared, t, rangeLo, rangeHi); + threads.push_back(ThreadState(&shared, t, rangeLo, rangeHi)); } dispatcher.kickOne(0, &ThreadState::registerThread, threads[0]); @@ -232,14 +235,13 @@ int main(int argc, const char** argv) { } printf("{\n"); - printf("'mapType': '%s',\n", MapAdapter::MapName); + printf("'mapType': '%s',\n", MapAdapter::getMapName()); printf("'population': %d,\n", (int) (numCores * NumKeysPerThread)); printf("'readsPerWrite': %d,\n", (int) readsPerWrite); printf("'itersPerChunk': %d,\n", (int) itersPerChunk); printf("'chunks': %d,\n", (int) chunks); printf("'keepChunkFraction': %f,\n", keepChunkFraction); - printf("'labels': ('numThreads', 'mapOpsDone', 'totalTime'),\n"), - printf("'points': [\n"); + printf("'labels': ('numThreads', 'mapOpsDone', 'totalTime'),\n"), printf("'points': [\n"); for (shared.numThreads = 1; shared.numThreads <= numCores; shared.numThreads++) { if (shared.numThreads > 1) { // Spawn and register a new thread @@ -263,10 +265,7 @@ int main(int argc, const char** argv) { totals += kickTotals[t]; } - printf(" (%d, %d, %f),\n", - int(shared.numThreads), - int(totals.mapOpsDone), - totals.duration); + printf(" (%d, %d, %f),\n", int(shared.numThreads), int(totals.mapOpsDone), totals.duration); } printf("],\n"); printf("}\n");