A few weeks ago, @miguelraz , kindly unleashed binary builder magic to create primecount.jll, which reveals the number of primes below a given number very quickly.
Thanks to @giordano , we have AVX2 speedups from the most recent build
julia> using primecount_jll
julia> @time run(`$(primecount()) 1e8`);
5761455
0.011614 seconds (467 allocations: 33.562 KiB)
julia> @time run(`$(primecount()) 1e14`);
3204941750802
0.181341 seconds (467 allocations: 33.562 KiB)
julia> versioninfo()
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz
WOR…
It’s been useful, but I’m still stumped by something…this works great …
using primecount_jll
@time run($(primecount()) 4999933
);
But I want to do something like …
using primecount_jll
x = 4999933
@time run($(primecount()) x
);
I thought whatever the trick needed would become clear as I used it, but it has not.
1 Like
oheil
May 27, 2021, 6:21pm
2
julia> x=4999933
4999933
julia> run(`$(primecount()) $x`);
348508
But I found an issue. The following doesnt work:
julia> x=1e14
1.0e14
julia> run(`$(primecount()) $x`);
Because the implicit formating into 1.0e14
from 1e14
makes the primecount
executable to fail.
But this would work:
julia> x="1e14"
"1e14"
julia> run(`$(primecount()) $x`);
3204941750802
1 Like
Do note that it is much more efficient to just use @ccall
, and not spawn an external process with run
every time you call the function:
Yup - that would add a dependency to primecount, but I think that’s accessible. If any newcomers want to PR that, feel free to DM and I’ll mentor through the process.
Concretely, we wouldn’t want to spawn an external process with run(...) every time we want to count primes - we want to call to the C ABI with @ccall so that this is just a direct function call:
julia> myprimecount(x) = @ccall libprimecount.primecount_pi(x::Clonglong)::Clonglong
myprimecount (generic function with 1 method)
juli…
1 Like