Skip to content

Commit

Permalink
Use global timer to measure performance
Browse files Browse the repository at this point in the history
This makes syntax a little bit easier. Also, measure more accurately performance
of modal solver under investigation.
  • Loading branch information
ahojukka5 committed Aug 19, 2017
1 parent b72db93 commit 6e03687
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 61 deletions.
7 changes: 1 addition & 6 deletions src/JuliaFEM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ This is JuliaFEM -- Finite Element Package
module JuliaFEM

using TimerOutputs
const to = TimerOutput()
function print_statistics()
println(to)
end

export print_statistics, @timeit, to
export @timeit, print_timer

import Base: getindex, setindex!, convert, length, size, isapprox, similar,
start, first, next, done, last, endof, vec, ==, +, -, *, /, haskey, copy,
Expand Down
56 changes: 28 additions & 28 deletions src/solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,43 +363,43 @@ function solve!(solver::Solver; empty_assemblies_before_solution=true, symmetric
return
end

""" Default assembler for solver. """
function assemble!(solver::Solver; timing=true, with_mass_matrix=false)
"""
assemble!(solver; with_mass_matrix=false)
Default assembler for solver.
This function loops over all problems defined in problem and launches
standard assembler for them. As a result, each problem.assembly is
populated with global stiffness matrix, force vector, and, optionally,
mass matrix.
"""
function assemble!(solver::Solver; with_mass_matrix=false)
info("Assembling problems ...")

function do_assemble(problem)
t00 = Base.time()
empty!(problem.assembly)
assemble!(problem, solver.time)
if with_mass_matrix && is_field_problem(problem)
assemble!(problem, solver.time, Val{:mass_matrix})
for problem in get_problems(solver)
timeit("assemble $(problem.name)") do
empty!(problem.assembly)
assemble!(problem, solver.time)
end
t11 = Base.time()
return t11-t00
end

t0 = Base.time()
assembly_times = map(do_assemble, solver.problems)
nproblems = length(assembly_times)
if with_mass_matrix
for problem in get_field_problems(solver)
timeit("assemble $(problem.name) mass matrix") do
assemble!(problem, solver.time, Val{:mass_matrix})
end
end
end

ndofs = 0
for problem in solver.problems
Ks = size(problem.assembly.K, 2)
Cs = size(problem.assembly.C1, 2)
ndofs = max(ndofs, Ks, Cs)
end

solver.ndofs = ndofs
t1 = round(Base.time()-t0, 2)
info("Assembled $nproblems problems in $t1 seconds. ndofs = $ndofs.")
if timing
info("Assembly times:")
for (i, problem) in enumerate(solver.problems)
pn = problem.name
pt = round(assembly_times[i], 2)
info("$i $pn $pt")
end
end

info("Assembly done!")
end

function get_unknown_fields(solver::Solver)
Expand Down Expand Up @@ -688,10 +688,10 @@ function (solver::Solver{Linear})()
info("Starting linear solver")
info("Increment time t=$(round(solver.time, 3))")
info(repeat("-", 80))
@timeit to "initialize solver" initialize!(solver)
@timeit to "assemble problems" assemble!(solver)
@timeit to "solve linear system" solve!(solver)
@timeit to "update problems" update!(solver)
@timeit "initialize solver" initialize!(solver)
@timeit "assemble problems" assemble!(solver)
@timeit "solve linear system" solve!(solver)
@timeit "update problems" update!(solver)
t1 = round(Base.time()-t0, 2)
info("Linear solver ready in $t1 seconds.")
end
Expand Down
45 changes: 20 additions & 25 deletions src/solvers_modal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,13 @@ function (solver::Solver{Modal})(; bc_invertible=false, P=nothing, symmetric=tru
info("Increment time t=$(round(solver.time, 3))")
info(repeat("-", 80))
initialize!(solver)
@timeit to "assemble matrices" begin

@timeit "assemble matrices" begin
assemble!(solver; with_mass_matrix=true)
end
M, K, Kg, f = get_field_assembly(solver)
if solver.properties.geometric_stiffness
K += Kg
M, K, Kg, f = get_field_assembly(solver)
if solver.properties.geometric_stiffness
K += Kg
end
end

dim = size(K, 1)
Expand All @@ -232,23 +233,19 @@ function (solver::Solver{Modal})(; bc_invertible=false, P=nothing, symmetric=tru
K_red = K
M_red = M

if !(P == nothing)
tic()
info("Using custom P to make transform K_red = P'*K*P and M_red = P'*M*P")
K_red = P'*K_red*P
M_red = P'*M_red*P
t1 = round(toq(), 2)
info("Transform ready in $t1 seconds.")
elseif nboundary_problems != 0
tic()
info("Eliminate boundary conditions from system.")
for boundary_problem in get_boundary_problems(solver)
eliminate_boundary_conditions!(K_red, M_red, boundary_problem, dim)
@timeit "eliminate boundary conditions" begin
if !(P == nothing)
info("Using custom P to make transform K_red = P'*K*P and M_red = P'*M*P")
K_red = P'*K_red*P
M_red = P'*M_red*P
elseif nboundary_problems != 0
info("Eliminate boundary conditions from system.")
for boundary_problem in get_boundary_problems(solver)
eliminate_boundary_conditions!(K_red, M_red, boundary_problem, dim)
end
else
info("No boundary Dirichlet boundary conditions found for system.")
end
t1 = round(toq(), 2)
info("Eliminated boundary conditions in $t1 seconds.")
else
info("No boundary Dirichlet boundary conditions found for system.")
end

# free up some memory before solution
Expand Down Expand Up @@ -299,7 +296,7 @@ function (solver::Solver{Modal})(; bc_invertible=false, P=nothing, symmetric=tru
passed = false

try
@timeit to "solve eigenvalue problem using `eigs`" begin
@timeit "solve eigenvalue problem using `eigs`" begin
om2, X = eigs(K_red + sigma*I, M_red; nev=props.nev, which=props.which)
end
passed = true
Expand Down Expand Up @@ -354,9 +351,7 @@ function (solver::Solver{Modal})(; bc_invertible=false, P=nothing, symmetric=tru
end
end

@timeit to "save results to Xdmf" begin
update_xdmf!(solver)
end
@timeit "save results to Xdmf" update_xdmf!(solver)

return true

Expand Down
2 changes: 0 additions & 2 deletions test/test_elasticity_2d_linear_with_surface_load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,3 @@ using JuliaFEM
u3_expected = f/E*[-nu, 1] + g/(2*E)*[-nu, 1]
@test isapprox(u3, u3_expected)
end

print_statistics()

0 comments on commit 6e03687

Please sign in to comment.