bscpkgs/garlic/fig/nbody/old/scaling.R
Rodrigo Arias Mallo 92cd88e365 fig: use the $out path in the subtitle
The input dataset is not enough to determine which script produced a
given plot.
2021-04-21 13:40:25 +02:00

112 lines
2.6 KiB
R

library(ggplot2)
library(dplyr)
library(scales)
library(jsonlite)
args=commandArgs(trailingOnly=TRUE)
# Read the timetable from args[1]
input_file = "input.json"
if (length(args)>0) { input_file = args[1] }
if (length(args)>1) { output = args[2] } else { output = "?" }
# 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)
df$blocksPerCpuFactor = as.factor(df$blocksPerCpu)
# Normalize the time by the median
D=group_by(df, nblocks) %>%
mutate(tnorm = time / median(time) - 1) %>%
mutate(bad = max(ifelse(abs(tnorm) >= 0.01, 1, 0)))
D$bad = as.factor(D$bad)
#D$bad = as.factor(ifelse(abs(D$tnorm) >= 0.01, 2,
# ifelse(abs(D$tnorm) >= 0.005, 1, 0)))
bs_unique = unique(df$nblocks)
nbs=length(bs_unique)
print(D)
ppi=300
h=5
w=5
png("box.png", width=w*ppi, height=h*ppi, res=ppi)
#
#
#
# Create the plot with the normalized time vs nblocks
p = ggplot(data=D, aes(x=blocksPerCpuFactor, y=tnorm, color=bad)) +
# Labels
labs(x="Blocks/CPU", y="Normalized time",
title=sprintf("Nbody normalized time. Particles=%d", particles),
subtitle=output) +
# Center the title
#theme(plot.title = element_text(hjust = 0.5)) +
# Black and white mode (useful for printing)
#theme_bw() +
# Add the maximum allowed error lines
geom_hline(yintercept=c(-0.01, 0.01),
linetype="dashed", color="gray") +
# Draw boxplots
geom_boxplot() +
scale_color_manual(values=c("black", "brown")) +
#scale_y_continuous(breaks = scales::pretty_breaks(n = 10)) +
theme_bw() +
theme(plot.subtitle=element_text(size=8)) +
theme(legend.position = "none")
#theme(legend.position = c(0.85, 0.85))
# Render the plot
print(p)
## Save the png image
dev.off()
#
png("scatter.png", width=w*ppi, height=h*ppi, res=ppi)
#
## Create the plot with the normalized time vs nblocks
p = ggplot(D, aes(x=blocksPerCpuFactor, y=time)) +
labs(x="Blocks/CPU", y="Time (s)",
title=sprintf("Nbody granularity. Particles=%d", particles),
subtitle=output) +
theme_bw() +
theme(plot.subtitle=element_text(size=8)) +
theme(legend.position = c(0.5, 0.88)) +
geom_point(shape=21, size=3) +
#scale_x_continuous(trans=log2_trans()) +
scale_y_continuous(trans=log2_trans())
# Render the plot
print(p)
# Save the png image
dev.off()