Skip to content

Commit

Permalink
Merge pull request #76 from GeoscienceAustralia/silentlog
Browse files Browse the repository at this point in the history
explicit gc for McMC
  • Loading branch information
a2ray authored Oct 9, 2024
2 parents 4773825 + 9465983 commit bd9d975
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
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 <[email protected]>"]
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

2 comments on commit bd9d975

@a2ray
Copy link
Collaborator Author

@a2ray a2ray commented on bd9d975 Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/116890

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.9 -m "<description of version>" bd9d9754d55d0830b09efc7d6c0e715e46bf407f
git push origin v0.4.9

Please sign in to comment.