Skip to content

Commit

Permalink
Rel 9.3.1 - Updated RedCardsStudy
Browse files Browse the repository at this point in the history
  • Loading branch information
goedman committed Feb 26, 2022
1 parent 9184552 commit 956c06e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 65 deletions.
Binary file modified Examples/RedCardsStudy/graphs/arm_log_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Examples/RedCardsStudy/graphs/arm_log_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 21 additions & 2 deletions Examples/RedCardsStudy/redcardstudy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,24 @@ if success(rc_1)
println()
end

println("Timing of logitic_1 (4 Julia chains, 16 num_threads):")
@time rc_2 = stan_sample(logistic_1; data, num_threads=16);
println("Timing of logistic_1 (4 C++ chains, 4 num_threads):")
@time rc_2 = stan_sample(logistic_1; data,
use_cpp_chains=true, num_threads=4);

if success(rc_2)
dfs_2 = read_summary(logistic_1)
dfs_2[8:9, [1,2,4,8,9,10]] |> display
println()
end

println("Timing of logistic_1 (4 C++ chains, 9 num_threads):")
@time rc_3 = stan_sample(logistic_1; data,
use_cpp_chains=true, num_threads=9);

if success(rc_3)
dfs_3 = read_summary(logistic_1)
dfs_3[8:9, [1,2,4,8,9,10]] |> display
println()
end


46 changes: 25 additions & 21 deletions Examples/RedCardsStudy/results/arm_log_0_df.csv
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
num_threads,num_cpp_chains,num_chains,min,median,max
1,1,1,41.14798875,42.0751239375,43.002259125
1,1,2,43.053162667,43.684225792,44.315288917
1,2,1,85.082179042,85.523311354,85.964443666
1,1,4,44.348197333,45.266327833000005,46.184458333
1,4,1,169.541247042,170.051630875,170.562014708
4,1,1,44.5953465,45.1246455415,45.653944583
4,1,2,43.011960125,43.208479979,43.404999833
4,2,1,43.71961475,44.5449918545,45.370368959
4,1,4,43.972719125,45.259647228999995,46.546575333
4,4,1,44.549866125,45.357865853999996,46.165865583
7,1,1,43.489759791,43.498075,43.506390209
7,1,2,44.942660125,44.949248187500004,44.95583625
7,2,1,43.117407208,43.1499807085,43.182554209
7,1,4,44.885566916,46.495810916500005,48.106054917
7,4,1,44.602492541,44.8093151035,45.016137666
9,1,1,42.936934416,43.366339083,43.79574375
9,1,2,44.745813375,45.0354235,45.325033625
9,2,1,43.150660125,44.491569874999996,45.832479625
9,1,4,43.94656775,44.9314855625,45.916403375
9,4,1,45.661471792,46.5689024795,47.476333167
num_threads,use_cpp_chains,num_chains,min,median,max
1,false,1,41.211678791,42.2855897915,43.359500792
1,true,1,40.949756875,41.7220244375,42.494292
1,false,2,40.872385917,41.2066827505,41.540979584
1,true,2,81.326617541,83.9514828745,86.576348208
1,false,4,44.288551208,44.3492694375,44.409987667
1,true,4,166.786811375,168.702599625,170.618387875
4,false,1,41.581995708,41.842955062499996,42.103914417
4,true,1,41.584224,42.4099076455,43.235591291
4,false,2,41.476701083,42.056946604000004,42.637192125
4,true,2,41.81829475,42.3697993335,42.921303917
4,false,4,43.143137209,43.900177938,44.657218667
4,true,4,43.441621167,44.6937598545,45.945898542
7,false,1,42.499945333,43.678637416499996,44.8573295
7,true,1,41.30137825,41.3448683125,41.388358375
7,false,2,42.525958625,43.2620819375,43.99820525
7,true,2,42.931152041,43.25606247899999,43.580972917
7,false,4,43.932969959,44.663448417,45.393926875
7,true,4,43.134551542,43.891019000499995,44.647486459
9,false,1,42.28336375,42.4457649795,42.608166209
9,true,1,40.02080625,42.7533424585,45.485878667
9,false,2,43.041884292,43.449855521,43.85782675
9,true,2,42.860552292,42.984702812500004,43.108853333
9,false,4,43.115265958,43.5552859995,43.995306041
9,true,4,43.649232167,44.2822028335,44.9151735
46 changes: 25 additions & 21 deletions Examples/RedCardsStudy/results/arm_log_1_df.csv
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
num_threads,num_cpp_chains,num_chains,min,median,max
1,1,1,46.306252667,47.9648187295,49.623384792
1,1,2,48.368639416,48.4196988745,48.470758333
1,2,1,94.759566375,96.0593121455,97.359057916
1,1,4,49.722570333,50.168888833,50.615207333
1,4,1,186.620181375,188.34839281249998,190.07660425
4,1,1,14.528930375,15.0171946665,15.505458958
4,1,2,15.309789542,15.6137181045,15.917646667
4,2,1,24.553085291,24.862362291,25.171639291
4,1,4,27.319480916,27.445425041500002,27.571369167
4,4,1,49.113697125,49.164597854,49.215498583
7,1,1,10.132694166,10.1948228125,10.256951459
7,1,2,15.951696583,15.966202687500001,15.980708792
7,2,1,15.239714208,15.444107083,15.648499958
7,1,4,29.241835584,30.572780375500002,31.903725167
7,4,1,29.273695459,29.490604646,29.707513833
9,1,1,8.955993875,9.0660999165,9.176205958
9,1,2,16.059763959,16.2423760215,16.424988084
9,2,1,13.666453375,13.7145771045,13.762700834
9,1,4,30.416946125,30.9933443125,31.5697425
9,4,1,25.049932583,25.092168479,25.134404375
num_threads,use_cpp_chains,num_chains,min,median,max
1,false,1,44.046182417,44.3319545835,44.61772675
1,true,1,45.254333417,45.4359961255,45.617658834
1,false,2,44.803754166,44.8702592705,44.936764375
1,true,2,85.577641708,88.2907146455,91.003787583
1,false,4,47.436434584,48.1685463125,48.900658041
1,true,4,172.568950959,172.733074521,172.897198083
4,false,1,41.721457417,42.4480268335,43.17459625
4,true,1,13.539867541,13.6163644165,13.692861292
4,false,2,45.27366025,46.6444991665,48.015338083
4,true,2,23.160712375,23.161572937499997,23.1624335
4,false,4,46.442843708,46.880515229,47.31818675
4,true,4,45.075045666,45.8543589785,46.633672291
7,false,1,42.732774209,42.8791680835,43.025561958
7,true,1,9.25149175,9.2807329165,9.309974083
7,false,2,44.223115625,44.658409207999995,45.093702791
7,true,2,13.891670208,14.031236958000001,14.170803708
7,false,4,46.175434958,48.128653625,50.081872292
7,true,4,26.895896625,27.062507396,27.229118167
9,false,1,42.566672708,42.961287020499995,43.355901333
9,true,1,8.205664625,8.266715354,8.327766083
9,false,2,47.130992792,47.399313645999996,47.6676345
9,true,2,12.101010667,12.338285479,12.575560291
9,false,4,46.196332084,46.449306458500004,46.702280833
9,true,4,22.849060542,22.917174917,22.985289292
26 changes: 9 additions & 17 deletions Examples/RedCardsStudy/timings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,25 @@ using Distributed, StanSample, CSV, DataFrames, StatsPlots, Statistics
ProjDir = @__DIR__
#include(joinpath(ProjDir, "redcardstudy.jl"))

function timings(model, nts, ncs; N=6, types=[1, 2])
function timings(model, nts, ncs; N=6, use_cpp=[false, true])

df = DataFrame()
res_t = zeros(N)
println("\n\n")
for nt in nts # Number of C++ threads
for n in ncs # Number of chains
for j in types # types==1: Julia, types==2: C++
if j ==1
nc = 1
nj = n
else
nc = n
nj = 1
end
if j==1 && n==1
continue
end
println("(num_threads=$nt, num_cpp-chains=$nc, \
num_chains=$nj) runs")
for j in use_cpp # types==1: Julia, types==2: C++
println("(num_threads=$nt, use_cpp-chains=$j, \
num_chains=$n) runs")
for i in 1:N
res_t[i] = @elapsed stan_sample(model;
data, num_threads=nt, num_cpp_chains=nc, num_chains=nj)
data, num_threads=nt, use_cpp_chains=j, num_chains=n)
println("Iteration=$i, time=$(res_t[i])")
end
append!(df, DataFrame(
num_threads=nt,
num_cpp_chains=nc,
num_chains=nj,
use_cpp_chains=j,
num_chains=n,
min=minimum(res_t),
median=median(res_t),
max=maximum(res_t))
Expand All @@ -47,12 +37,14 @@ nts = [1, 4, 7, 9]
ncs = [1, 2, 4]
N = 2

println("\nlogistic_0 runs\n")
model = logistic_0
arm_log_0_df = timings(model, nts, ncs; N)
arm_log_0_df |> display

CSV.write(joinpath(ProjDir, "results", "arm_log_0_df.csv"), arm_log_0_df)

println("\nlogistic_1 runs\n")
model = logistic_1
arm_log_1_df = timings(model, nts, ncs; N)
arm_log_1_df |> display
Expand Down
12 changes: 8 additions & 4 deletions Examples/RedCardsStudy/timings_plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ function timings_plot(df::DataFrame; model = "1", ylim=(0, 250))
colors = [:darkred, :darkblue, :darkgreen, :black]
fig1 = plot(; xlim=(0, 9), ylim=ylim,
xlab="c++ num_threads", ylab="elapsed time [s]")
println("\nuse_cpp_chains == false\n")
for (indx, i) in enumerate([1, 4])
dft = df[df.num_cpp_chains .== 1 .&& df.num_chains .== i, :]
dft = df[df.num_chains .== i .&& df.use_cpp_chains .== false, :]
println(dft)
marksym = :cross
plot!(dft.num_threads, dft.median;
marker=marksym, lab="$(i) num_chains")
title!("Log_$(model) Julia\n(4 Julia threads)")
end
println("\nuse_cpp_chains == true\n")
fig2 = plot(; xlim=(0, 9), ylim=ylim,
xlab="c++ num_threads", ylab="elapsed time [s]")
for (indx, i) in enumerate([1, 4])
dft = df[df.num_chains .== 1 .&& df.num_cpp_chains .== i, :]
dft = df[df.num_chains .== i .&& df.use_cpp_chains .== true, :]
println(dft)
marksym = :cross
plot!(dft.num_threads, dft.median;
marker=marksym, lab="$(i) num_cpp_chains")
marker=marksym, lab="$(i) cpp_chains")
title!("Log_$(model) C++\n(4 Julia threads)")
end
plot(fig1, fig2, layout=(1, 2))
Expand All @@ -41,6 +43,8 @@ f0 = timings_plot(arm_log_0; model="0")
savefig(joinpath(ProjDir, "graphs", "arm_log_0.png"))
f1 = timings_plot(arm_log_1)
savefig(joinpath(ProjDir, "graphs", "arm_log_1.png"))

#=
f3 = timings_plot(intel_tbb_log_0; model="0", ylim=(0, 300))
savefig(joinpath(ProjDir, "graphs", "intel_tbb_log_0.png"))
f4 = timings_plot(intel_tbb_log_1)
Expand All @@ -49,4 +53,4 @@ f5 = timings_plot(intel_log_0; model="0", ylim=(0, 300))
savefig(joinpath(ProjDir, "graphs", "intel_log_0.png"))
f6 = timings_plot(intel_log_1; ylim=(0, 300))
savefig(joinpath(ProjDir, "graphs", "intel_log_1.png"))

=#

0 comments on commit 956c06e

Please sign in to comment.