profiling.jl (7472B)
1 #!/usr/bin/env julia 2 if VERSION < v"0.7.0-DEV.2004" 3 using Base.Test 4 else 5 using Test 6 end 7 import Plots 8 import Granular 9 import CurveFit 10 11 verbose=false 12 13 @info "Testing performance with many interacting grains" 14 15 function timeSingleStepInDenseSimulation(nx::Int; verbose::Bool=true, 16 profile::Bool=false, 17 grid_sorting::Bool=true, 18 include_atmosphere::Bool=false) 19 20 sim = Granular.createSimulation() 21 #nx, ny = 25, 25 22 #nx, ny = 250, 250 23 ny = nx 24 dx, dy = 40., 40. 25 sim.ocean = Granular.createRegularOceanGrid([nx, ny, 2], [nx*dx, ny*dy, 10.]) 26 if !grid_sorting 27 sim.ocean.input_file = false # fallback to all-to-all contact search 28 end 29 r = min(dx, dy)/2. 30 if include_atmosphere 31 sim.atmosphere = Granular.createRegularAtmosphereGrid([nx, ny, 2], 32 [nx*dx, ny*dy, 10.]) 33 end 34 35 # add grains in regular packing 36 for iy=1:ny 37 for ix=1:nx 38 x = r + (ix - 1)*dx 39 y = r + (iy - 1)*dy 40 fixed = false 41 if ix == 1 || iy == 1 || ix == nx || iy == ny 42 fixed = true 43 end 44 Granular.addGrainCylindrical!(sim, [x, y], r*1.1, 1., 45 fixed=fixed, verbose=false) 46 end 47 end 48 printstyled("number of grains: $(length(sim.grains))\n", 49 color=:green) 50 if grid_sorting 51 if include_atmosphere 52 printstyled("using cell-based spatial decomposition " * 53 " (ocean + atmosphere)\n", color=:green) 54 else 55 printstyled("using cell-based spatial " * 56 "decomposition (ocean)\n", color=:green) 57 end 58 else 59 printstyled("using all-to-all contact search\n", color=:green) 60 end 61 62 Granular.setTotalTime!(sim, 1.0) 63 Granular.setTimeStep!(sim) 64 Granular.run!(sim, single_step=true, verbose=true) 65 if profile 66 @profile Granular.run!(sim, single_step=true, verbose=true) 67 if verbose 68 Profile.print() 69 end 70 Granular.run!(sim, single_step=true, verbose=true) 71 end 72 n_runs = 4 73 t_elapsed = 1e12 74 for i=1:n_runs 75 tic() 76 @time Granular.run!(sim, single_step=true, verbose=true) 77 t = toc() 78 if t < t_elapsed 79 t_elapsed = t 80 end 81 end 82 83 #Granular.writeVTK(sim) 84 85 @test sim.grains[1].n_contacts == 0 86 @test sim.grains[2].n_contacts == 1 87 @test sim.grains[3].n_contacts == 1 88 @test sim.grains[nx].n_contacts == 0 89 @test sim.grains[nx + 1].n_contacts == 1 90 @test sim.grains[nx + 2].n_contacts == 4 91 return t_elapsed, Base.summarysize(sim) 92 end 93 94 #nx = Int[4 8 16 32 64 96] 95 nx = round.(logspace(1, 2, 16)) 96 elements = zeros(length(nx)) 97 t_elapsed = zeros(length(nx)) 98 t_elapsed_all_to_all = zeros(length(nx)) 99 t_elapsed_cell_sorting = zeros(length(nx)) 100 t_elapsed_cell_sorting2 = zeros(length(nx)) 101 memory_usage_all_to_all = zeros(length(nx)) 102 memory_usage_cell_sorting = zeros(length(nx)) 103 memory_usage_cell_sorting2 = zeros(length(nx)) 104 for i=1:length(nx) 105 @info "nx = $(nx[i])" 106 t_elapsed_all_to_all[i], memory_usage_all_to_all[i] = 107 timeSingleStepInDenseSimulation(Int(nx[i]), grid_sorting=false) 108 t_elapsed_cell_sorting[i], memory_usage_cell_sorting[i] = 109 timeSingleStepInDenseSimulation(Int(nx[i]), grid_sorting=true) 110 t_elapsed_cell_sorting2[i], memory_usage_cell_sorting2[i] = 111 timeSingleStepInDenseSimulation(Int(nx[i]), grid_sorting=true, 112 include_atmosphere=true) 113 elements[i] = nx[i]*nx[i] 114 end 115 116 #Plots.gr() 117 Plots.pyplot() 118 Plots.scatter(elements, t_elapsed_all_to_all, 119 xscale=:log10, 120 yscale=:log10, 121 label="All to all") 122 fit_all_to_all = CurveFit.curve_fit(CurveFit.PowerFit, 123 elements, t_elapsed_all_to_all) 124 label_all_to_all = @sprintf "%1.3g n^%3.2f" fit_all_to_all.coefs[1] fit_all_to_all.coefs[2] 125 Plots.plot!(elements, fit_all_to_all(elements), 126 xscale=:log10, 127 yscale=:log10, 128 label=label_all_to_all) 129 130 Plots.scatter!(elements, t_elapsed_cell_sorting, 131 xscale=:log10, 132 yscale=:log10, 133 label="Cell-based spatial decomposition (ocean only)") 134 fit_cell_sorting = CurveFit.curve_fit(CurveFit.PowerFit, 135 elements, t_elapsed_cell_sorting) 136 label_cell_sorting = @sprintf "%1.3g n^%3.2f" fit_cell_sorting.coefs[1] fit_cell_sorting.coefs[2] 137 Plots.plot!(elements, fit_cell_sorting(elements), 138 xscale=:log10, 139 yscale=:log10, 140 label=label_cell_sorting) 141 142 Plots.scatter!(elements, t_elapsed_cell_sorting2, 143 xscale=:log10, 144 yscale=:log10, 145 label="Cell-based spatial decomposition (ocean + atmosphere)") 146 fit_cell_sorting2 = CurveFit.curve_fit(CurveFit.PowerFit, 147 elements, t_elapsed_cell_sorting2) 148 label_cell_sorting2 = @sprintf "%1.3g n^%3.2f" fit_cell_sorting2.coefs[1] fit_cell_sorting2.coefs[2] 149 Plots.plot!(elements, fit_cell_sorting2(elements), 150 xscale=:log10, 151 yscale=:log10, 152 label=label_cell_sorting2) 153 154 Plots.title!("Dense granular system " * "(host: $(gethostname()))") 155 Plots.xaxis!("Number of grains") 156 Plots.yaxis!("Wall time per time step [s]") 157 Plots.savefig("profiling-cpu.pdf") 158 159 Plots.scatter(elements, memory_usage_all_to_all .÷ 1024, 160 xscale=:log10, 161 yscale=:log10, 162 label="All to all") 163 fit_all_to_all = CurveFit.curve_fit(CurveFit.PowerFit, 164 elements, memory_usage_all_to_all .÷ 1024) 165 label_all_to_all = @sprintf "%1.3g n^%3.2f" fit_all_to_all.coefs[1] fit_all_to_all.coefs[2] 166 Plots.plot!(elements, fit_all_to_all(elements), 167 xscale=:log10, 168 yscale=:log10, 169 label=label_all_to_all) 170 171 Plots.scatter!(elements, memory_usage_cell_sorting .÷ 1024, 172 xscale=:log10, 173 yscale=:log10, 174 label="Cell-based spatial decomposition (ocean only)") 175 fit_cell_sorting = CurveFit.curve_fit(CurveFit.PowerFit, 176 elements, memory_usage_cell_sorting .÷ 1024) 177 label_cell_sorting = @sprintf "%1.3g n^%3.2f" fit_cell_sorting.coefs[1] fit_cell_sorting.coefs[2] 178 Plots.plot!(elements, fit_cell_sorting(elements), 179 xscale=:log10, 180 yscale=:log10, 181 label=label_cell_sorting) 182 183 Plots.scatter!(elements, memory_usage_cell_sorting2 .÷ 1024, 184 xscale=:log10, 185 yscale=:log10, 186 label="Cell-based spatial decomposition (ocean + atmosphere)") 187 fit_cell_sorting2 = CurveFit.curve_fit(CurveFit.PowerFit, 188 elements, 189 memory_usage_cell_sorting2 .÷ 1024) 190 label_cell_sorting2 = @sprintf "%1.3g n^%3.2f" fit_cell_sorting2.coefs[1] fit_cell_sorting2.coefs[2] 191 Plots.plot!(elements, fit_cell_sorting2(elements), 192 xscale=:log10, 193 yscale=:log10, 194 label=label_cell_sorting2) 195 196 Plots.title!("Dense granular system " * "(host: $(gethostname()))") 197 Plots.xaxis!("Number of grains") 198 Plots.yaxis!("Memory usage [kb]") 199 Plots.savefig("profiling-memory-usage.pdf")