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

explicit gc for McMC #76

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HiQGA"
uuid = "01574e87-63b6-4466-925a-334cf7e21b6b"
authors = ["richardt94 <29562583+richardt94@users.noreply.github.com>"]
version = "0.4.8"
version = "0.4.9"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
2 changes: 1 addition & 1 deletion src/AEMnoNuisanceGradientInversionTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function loopacrossAEMsoundings(soundings::Array{S, 1}, aem_in, σstart, σ0;
aem = makeoperator(aem_in, soundings[s])
fname = soundings[s].sounding_string*"_gradientinv.dat"
σstart_, σ0_ = map(x->x*ones(length(aem.ρ)-1), [σstart, σ0])
@async remotecall_wait(gradientinv, pids[i], σstart_, σ0_, aem;
@async remotecall_fetch(gradientinv, pids[i], σstart_, σ0_, aem;
regtype = regtype ,
nstepsmax = nstepsmax ,
ntries = ntries ,
Expand Down
3 changes: 2 additions & 1 deletion src/AEMnoNuisanceMcMCInversionTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,14 @@ function loopacrossAEMsoundings(soundings::Array{S, 1}, aem_in::Operator1D, opt_
opt = deepcopy(opt_in)
opt.fdataname = soundings[s].sounding_string*"_"

@async remotecall_wait(main, pids[1], opt, aem, collect(pids[2:end]);
@async remotecall_fetch(main, pids[1], opt, aem, collect(pids[2:end]);
Tmax, nsamples, nchainsatone, nominaltime)

end # @sync
dt = time() - t2 #seconds
catlocallogs(nparallelsoundings, nchainspersounding)
writetogloballog("done $iter out of $nsequentialiters at $(Dates.now()) in $dt sec")
GC.gc()
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/AEMwithNuisanceGradientInversionTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function loopacrossAEMsoundings(soundings::Array{S, 1}, aem_in, σstart, σ0, nu
nubounds, nustart = setnuboundsandstartforgradinv(aem, nuboundsΔ)
fname = soundings[s].sounding_string*"_gradientinv.dat"
σstart_, σ0_ = map(x->x*ones(length(aem.ρ)-1), [σstart, σ0])
@async remotecall_wait(gradientinv, pids[i], σstart_, σ0_, nustart, aem;
@async remotecall_fetch(gradientinv, pids[i], σstart_, σ0_, nustart, aem;
regtype = regtype ,
nstepsmax = nstepsmax ,
ntries = ntries ,
Expand Down
3 changes: 2 additions & 1 deletion src/AEMwithNuisanceMcMCInversionTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,14 @@ function loopacrossAEMsoundings(soundings::Array{S, 1}, aem_in::Operator1D, opt_
opt.fdataname = soundings[s].sounding_string*"_"
optn = getoptnfromexisting(optn_in, opt, soundings[s])

@async remotecall_wait(main, pids[1], opt, optn, aem, collect(pids[2:end]);
@async remotecall_fetch(main, pids[1], opt, optn, aem, collect(pids[2:end]);
Tmax, nsamples, nchainsatone, nominaltime)

end # @sync
dt = time() - t2 #seconds
catlocallogs(nparallelsoundings, nchainspersounding)
writetogloballog("done $iter out of $nsequentialiters at $(Dates.now()) in $dt sec")
GC.gc()
end
end

Expand Down
27 changes: 20 additions & 7 deletions src/MCMC_Driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ function main(opt_in ::OptionsStat,
Tmax = 2.5,
nominaltime = nothing)
# for nonstat, stat, and nuisances all together

chains = Chain(myid(), chainprocs, nchainsatone=nchainsatone, Tmax=Tmax)
master_pid = myid()
chains = Chain(master_pid, chainprocs, nchainsatone=nchainsatone, Tmax=Tmax)

m, mns, mn, opt, optns, optn, stat,
statns, statn, F, current_misfit, wp, wpns, wpn,
Expand All @@ -438,6 +438,7 @@ function main(opt_in ::OptionsStat,

close_history.([wp, wpns, wpn])
d_closeall()
explicit_gc(master_pid, chainprocs)
nothing
end

Expand Down Expand Up @@ -541,7 +542,8 @@ function main(opt_in ::OptionsStat,
nominaltime = nothing)
# for nonstat and stat together

chains = Chain(myid(), chainprocs, nchainsatone=nchainsatone, Tmax=Tmax)
master_pid = myid()
chains = Chain(master_pid, chainprocs, nchainsatone=nchainsatone, Tmax=Tmax)

m, mns, opt, optns, stat,
statns, F, current_misfit, wp, wpns,
Expand All @@ -552,6 +554,7 @@ function main(opt_in ::OptionsStat,

close_history.([wp, wpns])
d_closeall()
explicit_gc(master_pid, chainprocs)
nothing
end

Expand Down Expand Up @@ -653,8 +656,8 @@ function main(opt_in ::OptionsStat,
Tmax = 2.5,
nominaltime = nothing)
# purely stationary GP moves + nuisance

chains = Chain(myid(), chainprocs, nchainsatone=nchainsatone, Tmax=Tmax)
master_pid = myid()
chains = Chain(master_pid, chainprocs, nchainsatone=nchainsatone, Tmax=Tmax)

m, mn, opt, optn, stat,
statn, F, current_misfit, wp, wpn,
Expand All @@ -665,6 +668,7 @@ function main(opt_in ::OptionsStat,

close_history.([wp, wpn])
d_closeall()
explicit_gc(master_pid, chainprocs)
nothing
end

Expand Down Expand Up @@ -745,8 +749,8 @@ function main(opt_in ::OptionsStat,
Tmax = 2.5,
nominaltime = nothing)
# purely stationary GP moves

chains = Chain(myid(), chainprocs, nchainsatone=nchainsatone, Tmax=Tmax)
master_pid = myid()
chains = Chain(master_pid, chainprocs, nchainsatone=nchainsatone, Tmax=Tmax)

m, opt, stat,
F, current_misfit, wp,
Expand All @@ -757,6 +761,7 @@ function main(opt_in ::OptionsStat,

close_history(wp)
d_closeall()
explicit_gc(master_pid, chainprocs)
nothing
end

Expand Down Expand Up @@ -826,3 +831,11 @@ function write_to_bin(fp::IOStream, cidx::Int, data)
write(fp, data)
flush(fp)
end

function explicit_gc(master_pid, chainprocs)
pids = [master_pid; chainprocs]
@sync for p in pids
@async remotecall_fetch(GC.gc, p)
end
nothing
end
Loading