Skip to content

Instantly share code, notes, and snippets.

@terasakisatoshi
Last active January 1, 2024 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terasakisatoshi/12ff2013b74a070e71281d753d7e401c to your computer and use it in GitHub Desktop.
Save terasakisatoshi/12ff2013b74a070e71281d753d7e401c to your computer and use it in GitHub Desktop.
dc1394 さんの mc_xorshift 系列を動かす
#=
Usage
```
$ julia <this_file>
julia compile.jl
Cloning into '/var/folders/14/cg438fvd28dg9wpvpwt1lz0c0000gn/T/jl_KgU2vo/Xoshiro256PlusSIMD'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 21 (delta 5), reused 11 (delta 2), pack-reused 0
Receiving objects: 100% (21/21), 15.53 KiB | 418.00 KiB/s, done.
Resolving deltas: 100% (5/5), done.
pi = 3.1416129920000002
1.353768 seconds (42 allocations: 1.406 KiB)
Cloning into '/var/folders/14/cg438fvd28dg9wpvpwt1lz0c0000gn/T/jl_tuYPot/Xoshiro256PlusSIMD'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 21 (delta 5), reused 11 (delta 2), pack-reused 0
Receiving objects: 100% (21/21), 15.53 KiB | 3.88 MiB/s, done.
Resolving deltas: 100% (5/5), done.
pi = 3.1417138080000000
1.019786 seconds (42 allocations: 1.414 KiB)
```
=#
# dc1394/mc_mt19937.cpp
const gist_mc_mt19937_cpp = "https://gist.githubusercontent.com/dc1394/fdde22bf8017371d9658d77e4bdcfb1e/raw/1197af1105e79958f1d8b00e96e8d388c6c3b2e4/mc_mt19937.cpp"
# This should work, but it is slower than mc_xorshift below
mktempdir() do d
cppsource = basename(gist_mc_mt19937_cpp)
cppsource = download(gist_mc_mt19937_cpp, joinpath(d, cppsource))
@info "building..."
run(`g++ -mtune=native -march=native -O3 -std=c++20 $(cppsource) -o ./mc_mt19937`)
@info "start running..."
@time run(`./mc_mt19937`)
@info "done"
end
# dc1394/mc_xorshift.cpp
const gist_mc_xorshift_cpp = "https://gist.githubusercontent.com/dc1394/dcfb3e3d3512cf186812358877be5d57/raw/74a0e66cfab61e084e2b65b59edf0646d643803d/mc_xorshift.cpp"
const repository_Xoshiro256PlusSIMD = "https://github.com/stephanfr/Xoshiro256PlusSIMD"
mktempdir() do d
cppsource = basename(gist_mc_xorshift_cpp)
cppsource = download(gist_mc_xorshift_cpp, joinpath(d, cppsource))
include_path = joinpath(d, "Xoshiro256PlusSIMD", "include")
run(`git clone --depth 1 $(repository_Xoshiro256PlusSIMD) $(joinpath(d, "Xoshiro256PlusSIMD"))`)
@info "building..."
run(`g++ -mavx2 -std=c++17 -I$(include_path) -O3 $(cppsource) -o ./mc_xorshift`)
@info "start running..."
@time run(`./mc_xorshift`)
@info "done"
end
const gist_mc_xorshift_vec_cpp = "https://gist.githubusercontent.com/dc1394/9dcbd93253a363a80da49d148718b425/raw/60ad71f094b020c36deeecbd79c64094054d9a27/mc_xorshift_vec.cpp"
# dc1394/mc_xorshift_vec.cpp
mktempdir() do d
cppsource = basename(gist_mc_xorshift_vec_cpp)
cppsource = download(gist_mc_xorshift_vec_cpp, joinpath(d, cppsource))
include_path = joinpath(d, "Xoshiro256PlusSIMD", "include")
run(`git clone --depth 1 $(repository_Xoshiro256PlusSIMD) $(joinpath(d, "Xoshiro256PlusSIMD"))`)
@info "building..."
run(`g++ -mavx2 -std=c++17 -I$(include_path) -O3 $(cppsource) -o ./mc_xorshift_vec`)
@info "start running..."
@time run(`./mc_xorshift_vec`)
@info "done"
end
#=
# avx512 は手元のマシンでは動かなかったので諦めました.sorry
const gist_mc_dsfmt_cpp = "https://gist.githubusercontent.com/dc1394/b86cca265e2a6f801a2f9e0d7ab40877/raw/f3f1c67a528d0fafd74b39fdb0017e2173d544f6/mc_dsfmt.cpp"
const repository_dSFMT = "https://github.com/magurosan/dSFMT.git"
const branch_dSFMT = "AVX512"
mktempdir() do d
cppsource = basename(gist_mc_dsfmt_cpp)
cppsource = download(gist_mc_dsfmt_cpp, joinpath(d, cppsource))
run(`git clone --depth 1 -b AVX512 https://github.com/magurosan/dSFMT.git $(joinpath(d, "dSFMT"))`)
run(`g++ -mavx512f -std=c++17 -IdSFMT -O3 $(cppsource) -o ./mc_dsfmt`)
@time run(`mc_dsfmt`)
end
=#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment