Skip to content

Commit

Permalink
Merge pull request #7 from lorenzhs/fix-exponential-option
Browse files Browse the repository at this point in the history
Fix exponential threads option
  • Loading branch information
bingmann authored Sep 4, 2018
2 parents fc71268 + a3e1e0f commit 39fb1da
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions pmbw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ uint64_t gopt_memlimit = 0;
// lower and upper limit to number of threads
int gopt_nthreads_min = 0, gopt_nthreads_max = 0;

// quadraticly increasing number of threads
bool gopt_nthreads_quadratic = false;
// exponentially increasing number of threads
bool gopt_nthreads_exponential = false;

// option to test permutation cycle before measurement
bool gopt_testcycle = false;
Expand Down Expand Up @@ -665,6 +665,8 @@ void testfunc(const TestFunction* func)
if (gopt_nthreads_max == 0)
gopt_nthreads_max = g_physical_cpus + 2;

bool exp_have_physical = false;

while (1)
{
// globally set test function and thread number
Expand All @@ -687,11 +689,25 @@ void testfunc(const TestFunction* func)
// increase thread count
if (nthreads >= gopt_nthreads_max) break;

if (gopt_nthreads_quadratic)
if (gopt_nthreads_exponential)
nthreads = 2 * nthreads;
else
nthreads++;

// Prevent the next check from running the tests with g_physical_cpus
// twice if that is a power of two
if (gopt_nthreads_exponential && nthreads == g_physical_cpus)
exp_have_physical = true;

if (gopt_nthreads_exponential && nthreads > g_physical_cpus &&
!exp_have_physical) {
// Halve it because we want both with and without hyperthreading.
// The next iteration will then have nthreads == g_physical_cpus,
// and the one after that will be the last with gopt_nthreads_max.
nthreads = g_physical_cpus / 2;
exp_have_physical = true;
}

if (nthreads > gopt_nthreads_max)
nthreads = gopt_nthreads_max;
}
Expand All @@ -716,7 +732,7 @@ void print_usage(const char* prog)
<< " -o <file> Write the results to <file> instead of stats.txt." << std::endl
<< " -p <nthrs> Run benchmarks with at least this thread count." << std::endl
<< " -P <nthrs> Run benchmarks with at most this thread count (overrides detected processor count)." << std::endl
<< " -Q Run benchmarks with quadratically increasing thread count." << std::endl
<< " -Q Run benchmarks with exponentially increasing thread count." << std::endl
<< " -s <size> Limit the _minimum_ test array size [byte]. Set to 0 for no limit." << std::endl
<< " -S <size> Limit the _maximum_ test array size [byte]. Set to 0 for no limit." << std::endl
);
Expand Down Expand Up @@ -777,8 +793,8 @@ int main(int argc, char* argv[])
break;

case 'Q':
ERR("Running benchmarks with quadratically increasing thread counts.");
gopt_nthreads_quadratic = true;
ERR("Running benchmarks with exponentially increasing thread counts.");
gopt_nthreads_exponential = true;
break;

case 'p':
Expand Down

0 comments on commit 39fb1da

Please sign in to comment.