Skip to content

Commit

Permalink
cutoffs based on num_available_threads instead of num_threads
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-johansson committed Jun 26, 2022
1 parent 40c3f15 commit a3e9bac
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion acb_dirichlet/euler_product_real_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void _acb_dirichlet_euler_product_real_ui(arb_t res, ulong s,
which gives prec ^ 1.2956 here. */
limit = 100 + prec * sqrt(prec);

num_threads = flint_get_num_threads();
num_threads = arb_flint_get_num_available_threads();

if (num_threads > 1 && prec > 5000 && s > 5000)
{
Expand Down
2 changes: 1 addition & 1 deletion arb/atan_arf_bb.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ arb_atan_arf_bb(arb_t z, const arf_t x, slong prec)

/* s = 0, t = x */

if (flint_get_num_threads() == 1 || prec >= 1000000000)
if (arb_flint_get_num_available_threads() == 1 || prec >= 1000000000)
{
for (iter = 0, bits = start_bits; !fmpz_is_zero(t);
iter++, bits *= 2)
Expand Down
2 changes: 1 addition & 1 deletion arb/atan_sum_bs_powtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ _arb_atan_sum_bs_powtab(fmpz_t T, fmpz_t Q, flint_bitcnt_t * Qexp,
}
}

if (flint_get_num_threads() == 1)
if (arb_flint_get_num_available_threads() == 1)
bsplit(T, Q, Qexp, xexp, xpow, r, 0, N);
else
bsplit2(T, Q, Qexp, xexp, xpow, r, 0, N);
Expand Down
2 changes: 1 addition & 1 deletion arb/exp_arf.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ arb_exp_arf_generic(arb_t z, const arf_t x, slong prec, int minus_one)
{
want_rs = 0;
}
else if (flint_get_num_threads() == 1) /* todo: get_available_threads */
else if (arb_flint_get_num_available_threads() == 1)
{
want_rs = (prec < 20000) || (prec < 1000000000 && mag < -prec / 800);
}
Expand Down
2 changes: 1 addition & 1 deletion arb/exp_arf_bb.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ arb_exp_arf_bb(arb_t z, const arf_t x, slong prec, int minus_one)
/* Start with z = 1. */
arb_one(z);

num_threads = flint_get_num_threads();
num_threads = arb_flint_get_num_available_threads();

/* We have two ways to parallelize the BB algorithm: run
the main loop serially and rely on parallel binary splitting,
Expand Down
2 changes: 1 addition & 1 deletion arb/exp_sum_bs_powtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ _arb_exp_sum_bs_powtab(fmpz_t T, fmpz_t Q, flint_bitcnt_t * Qexp,
}
}

if (flint_get_num_threads() == 1)
if (arb_flint_get_num_available_threads() == 1)
bsplit(T, Q, Qexp, xexp, xpow, r, 0, N);
else
bsplit2(T, Q, Qexp, xexp, xpow, r, 0, N);
Expand Down
4 changes: 2 additions & 2 deletions arb/sin_cos_arf_bb.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ _arb_sin_sum_bs_powtab(fmpz_t T, fmpz_t Q, flint_bitcnt_t * Qexp,
}
}

if (flint_get_num_threads() == 1)
if (arb_flint_get_num_available_threads() == 1)
bsplit(T, Q, Qexp, xexp, xpow, r, 0, N);
else
bsplit2(T, Q, Qexp, xexp, xpow, r, 0, N);
Expand Down Expand Up @@ -480,7 +480,7 @@ arb_sin_cos_arf_bb(arb_t zsin, arb_t zcos, const arf_t x, slong prec)
or compute all the sines/cosines in parallel. The latter is
more efficient (empirically about 1.7x) but uses more memory,
so we fall back on a serial main loop at high enough precision. */
if (flint_get_num_threads() == 1 || prec >= 4e8)
if (arb_flint_get_num_available_threads() == 1 || prec >= 4e8)
{
/* Bit-burst loop. */
for (iter = 0, bits = start_bits; !fmpz_is_zero(t); iter++, bits *= 3)
Expand Down
2 changes: 1 addition & 1 deletion arb/sin_cos_arf_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ arb_sin_cos_arf_generic(arb_t res_sin, arb_t res_cos, const arf_t x, slong prec)
{
want_rs = 0;
}
else if (flint_get_num_threads() == 1) /* todo: get_available_threads */
else if (arb_flint_get_num_available_threads() == 1)
{
want_rs = (prec < 200000) || (prec < 1000000000 && mag < -prec / 5000);
}
Expand Down
3 changes: 3 additions & 0 deletions fmpz_extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ extern "C" {
/* currently defined in the arb module, but global to the library */
double arb_test_multiplier(void);

/* should be in flint */
slong arb_flint_get_num_available_threads(void);

static __inline__ void
fmpz_add_inline(fmpz_t z, const fmpz_t x, const fmpz_t y)
{
Expand Down
46 changes: 46 additions & 0 deletions fmpz_extras/flint_get_num_available_threads.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright (C) 2022 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/

#include "flint/thread_pool.h"
#include "fmpz_extras.h"

slong arb_thread_pool_num_available(thread_pool_t T)
{
slong i, num = 0;
thread_pool_entry_struct * D;

#if FLINT_USES_PTHREAD
pthread_mutex_lock(&T->mutex);
#endif

D = T->tdata;
if (T->length > 0)
{
for (i = 0; i < T->length; i++)
{
num += D[i].available;
}
}

#if FLINT_USES_PTHREAD
pthread_mutex_unlock(&T->mutex);
#endif

return num;
}

slong arb_flint_get_num_available_threads(void)
{
if (global_thread_pool_initialized)
return arb_thread_pool_num_available(global_thread_pool) + 1;

return flint_get_num_threads();
}

0 comments on commit a3e9bac

Please sign in to comment.