bscpkgs/garlic/fig/nbody/baseline.R

103 lines
2.3 KiB
R
Raw Normal View History

2020-10-16 21:55:52 +08:00
library(ggplot2)
library(dplyr)
library(scales)
2020-10-23 16:53:39 +08:00
library(jsonlite)
2020-10-16 21:55:52 +08:00
2020-10-23 16:53:39 +08:00
args=commandArgs(trailingOnly=TRUE)
2020-10-16 21:55:52 +08:00
2020-10-23 16:53:39 +08:00
# Read the timetable from args[1]
input_file = "input.json"
if (length(args)>0) { input_file = args[1] }
# Load the dataset in NDJSON format
dataset = jsonlite::stream_in(file(input_file)) %>%
jsonlite::flatten()
particles = unique(dataset$config.particles)
# We only need the nblocks and time
df = select(dataset, config.nblocks, config.hw.cpusPerSocket, time) %>%
rename(nblocks=config.nblocks,
cpusPerSocket=config.hw.cpusPerSocket)
df = df %>% mutate(blocksPerCpu = nblocks / cpusPerSocket)
df$nblocks = as.factor(df$nblocks)
2020-11-02 17:37:22 +08:00
df$blocksPerCpuFactor = as.factor(df$blocksPerCpu)
2020-10-16 21:55:52 +08:00
# Normalize the time by the median
2020-10-23 16:53:39 +08:00
D=group_by(df, nblocks) %>%
mutate(tnorm = time / median(time) - 1)
2020-10-23 16:53:39 +08:00
bs_unique = unique(df$nblocks)
nbs=length(bs_unique)
print(D)
2020-10-23 16:53:39 +08:00
ppi=300
h=5
w=5
png("box.png", width=w*ppi, height=h*ppi, res=ppi)
#
#
#
2020-10-23 16:53:39 +08:00
# Create the plot with the normalized time vs nblocks
2020-11-02 17:37:22 +08:00
p = ggplot(data=D, aes(x=blocksPerCpuFactor, y=tnorm)) +
2020-10-16 21:55:52 +08:00
# Labels
2020-11-02 17:37:22 +08:00
labs(x="Num blocks", y="Normalized time",
2020-10-23 16:53:39 +08:00
title=sprintf("Nbody normalized time. Particles=%d", particles),
subtitle=input_file) +
2020-10-16 21:55:52 +08:00
# Center the title
#theme(plot.title = element_text(hjust = 0.5)) +
# Black and white mode (useful for printing)
#theme_bw() +
2020-10-23 16:53:39 +08:00
# Add the maximum allowed error lines
2020-11-02 17:37:22 +08:00
geom_hline(yintercept=c(-0.01, 0.01),
linetype="dashed", color="red") +
2020-10-16 21:55:52 +08:00
2020-10-23 16:53:39 +08:00
# Draw boxplots
geom_boxplot() +
2020-10-16 21:55:52 +08:00
2020-10-27 17:49:00 +08:00
#scale_y_continuous(breaks = scales::pretty_breaks(n = 10)) +
2020-10-16 21:55:52 +08:00
2020-10-23 16:53:39 +08:00
theme_bw() +
theme(plot.subtitle=element_text(size=8)) +
theme(legend.position = c(0.85, 0.85)) #+
2020-10-16 21:55:52 +08:00
# Render the plot
print(p)
2020-10-23 16:53:39 +08:00
## Save the png image
dev.off()
#
2020-10-23 16:53:39 +08:00
png("scatter.png", width=w*ppi, height=h*ppi, res=ppi)
#
2020-10-23 16:53:39 +08:00
## Create the plot with the normalized time vs nblocks
2020-11-02 17:37:22 +08:00
p = ggplot(D, aes(x=blocksPerCpuFactor, y=time)) +
2020-10-23 16:53:39 +08:00
2020-11-02 17:37:22 +08:00
labs(x="Blocks/CPU", y="Time (s)",
2020-10-23 16:53:39 +08:00
title=sprintf("Nbody granularity. Particles=%d", particles),
subtitle=input_file) +
theme_bw() +
theme(plot.subtitle=element_text(size=8)) +
theme(legend.position = c(0.5, 0.88)) +
2020-11-02 17:37:22 +08:00
geom_point(shape=21, size=3) +
#scale_x_continuous(trans=log2_trans()) +
scale_y_continuous(trans=log2_trans())
2020-10-23 16:53:39 +08:00
# Render the plot
print(p)
2020-10-16 21:55:52 +08:00
# Save the png image
2020-10-23 16:53:39 +08:00
dev.off()