Skip to content

Commit

Permalink
Merge pull request #169 from kaipartmann/juliacon_review_errors
Browse files Browse the repository at this point in the history
Fixed JuliaCon review errors with the tests
  • Loading branch information
kaipartmann authored Sep 11, 2024
2 parents f5898d9 + 8894ba1 commit 372ed45
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/auxiliary/logs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ function set_progress_bars!()
progress_bars_enabled = !is_logging && !quiet()
set_progress_bars!(progress_bars_enabled)
mpi_run() || return nothing
if !progress_bars_enabled && !quiet() && mpi_progress_bars()
set_progress_bars!(mpi_progress_bars())
if mpi_progress_bars()
set_progress_bars!(true)
msg = "progress bar settings overwritten manually!\n"
msg *= "The use of progress bars with MPI can lead to a mess in output files!"
@warn msg
else
set_progress_bars!(false)
end
return nothing
end
Expand Down
13 changes: 5 additions & 8 deletions src/auxiliary/mpi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,21 @@ After this function is called, all following simulations will use multithreading
return nothing
end

@inline function set_mpi_run!(b::Bool)
MPI_RUN_FORCED[] && return nothing
MPI_RUN[] = b
return nothing
end

function init_mpi()
if !MPI_INITIALIZED[]
MPI.Init(finalize_atexit=true)
MPI_INITIALIZED[] = true
end
MPI_ISROOT[] = mpi_rank() == 0
set_mpi_run!(mpi_run_initial_check())

# do not overwrite settings if they were already set manually
MPI_RUN_FORCED[] && return nothing

MPI_RUN[] = mpi_run_initial_check()
return nothing
end

function mpi_run_initial_check()
MPI_RUN_FORCED[] && return MPI_RUN[]
haskey(ENV, "MPI_LOCALRANKID") && return true
mpi_nranks() > 1 && return true
nthreads() > 1 && return false
Expand Down
4 changes: 2 additions & 2 deletions test/auxiliary/test_mpi.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@testitem "force_mpi_run!" begin
Peridynamics.force_mpi_run!()
@test Peridynamics.mpi_run() == true
Peridynamics.set_mpi_run!(false) # will do nothing because MPI_RUN was forced
Peridynamics.init_mpi() # will do nothing because MPI_RUN was forced
@test Peridynamics.mpi_run() == true
end

@testitem "force_threads_run!" begin
Peridynamics.force_threads_run!()
@test Peridynamics.mpi_run() == false
Peridynamics.set_mpi_run!(true) # will do nothing because MPI_RUN was forced
Peridynamics.init_mpi() # will do nothing because MPI_RUN was forced
@test Peridynamics.mpi_run() == false
end
14 changes: 14 additions & 0 deletions test/core/test_job.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@testitem "show Job" begin
# for now, this test only works with multithreading!
mpi_run_current_value = Peridynamics.MPI_RUN[]
Peridynamics.MPI_RUN[] = false

io = IOBuffer()

b1 = Body(BBMaterial(), rand(3,10), rand(10))
Expand All @@ -17,9 +21,16 @@
msg = String(take!(io))
@test contains(msg, "15-point MultibodySetup")
@test contains(msg, "VelocityVerlet(n_steps=1, safety_factor=0.7)")

# reset to the value as before
Peridynamics.MPI_RUN[] = mpi_run_current_value
end

@testitem "Job pre submission checks" begin
# for now, this test only works with multithreading!
mpi_run_current_value = Peridynamics.MPI_RUN[]
Peridynamics.MPI_RUN[] = false

b1 = Body(BBMaterial(), rand(3,10), rand(10))
vv = VelocityVerlet(steps=1)
@test_throws ErrorException Job(b1, vv)
Expand All @@ -45,4 +56,7 @@ end
velocity_ic!(b2, :all_points, 1, 1.0)
job = Job(ms, vv)
@test job.spatial_setup isa MultibodySetup

# reset to the value as before
Peridynamics.MPI_RUN[] = mpi_run_current_value
end
7 changes: 7 additions & 0 deletions test/integration/test_contact_4_points.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@testitem "Contact example with 4 points" begin
# for now, this test only works with multithreading!
mpi_run_current_value = Peridynamics.MPI_RUN[]
Peridynamics.MPI_RUN[] = false

pos1 = [
0.0 1.0
0.0 0.0
Expand Down Expand Up @@ -38,4 +42,7 @@
vel_contact = acc_contact * job.time_solver.Δt * 0.5
@test s1.velocity[1,2] -vel_contact
@test s2.velocity[1,1] vel_contact

# reset to the value as before
Peridynamics.MPI_RUN[] = mpi_run_current_value
end

0 comments on commit 372ed45

Please sign in to comment.