Created
February 2, 2022 18:22
-
-
Save chipbuster/56f9cc8fe0e8712d45bc622aac3801f7 to your computer and use it in GitHub Desktop.
A Julia program which segfaults on x64 Arch, when running under 32 threads. Seems to segfault more often when caches are cold.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Base.Threads | |
using Serialization | |
using Distributions | |
using LoopVectorization | |
function bin_data(data, lo, hi, nbins) | |
dx = (hi - lo) / nbins | |
bins = ((data .- lo) ./ dx) .|> floor | |
bins = UInt8.(bins) | |
clamp.(bins, UInt8(0), UInt8(nbins)) | |
end | |
l = SpinLock() | |
function compress_data(data) | |
lock(l) | |
tmpfn = tempname() | |
unlock(l) | |
write(tmpfn, data) | |
run( | |
pipeline( | |
`xz -9e --keep --format=raw --suffix=.xz $(tmpfn)`, | |
stdout = devnull, | |
stderr = devnull, | |
), | |
) | |
nbytes = filesize(tmpfn * ".xz") | |
rm(tmpfn * ".xz") | |
rm(tmpfn) | |
return nbytes | |
end | |
compressed_size_bytes(data) = compress_data(data) | |
compressed_size_bits(data) = compress_data(data) * 8 | |
function emission_times_exp(n, k, Γ) | |
η = (k + Γ) / (k * Γ) | |
dist = Exponential(η) | |
rand(dist, n) | |
end | |
function lose_data(lagtimes, γ) | |
@assert(all(lagtimes .>= 0.0)) | |
ind = Int[] | |
fixed_times = cumsum(lagtimes) | |
for i = 1:length(lagtimes) | |
x = rand() | |
if x < γ | |
push!(ind, i) | |
end | |
end | |
detected_times = fixed_times[ind] | |
detected_times |> diff | |
end | |
ns = [100_000, 1_000_000, 10_000_000] | |
# ns = [1_000] # testing only | |
ks = [0.1, 0.5, 1.0, 5.0, 10.0] | |
Γs = [0.1, 0.5, 1.0, 5.0, 10.0] | |
γs = range(0.1, 1.0, step = 0.1) | |
ntrials = 1000 | |
smrates = Iterators.product(ks, Γs) |> collect |> vec | |
l = SpinLock() | |
@threads for trialnum = 1:ntrials | |
data = Dict() | |
for p in smrates | |
(k, Γ) = p | |
for n in ns | |
# nm_times = get_emission_dt(n, k, Γ) | |
# mar_times = emission_times_exp(n, k, Γ) | |
nm_times = 10.0 .* rand(n) | |
mar_times = 10.0 .* rand(n) | |
for γ in γs | |
nm_lost = lose_data(nm_times, γ) | |
mar_lost = lose_data(mar_times, γ) | |
hi = max(maximum(nm_lost),maximum(mar_lost)) | |
@assert(all(nm_lost .>= 0.0)) | |
@assert(all(mar_lost .>= 0.0)) | |
nm_binned = bin_data(nm_lost, 0.0, hi, 100) | |
mar_binned = bin_data(mar_lost, 0.0, hi, 100) | |
nm_size = compressed_size_bytes(nm_binned) | |
mar_size = compressed_size_bytes(mar_binned) | |
experiment_index = (n = n, k = k, Γ = Γ, γ = γ, trial = trialnum) | |
try | |
lock(l) | |
data[experiment_index] = (1.0, 1.0) | |
finally | |
unlock(l) | |
end | |
end | |
end | |
end | |
serialize("../data/compression_sweep_$(trialnum).jls", data) | |
@info "Finishing trial $(trialnum)" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment