Ver código fonte

small improvements

Nicolas Winkler 5 anos atrás
pai
commit
03111c3e8c

+ 2 - 2
MandelWidget.cpp

@@ -235,11 +235,11 @@ void Job::run(void)
 
 
 Calcer::Calcer(mnd::Generator* generator, MandelWidget& owner, int maxIter, bool smooth) :
-    generator{ generator },
     jobsMutex{ QMutex::Recursive },
+    generator{ generator },
     owner{ owner },
-    gradient{ owner.getGradient() },
     threadPool{ std::make_unique<QThreadPool>() },
+    gradient{ owner.getGradient() },
     maxIter{ maxIter },
     smooth{ smooth }
 {

+ 2 - 6
libmandel/include/Types.h

@@ -17,10 +17,8 @@
 #   include <boost/functional/hash.hpp>
 #endif
 
-#ifdef WITH_QD
-#   include <qd/dd_real.h>
-#   include <qd/qd_real.h>
-#endif
+#include <qd/dd_real.h>
+#include <qd/qd_real.h>
 
 namespace mnd
 {
@@ -62,7 +60,6 @@ namespace mnd
 #endif
 
 
-#ifdef WITH_QD
     using DoubleDouble = dd_real;
     using QuadDouble = qd_real;
 
@@ -78,7 +75,6 @@ namespace mnd
     inline QuadDouble log(const QuadDouble& x) { return ::log(x); }
     inline QuadDouble log2(const QuadDouble& x) { return ::log(x) / ::log(QuadDouble(2.0)); }
     inline QuadDouble pow(const QuadDouble& x, const QuadDouble& y) { return ::pow(x, y); }
-#endif
 
     inline double abs(double x) { return ::abs(x); }
     inline float abs(float x) { return ::abs(x); }

+ 2 - 2
libmandel/src/ClGenerators.cpp

@@ -152,7 +152,7 @@ std::string ClGeneratorFloat::getKernelCode(bool smooth) const
         "       float ab = a * b;"
         "       if (aa + bb > 16) break;"
         "       a = aa - bb + ca;"
-        "       b = 2 * ab + cb;"
+        "       b = ab + ab + cb;"
         "       n++;"
         "   }\n"
         "   if (n >= max - 1)\n"
@@ -229,7 +229,7 @@ std::string ClGeneratorDouble::getKernelCode(bool smooth) const
         "       double ab = a * b;"
         "       if (aa + bb > 16) break;"
         "       a = aa - bb + ca;"
-        "       b = 2 * ab + cb;"
+        "       b = ab + ab + cb;"
         "       n++;"
         "   }\n"
         // N + 1 - log (log  |Z(N)|) / log 2

+ 1 - 1
libmandel/src/CpuGenerators.cpp

@@ -61,7 +61,7 @@ void CpuGenerator<T, mnd::NONE, parallel>::generate(const mnd::MandelInfo& info,
 
     if constexpr (parallel)
         omp_set_num_threads(omp_get_num_procs());
-#pragma omp parallel for if (parallel)
+#pragma omp parallel for schedule(static, 1) if (parallel)
     for (long j = 0; j < info.bHeight; j++) {
         T y = viewy + T(double(j)) * hpp;
         long i = 0;

+ 5 - 6
libmandel/src/CpuGeneratorsAVX.cpp

@@ -28,7 +28,7 @@ void CpuGenerator<float, mnd::X86_AVX, parallel>::generate(const mnd::MandelInfo
     const MandelViewport& view = info.view;
 
     if constexpr(parallel)
-    omp_set_num_threads(2 * omp_get_num_procs());
+        omp_set_num_threads(omp_get_num_procs());
 #pragma omp parallel for schedule(static, 1) if (parallel)
     for (long j = 0; j < info.bHeight; j++) {
         T y = T(view.y) + T(j) * T(view.height / info.bHeight);
@@ -109,7 +109,7 @@ void CpuGenerator<double, mnd::X86_AVX, parallel>::generate(const mnd::MandelInf
     const MandelViewport& view = info.view;
 
     if constexpr(parallel)
-        omp_set_num_threads(2 * omp_get_num_procs());
+        omp_set_num_threads(omp_get_num_procs());
 #pragma omp parallel for schedule(static, 1) if (parallel)
     for (long j = 0; j < info.bHeight; j++) {
         T y = T(view.y + T(j) * view.height / info.bHeight);
@@ -299,10 +299,9 @@ void CpuGenerator<mnd::DoubleDouble, mnd::X86_AVX, parallel>::generate(const mnd
     T wpp = mnd::convert<T>(view.width / info.bWidth);
     T hpp = mnd::convert<T>(view.height / info.bHeight);
 
-//    if constexpr(parallel)
-//        omp_set_num_threads(2 * omp_get_num_procs());
-//#pragma omp parallel for schedule(static, 1) if (parallel)
-
+    if constexpr(parallel)
+        omp_set_num_threads(omp_get_num_procs());
+#pragma omp parallel for schedule(static, 1) if (parallel)
     for (long j = 0; j < info.bHeight; j++) {
         T y = viewy + T(double(j)) * hpp;
         __m256d y0s = { y.x[0], y.x[0], y.x[0], y.x[0] };

+ 3 - 71
libmandel/src/CpuGeneratorsAVXFMA.cpp

@@ -129,10 +129,9 @@ void CpuGenerator<mnd::DoubleDouble, mnd::X86_AVX_FMA, parallel>::generate(const
     T wpp = mnd::convert<T>(view.width / info.bWidth);
     T hpp = mnd::convert<T>(view.height / info.bHeight);
 
-//    if constexpr(parallel)
-//        omp_set_num_threads(2 * omp_get_num_procs());
-//#pragma omp parallel for schedule(static, 1) if (parallel)
-
+    if constexpr(parallel)
+        omp_set_num_threads(omp_get_num_procs());
+#pragma omp parallel for schedule(static, 1) if (parallel)
     for (long j = 0; j < info.bHeight; j++) {
         T y = viewy + T(double(j)) * hpp;
         __m256d y0s = { y.x[0], y.x[0], y.x[0], y.x[0] };
@@ -207,72 +206,5 @@ void CpuGenerator<mnd::DoubleDouble, mnd::X86_AVX_FMA, parallel>::generate(const
             }
         }
     }
-    return;
-
-
-
-    for (long j = 0; j < info.bHeight; j++) {
-        T y = viewy + T(double(j)) * hpp;
-        __m256d y0s = { y.x[0], y.x[0], y.x[0], y.x[0] };
-        __m256d y1s = { y.x[1], y.x[1], y.x[1], y.x[1] };
-        AvxDoubleDouble ys{ y0s, y1s };
-        long i = 0;
-        for (i; i < info.bWidth; i += 4) {
-            T x1 = viewx + T(double(i)) * wpp;
-            T x2 = viewx + T(double(i + 1)) * wpp;
-            T x3 = viewx + T(double(i + 2)) * wpp;
-            T x4 = viewx + T(double(i + 3)) * wpp;
-
-            __m256d x0s = {
-                x1.x[0], x2.x[0], x3.x[0], x4.x[0],
-            };
-
-            __m256d x1s = {
-                x1.x[1], x2.x[1], x3.x[1], x4.x[1],
-            };
-
-            AvxDoubleDouble xs{ x0s, x1s };
-
-            int itRes[4] = { 0, 0, 0, 0 };
-
-            __m256d threshold = { 16.0, 16.0, 16.0, 16.0 };
-            __m256d counter = { 0, 0, 0, 0 };
-            __m256d adder = { 1, 1, 1, 1 };
-
-            AvxDoubleDouble a = xs;
-            AvxDoubleDouble b = ys;
-
-            for (int k = 0; k < info.maxIter; k++) {
-                AvxDoubleDouble aa = a * a;
-                AvxDoubleDouble bb = b * b;
-                AvxDoubleDouble abab = a * b; abab = abab + abab;
-                a = aa - bb + xs;
-                b = abab + ys;
-                __m256i cmp = _mm256_castpd_si256(_mm256_cmp_pd(_mm256_add_pd(aa.x[0], bb.x[0]), threshold, _CMP_LE_OQ));
-                /*if (info.smooth) {
-                    resultsa = _mm256_or_pd(_mm256_andnot_ps(cmp, resultsa), _mm256_and_ps(cmp, a));
-                    resultsb = _mm256_or_ps(_mm256_andnot_ps(cmp, resultsb), _mm256_and_ps(cmp, b));
-                }*/
-                adder = _mm256_and_pd(adder, _mm256_castsi256_pd(cmp));
-                counter = _mm256_add_pd(counter, adder);
-                if ((k & 7) == 0 && _mm256_testz_si256(cmp, cmp) != 0) {
-                    break;
-                }
-            }
-
-            auto alignVec = [](double* data) -> double* {
-                void* aligned = data;
-                ::size_t length = 64;
-                std::align(32, 4 * sizeof(double), aligned, length);
-                return static_cast<double*>(aligned);
-            };
-
-            double resData[8];
-            double* ftRes = alignVec(resData);
-            _mm256_store_pd(ftRes, counter);
-            for (int k = 0; k < 4 && i + k < info.bWidth; k++)
-                data[i + k + j * info.bWidth] = ftRes[k] > 0 ? float(ftRes[k]) : info.maxIter;
-        }
-    }
 }
 

+ 4 - 4
libmandel/src/CpuGeneratorsSSE2.cpp

@@ -23,8 +23,8 @@ void CpuGenerator<float, mnd::X86_SSE2, parallel>::generate(const mnd::MandelInf
     const MandelViewport& view = info.view;
 
     if constexpr(parallel)
-    omp_set_num_threads(2 * omp_get_num_procs());
-#pragma omp parallel for if (parallel)
+    omp_set_num_threads(omp_get_num_procs());
+#pragma omp parallel for schedule(static, 1) if (parallel)
     for (long j = 0; j < info.bHeight; j++) {
         T y = T(view.y) + T(j) * T(view.height / info.bHeight);
         long i = 0;
@@ -100,8 +100,8 @@ void CpuGenerator<double, mnd::X86_SSE2, parallel>::generate(const mnd::MandelIn
     using T = double;
     const MandelViewport& view = info.view;
     if constexpr(parallel)
-        omp_set_num_threads(2 * omp_get_num_procs());
-#pragma omp parallel for if (parallel)
+        omp_set_num_threads(omp_get_num_procs());
+#pragma omp parallel for schedule(static, 1) if (parallel)
     for (long j = 0; j < info.bHeight; j++) {
         T y = T(view.y) + T(j) * T(view.height / info.bHeight);
         long i = 0;

+ 2 - 2
libmandel/src/Generators.cpp

@@ -81,8 +81,8 @@ namespace mnd
     Real getPrecision(Precision p)
     {
         static const std::map<Precision, Real> precs {
-            { Precision::FLOAT, 1.0e-7 },
-            { Precision::DOUBLE, 1.0e-15 },
+            { Precision::FLOAT, Real("1.0e-7") },
+            { Precision::DOUBLE, Real("1.0e-15") },
             { Precision::DOUBLE_DOUBLE, Real("1.0e-29") },
             { Precision::QUAD_DOUBLE, Real("1.0e-56") },
             { Precision::FLOAT256, Real("1.0e-58") },

+ 0 - 2
libmandel/src/Mandel.cpp

@@ -140,12 +140,10 @@ MandelContext::MandelContext(void)
     cpuGenerators.insert({ GeneratorType::FLOAT256, std::move(oct) });
 #endif // WITH_BOOST
 
-#ifdef WITH_QD
     auto dd = std::make_unique<CpuGenerator<DoubleDouble, mnd::NONE, true>>();
     auto qd = std::make_unique<CpuGenerator<QuadDouble, mnd::NONE, true>>();
     cpuGenerators.insert({ GeneratorType::DOUBLE_DOUBLE, std::move(dd) });
     cpuGenerators.insert({ GeneratorType::QUAD_DOUBLE, std::move(qd) });
-#endif // WITH_QD
 
     auto fix512 = std::make_unique<CpuGenerator<Fixed512, mnd::NONE, true>>();
     cpuGenerators.insert({ GeneratorType::FIXED512, std::move(fix512) });