Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Julia implementation #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

giordano
Copy link
Contributor

@giordano giordano commented Oct 18, 2022

Follow up to #52. CC @mcabbott

@Moelf
Copy link
Contributor

Moelf commented Oct 18, 2022

@giordano
Copy link
Contributor Author

Static compilation will probably not like this one, ooops 😅

@mcabbott
Copy link
Contributor

mcabbott commented Oct 18, 2022

For me this is not as quick locally, but maybe just a quirk of my CPU?

Edit: fixed now.

julia> f_57(n) = sum(i -> 4/i, (-2 * n + 1):4:(2 * n))  # this PR, one-line
fm (generic function with 1 method)

julia> @btime f_52(10^6) - pi
  min 398.584 μs, mean 403.151 μs (0 allocations)
-9.999999823762096e-7

julia> @btime f_57(10^6) - pi    # loop with @simd, any variant
  min 736.042 μs, mean 739.643 μs (0 allocations)
-9.999999903698154e-7

julia> @btime f_orig(10^6) - pi  # with x = -x inside loop
  min 1.552 ms, mean 1.569 ms (0 allocations)
-9.999980186137236e-7

julia> versioninfo()
Julia Version 1.9.0-DEV.1528
Platform Info:
  OS: macOS (arm64-apple-darwin21.1.0)
  CPU: 8 × Apple M1

src/leibniz.jl Outdated Show resolved Hide resolved
@niklas-heer
Copy link
Owner

It seems to have broken then compiled Julia version.
https://github.com/niklas-heer/speed-comparison/actions/runs/3275378446/jobs/5390146368#step:6:1598

@giordano
Copy link
Contributor Author

Yes, I know 🙂 Someone else is looking into whether StaticCompiler.jl can handle this. It's all very experimental 😅

@mcabbott
Copy link
Contributor

Note also that these behave differently at small n:

julia> g(i) = 4 / i;

julia> f_1st(rounds) = sum(g, (-2 * rounds + 1):4:(2 * rounds));

julia> f_2nd(n) = sum(i -> 4/(4i-2n-3), 1:n);

julia> hcat(f_orig.(1:10), f_1st.(1:10), f_2nd.(1:10))
10×3 Matrix{Float64}:
 3.46667  -4.0      -4.0
 2.89524   2.66667   2.66667
 3.33968  -3.46667  -3.46667
 2.97605   2.89524   2.89524
 3.28374  -3.33968  -3.33968
 3.01707   2.97605   2.97605
 3.25237  -3.28374  -3.28374
 3.04184   3.01707   3.01707
 3.23232  -3.25237  -3.25237
 3.0584    3.04184   3.04184

@niklas-heer
Copy link
Owner

@giordano ah okay, that is what you meant by that. Got it 👍

@niklas-heer
Copy link
Owner

@giordano I had to update it due to #66

@niklas-heer
Copy link
Owner

The compiled version still seems broken.

     +julia-compiled *failed* | ERROR Earthfile line 205:2
     +julia-compiled *failed* |       The command
     +julia-compiled *failed* |           RUN julia -e 'using Pkg; Pkg.add(name="StaticTools", version="0.8"); Pkg.add(name="StaticCompiler", version="0.4"); include("./leibniz_compiled.jl"); compile_executable(mainjl, (), "./")'
     +julia-compiled *failed* |       did not complete successfully. Exit code 1
Share your logs with an Earthly account (experimental)! Register for one at https://ci.earthly.dev.
Error: build target: build main: failed to solve: process "/bin/sh -c EARTHLY_LOCALLY=false JULIA_GPG=3673DF529D9049477F76B37566E3C7DC03D6E495 JULIA_PATH=/usr/local/julia JULIA_VERSION=1.8.2 PATH=/usr/local/julia/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin iterations=3 timeas=second warmups=2 /usr/bin/earth_debugger /bin/sh -c 'julia -e '\"'\"'using Pkg; Pkg.add(name=\"StaticTools\", version=\"0.8\"); Pkg.add(name=\"StaticCompiler\", version=\"0.4\"); include(\"./leibniz_compiled.jl\"); compile_executable(mainjl, (), \"./\")'\"'\"''" did not complete successfully: exit code: 1
Error: Process completed with exit code 1.

@giordano
Copy link
Contributor Author

Yeah, we're hoping tshort/StaticCompiler.jl#85 will help with that

@giordano giordano force-pushed the patch-1 branch 2 times, most recently from 1e2d6bb to 818b522 Compare October 21, 2022 12:06
@niklas-heer
Copy link
Owner

I guess we are still waiting for tshort/StaticCompiler.jl#89?

@giordano
Copy link
Contributor Author

Yes, which in the meantime became tshort/StaticCompiler.jl#90 (they're having some git-induced troubles over there)

@gbaraldi
Copy link
Contributor

As it turns out. Git is hard 😸

@niklas-heer
Copy link
Owner

Got it 👍 Just let me know when I should test it again through the CI @giordano

As it turns out. Git is hard 😸

Hahaha. Yes, that is very true 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants