[Assorted-commits] SF.net SVN: assorted: [398] numa-bench/trunk/src/malloc.cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-13 03:26:39
|
Revision: 398 http://assorted.svn.sourceforge.net/assorted/?rev=398&view=rev Author: yangzhang Date: 2008-02-12 19:26:37 -0800 (Tue, 12 Feb 2008) Log Message: ----------- calling rand() in seq to make the test more fair; writing by ints not chars; added some notes Modified Paths: -------------- numa-bench/trunk/src/malloc.cc Modified: numa-bench/trunk/src/malloc.cc =================================================================== --- numa-bench/trunk/src/malloc.cc 2008-02-12 22:15:13 UTC (rev 397) +++ numa-bench/trunk/src/malloc.cc 2008-02-13 03:26:37 UTC (rev 398) @@ -11,6 +11,8 @@ // - Huge difference. Also magnifies the locality effects more. // - 1700 from local, 1990 from one neighbor, 2020 from another neighbor, // and 2310 from remote. +// - What's the difference between reading and writing? +// - TODO! // - Can we observe prefetching's effects? (Random access but chew the full // cache line of data.) // - TODO! @@ -42,9 +44,10 @@ * shuffle the indexes we chew through. */ void* -chew(void* pp, int core, size_t size, int nreps, bool shuffle) +chew(void* pp, unsigned int core, size_t size, unsigned int nreps, bool shuffle) { - char* p = (char*) pp; + int* p = (int*) pp; + const size_t count = size / sizeof(int); pid_t pid = gettid(); timer t(": "); @@ -56,15 +59,18 @@ // Write sequentially to the memory region. if (shuffle) { - for (int c = 0; c < nreps; c++) { - for (size_t i = 0; i < size; i++) { - p[rand() % size] = i; + for (unsigned int c = 0; c < nreps; c++) { + for (size_t i = 0; i < count; i++) { + // NOTE: Using r as the index assumes that rand generates large-enough + // values. + int r = rand(); + p[r % count] += r; } } } else { - for (int c = 0; c < nreps; c++) { - for (size_t i = 0; i < size; i++) { - p[i] = i; + for (unsigned int c = 0; c < nreps; c++) { + for (size_t i = 0; i < count; i++) { + p[i] += rand(); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |