236 if (n >= 17878103347812890625ul) {
240 nat_type root = (
nat_type)floor(native_sqrt(native_sqrt(native_sqrt((
float)n))));
257 if (n >= 18446744065119617025ul) {
264 while (
square(sqrt_n) <= n) {
269 }
while (
square(sqrt_n) > n);
293 while (begin != end) {
294 __global
const nat_type* mid = begin + (end - begin)/2;
304 const bool b_right = !(n < *mid);
306 begin = (__global
const nat_type*)select((intptr_t)begin, (intptr_t)(mid + 1), b_right);
307 end = (__global
const nat_type*)select((intptr_t)mid, (intptr_t)end, b_right);
311 return (*begin == n);
326 __global
const prime_type* prime_ptr = primes - 1;
329 while ((prime = *(++prime_ptr)) <= sqrt_n_divided) {
330 unsigned int alpha = 0;
332 while ((n_divided % prime) == 0) {
355 return (varsigma_odd < n);
365 __global
const prime_type* prime_ptr = primes;
369 unsigned int nb_prime_divisor = 0;
374 const bool is_factor = ((n_divided % prime) == 0);
377 prime_divisors[nb_prime_divisor++] = prime;
380 prime = *(++prime_ptr);
381 not_finished = (prime <= sqrt_n);
382 }
while (not_finished);
385 for (
unsigned int i = 0; i < nb_prime_divisor; ++i) {
386 const nat_type prime = prime_divisors[i];
393 is_factor = ((n_divided % prime) == 0);
396 sigma_odd *= (pow_prime - 1)/(prime - 1) + pow_prime;
411 __global
const prime_type* prime_ptr = primes;
417 bool is_factor = ((n_divided % prime) == 0);
422 is_factor = ((n_divided % prime) == 0);
427 prime = *(++prime_ptr);
428 not_finished = (prime <= sqrt_n);
429 }
while (not_finished);
434 return (varsigma_odd < n);
469 return (rk - 1)/(r - 1) + rk;
486 bool is_lower = (
square(sqrt_n) < n);
489 is_lower = (
square(++sqrt_n) < n);
501 __global
const prime_type* prime_ptr = primes - 1;
504 while ((prime = *(++prime_ptr)) <= sqrt_n_divided) {
505 unsigned int alpha = 0;
507 while ((n_divided % prime) == 0) {
531 #ifndef ONLY_MAIN_KERNEL 535 __global
const nat_type* ns,
unsigned int nb,
536 __global
unsigned char* results) {
537 const unsigned int i = get_global_id(0);
550 __global
const nat_type* ns,
unsigned int nb,
551 __global
unsigned char* results) {
552 const unsigned int i = get_global_id(0);
560 #ifndef ONLY_MAIN_KERNEL 564 __global
const nat_type* ns,
unsigned int nb,
565 __global
unsigned char* results) {
566 const unsigned int i = get_global_id(0);
579 unsigned int prime_offset,
unsigned int opencl_nb,
582 const unsigned int i = get_global_id(0);
583 const prime_type prime = primes[prime_offset + i];
604 const bool is_not_receiver =
is_odd(i);
606 if (is_not_receiver) {
613 const unsigned int j = i + 1;
615 barrier(CLK_LOCAL_MEM_FENCE);
617 factors[i] *= factors[j];
618 factors[j] = (((n - 1)/(prime - 1) + n)
619 * ((factors[j] - 1)/(primes[prime_offset + j] - 1) + factors[j]));
623 unsigned int power2 = 2;
625 while (power2 < opencl_nb) {
626 const unsigned int double_power2 = power2 << 1;
629 const bool is_not_receiver = ((i & (double_power2 - 1)) != 0);
631 if (is_not_receiver) {
636 const unsigned int j = i + power2;
638 barrier(CLK_LOCAL_MEM_FENCE);
640 factors[i] *= factors[j];
641 factors[i + 1] *= factors[j + 1];
643 power2 = double_power2;
652 #ifndef ONLY_MAIN_KERNEL 660 const unsigned int i = get_global_id(0);
670 const unsigned int i = get_global_id(0);
680 const unsigned int i = get_global_id(0);
682 results[i] =
pow_nat(ns[i], i % 5);
690 const unsigned int i = get_global_id(0);
700 const unsigned int i = get_global_id(0);
__kernel void check_ns__optimized(__global const prime_type *primes, __global const nat_type *ns, unsigned int nb, __global unsigned char *results)
unsigned long nat_type
Type for natural number used in all code, on 64 bits.
nat_type pow_nat(nat_type n, unsigned int k)
Return x^k, x power k.
nat_type upper_square_root(nat_type n)
Return an approximation of the square root of n. The results is always >= the exact square root...
bool is_varsigma_odd_lower(__global const prime_type *primes, nat_type n)
Return true iff varsigma_odd(n) < n.
nat_type floor_square_root(nat_type n)
Return the square root of n rounded to below.
bool is_odd(nat_type n)
Return true iff n is odd.
__kernel void test__pow_nat(__global const prime_type *primes, __global const nat_type *ns, __global nat_type *results)
nat_type ceil_eighth_root(nat_type n)
Return the eighth root of n rounded to above.
bool is_varsigma_odd_lower__simplified(__global const prime_type *primes, nat_type n)
Simplified version of is_varsigma_odd_lower().
bool is_even(nat_type n)
Return true iff n is even.
__kernel void test__sum_geometric_progression_strict(__global const prime_type *primes, __global const nat_type *ns, __global nat_type *results)
nat_type sum_geometric_progression_strict(nat_type r, unsigned int k)
Return the sum of the (k + 1) terms of the geometric progression of the common ratio r...
bool is_in_table(__global const nat_type *begin, __global const nat_type *end, const nat_type n)
Return true iff n is in the table.
__kernel void test__divide_until_odd(__global const prime_type *primes, __global const nat_type *ns, __global nat_type *results)
__kernel void compute_partial_sigma_odd(__global const prime_type *primes, unsigned int prime_offset, unsigned int opencl_nb, nat_type n, __global nat_type *factors)
__kernel void test__floor_square_root(__global const prime_type *primes, __global const nat_type *ns, __global nat_type *results)
unsigned int prime_type
Type for prime number, particularly for the table of primes.
nat_type floor_eighth_root(nat_type n)
Return the eighth root of n rounded to below.
__kernel void test__varsigma_odd(__global const prime_type *primes, __global const nat_type *ns, __global nat_type *results)
__kernel void check_ns__simplified(__global const prime_type *primes, __global const nat_type *ns, unsigned int nb, __global unsigned char *results)
bool is_varsigma_odd_lower__optimized(__global const prime_type *primes, nat_type n)
Version of is_varsigma_odd_lower() rewritten to OpenCL.
nat_type sigma_odd_upper_bound(nat_type n)
Return an upper bound of sigma_odd(n).
nat_type square(nat_type n)
Return n*n.
bool is_divide(nat_type d, nat_type n)
Return true iff d divide n, i.e. if n is divisible by d.
nat_type divide_until_odd(nat_type n)
Return n divided by 2 until the result is odd.
__kernel void check_ns(__global const prime_type *primes, __global const nat_type *ns, unsigned int nb, __global unsigned char *results)
nat_type varsigma_odd(__global const prime_type *primes, nat_type n)
Return varsigma_odd(n), i.e. the sum of all odd divisors of n, divided by 2 until to be odd...