[libmath-prime-util-perl] 01/35: fix some prime count performance and openmp cases

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:50:01 UTC 2015


This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.33
in repository libmath-prime-util-perl.

commit 3af56a3da45f9ddfaea985b8774d995781a26d8f
Author: Dana Jacobsen <dana at acm.org>
Date:   Wed Oct 16 17:09:46 2013 -0700

    fix some prime count performance and openmp cases
---
 cpanfile |  4 ++--
 lehmer.c | 24 +++++++++++++-----------
 util.c   |  2 +-
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/cpanfile b/cpanfile
index 3d6e3de..b7b32d9 100644
--- a/cpanfile
+++ b/cpanfile
@@ -12,13 +12,13 @@ requires 'Math::BigFloat', '1.59';
 
 requires 'Bytes::Random::Secure', '0.23';
 
-recommends 'Math::Prime::Util::GMP', '0.13';
+recommends 'Math::Prime::Util::GMP', '0.15';
 recommends 'Math::BigInt::GMP';
 recommends 'Math::MPFR', '2.03';
 
 
 on test => sub {
   requires 'Test::More', '0.45';
-  requires 'Test::Warn';
   requires 'bignum', '0.22';
+  recommends 'Test::Warn';
 };
diff --git a/lehmer.c b/lehmer.c
index 89b5290..4e43f6e 100644
--- a/lehmer.c
+++ b/lehmer.c
@@ -3,7 +3,7 @@
 #include <string.h>
 #include <math.h>
 
-/* Below this size, just sieve. */
+/* Below this size, just sieve (with table speedup). */
 #define SIEVE_LIMIT  60000000
 #define MAX_PHI_MEM  (256*1024*1024)
 
@@ -368,7 +368,7 @@ static uint32_t mapes7_32(uint32_t x) {
 
 /* Max memory = 2*A*X bytes, e.g. 2*400*24000 = 18.3 MB */
 #define PHICACHEA 400
-#define PHICACHEX 24000
+#define PHICACHEX 32768
 typedef struct
 {
   uint32_t max[PHICACHEA];
@@ -410,6 +410,8 @@ static void phi_cache_insert(UV x, UV a, IV sum, cache_t* cache) {
     }
     if (sum < SHRT_MIN || sum > SHRT_MAX)
       croak("phi(%lu,%lu) 16-bit overflow: sum = %ld\n", x, a, sum);
+    if (cache->val[a] == 0)
+      croak("phi cache allocation failure");
     cache->val[a][x] = sum;
   }
 }
@@ -670,7 +672,7 @@ static UV phi(UV x, UV a)
       arr = a1.a;
       if (verbose > 0) printf("clipping small values at a=%lu a1.n=%lu \n", a, a1.n);
 #ifdef _OPENMP
-      #pragma omp parallel for reduction(+: sum) firstprivate(pcache) schedule(dynamic, 16)
+      /* #pragma omp parallel for reduction(+: sum) firstprivate(pcache) schedule(dynamic, 16) */
 #endif
       for (i = 0; i < a1.n-NTHRESH+NTHRESH/50; i++) {
         UV j = a1.n - 1 - i;
@@ -883,19 +885,19 @@ UV _XS_LMO_pi(UV n)
   phicache_init(&pcache);
   TIMING_START;
   for (i = 1; i <= n13; i++)
-    if (lpf[i] > primes[k])
+    if (lpf[i] > primes[k] && mu[i] != 0)
       /* S1 += mu[i] * phi_small(n/i, k, primes, lastprime, &pcache); */
       S1 += mu[i] * phi(n/i, k);
   TIMING_END_PRINT("S1")
 
   TIMING_START;
-  for (i = k; i+1 < a; i++)
-#ifdef _OPENMP
-    #pragma omp parallel for reduction(+: S2) firstprivate(pcache) schedule(dynamic, 16) num_threads(2)
-#endif
-    for (j = (n13/primes[i+1])+1; j <= n13; j++)
-      if (lpf[j] > primes[i+1])
-        S2 += -mu[j] * phi_small(n / (j*primes[i+1]), i, primes, lastprime, &pcache);
+  for (i = k; i+1 < a; i++) {
+    UV p = primes[i+1];
+    /* TODO: #pragma omp parallel for reduction(+: S2) firstprivate(pcache) schedule(dynamic, 16) */
+    for (j = (n13/p)+1; j <= n13; j++)
+      if (lpf[j] > p && mu[j] != 0)
+        S2 += -mu[j] * phi_small(n / (j*p), i, primes, lastprime, &pcache);
+  }
   TIMING_END_PRINT("S2")
   phicache_free(&pcache);
   Safefree(lpf);
diff --git a/util.c b/util.c
index c642b26..49c1cb5 100644
--- a/util.c
+++ b/util.c
@@ -493,7 +493,7 @@ UV _XS_prime_count(UV low, UV high)
         count += step_counts_30k[i++];
       }
       low = i * 30000;
-    } else if (high < (NSTEP_COUNTS_300K+1) * UVCONST(300000)) {
+    } else if (high < (10+NSTEP_COUNTS_300K+1) * UVCONST(300000)) {
       count = 216816;
       while (i < NSTEP_COUNTS_300K && high >= (i+11) * UVCONST(300000)) {
         count += step_counts_300k[i++];

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git



More information about the Pkg-perl-cvs-commits mailing list