From f620188536991e9cd4b65d9379aca7bc5cd82a71 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 20 Apr 2019 18:44:52 +0200 Subject: More parametric C++ code (no real performance regression) --- aberth/aberth.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'aberth') diff --git a/aberth/aberth.cpp b/aberth/aberth.cpp index 13883f7..3b3c11e 100644 --- a/aberth/aberth.cpp +++ b/aberth/aberth.cpp @@ -243,13 +243,9 @@ static vector derbyshireJobs(int targetJobs) { return jobs; } -static tuple> computeCounts() { - constexpr const int W = 900; - constexpr const int H = 900; +static vector computeCounts(int W, int H, Com bottomLeft, Com topRight) { constexpr const int numThreads = 4; static_assert(ispow2(numThreads)); - constexpr const Com bottomLeft = Com(-1.5, -1.5); - constexpr const Com topRight = Com(1.5, 1.5); vector counts(W * H); mutex countsMutex; @@ -259,11 +255,11 @@ static tuple> computeCounts() { vector threads(jobs.size()); for (int i = 0; i < (int)jobs.size(); i++) { - threads[i] = thread([&counts, &countsMutex, job = jobs[i], bottomLeft, topRight]() { + threads[i] = thread([W, H, &counts, &countsMutex, job = jobs[i], bottomLeft, topRight]() { auto calcIndex = [](double value, double left, double right, int steps) -> int { return (value - left) / (right - left) * (steps - 1) + 0.5; }; - auto calcPos = [bottomLeft, topRight, &calcIndex](Com z) -> pair { + auto calcPos = [W, H, bottomLeft, topRight, &calcIndex](Com z) -> pair { return make_pair( calcIndex(z.real(), bottomLeft.real(), topRight.real(), W), calcIndex(z.imag(), bottomLeft.imag(), topRight.imag(), H) @@ -291,7 +287,7 @@ static tuple> computeCounts() { for (thread &th : threads) th.join(); - return make_tuple(W, H, counts); + return counts; } static void writeCounts(int W, int H, const vector &counts, const char *fname) { @@ -461,11 +457,14 @@ int main(int argc, char **argv) { vector counts; if (argc <= 1) { - // tie(W, H, counts) = computeCounts(); - W = H = 2000; - Com bottomLeft = Com(0, -1.6); - Com topRight = Com(1.6, 0); - Kernel().run_chunked(counts, W, H, bottomLeft, topRight, 42, 1 << 14); + W = H = 900; + const Com bottomLeft = Com(-1.5, -1.5); + const Com topRight = Com(1.5, 1.5); + + counts = computeCounts(W, H, bottomLeft, topRight); + // Kernel().run_chunked(counts, W, H, bottomLeft, topRight, 42, 1 << 14); + // Kernel().run_all(counts, W, H, bottomLeft, topRight, 42); + writeCounts(W, H, counts, "out.txt"); } else if (argc == 2) { tie(W, H, counts) = readCounts(argv[1]); -- cgit v1.2.3-70-g09d2