bscpkgs/garlic/fig/hpcg/oss.R

113 lines
4.0 KiB
R
Raw Normal View History

# This R program takes as argument the dataset that contains the results of the
# execution of the heat example experiment and produces some plots. All the
# knowledge to understand how this script works is covered by this nice R book:
#
# Winston Chang, R Graphics Cookbook: Practical Recipes for Visualizing Data,
# OReilly Media (2020). 2nd edition
#
# Which can be freely read it online here: https://r-graphics.org/
#
# Please, search in this book before copying some random (and probably oudated)
# reply on stack overflow.
# We load some R packages to import the required functions. We mainly use the
# tidyverse packages, which are very good for ploting data,
2020-11-06 02:59:47 +08:00
library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
2020-11-06 02:59:47 +08:00
library(scales)
library(jsonlite)
library(viridis, warn.conflicts = FALSE)
2020-11-06 02:59:47 +08:00
# Here we simply load the arguments to find the input dataset. If nothing is
# specified we use the file named `input` in the current directory.
# We can run this script directly using:
# Rscript <path-to-this-script> <input-dataset>
2020-11-06 02:59:47 +08:00
# Load the arguments (argv)
args = commandArgs(trailingOnly=TRUE)
2020-11-06 02:59:47 +08:00
# Set the input dataset if given in argv[1], or use "input" as default
if (length(args)>0) { input_file = args[1] } else { input_file = "input" }
2020-11-06 02:59:47 +08:00
df = jsonlite::stream_in(file(input_file), verbose=FALSE) %>%
2020-11-06 02:59:47 +08:00
# Then we flatten it, as it may contain dictionaries inside the columns
jsonlite::flatten() %>%
2020-11-06 02:59:47 +08:00
# Now the dataframe contains all the configuration of the units inside the
# columns named `config.*`, for example `config.cbs`. We first select only
# the columns that we need:
select(config.nblocks, config.ncommblocks, config.hw.cpusPerSocket, unit, time) %>%
2020-11-06 02:59:47 +08:00
# And then we rename those columns to something shorter:
rename(nblocks=config.nblocks,
ncommblocks=config.ncommblocks,
cpusPerSocket=config.hw.cpusPerSocket) %>%
2020-11-06 02:59:47 +08:00
mutate(blocksPerCpu = nblocks / cpusPerSocket) %>%
2020-11-06 02:59:47 +08:00
mutate(nblocks = as.factor(nblocks)) %>%
mutate(blocksPerCpu = as.factor(blocksPerCpu)) %>%
mutate(unit = as.factor(unit)) %>%
2020-11-06 02:59:47 +08:00
group_by(unit) %>%
2020-11-06 02:59:47 +08:00
# And compute some metrics which are applied to each group. For example we
# compute the median time within the runs of a unit:
mutate(median.time = median(time)) %>%
mutate(normalized.time = time / median.time - 1) %>%
mutate(log.median.time = log(median.time)) %>%
2020-11-06 02:59:47 +08:00
# Then, we remove the grouping. This step is very important, otherwise the
# plotting functions get confused:
ungroup()
2020-11-06 02:59:47 +08:00
dpi=300
h=5
w=5
2020-11-06 02:59:47 +08:00
p = ggplot(df, aes(x=blocksPerCpu, y=normalized.time)) +
2020-11-06 02:59:47 +08:00
# The boxplots are useful to identify outliers and problems with the
# distribution of time
geom_boxplot() +
2020-11-06 02:59:47 +08:00
# We add a line to mark the 1% limit above and below the median
geom_hline(yintercept=c(-0.01, 0.01), linetype="dashed", color="red") +
2020-11-06 02:59:47 +08:00
# The bw theme is recommended for publications
theme_bw() +
2020-11-06 02:59:47 +08:00
# Here we add the title and the labels of the axes
labs(x="Blocks per CPU", y="Normalized time", title="HPCG granularity: normalized time",
subtitle=input_file) +
2020-11-06 02:59:47 +08:00
# And set the subtitle font size a bit smaller, so it fits nicely
theme(plot.subtitle=element_text(size=8))
2020-11-06 02:59:47 +08:00
# Then, we save the plot both in png and pdf
ggsave("normalized.time.png", plot=p, width=w, height=h, dpi=dpi)
ggsave("normalized.time.pdf", plot=p, width=w, height=h, dpi=dpi)
2020-11-06 02:59:47 +08:00
# We plot the time of each run as we vary the block size
p = ggplot(df, aes(x=blocksPerCpu, y=time)) +
2020-11-06 02:59:47 +08:00
# We add a points (scatter plot) using circles (shape=21) a bit larger
# than the default (size=3)
geom_point(shape=21, size=3) +
2020-11-06 02:59:47 +08:00
# The bw theme is recommended for publications
theme_bw() +
2020-11-06 02:59:47 +08:00
# Here we add the title and the labels of the axes
labs(x="Blocks Per CPU", y="Time (s)", title="HPCG granularity: time",
subtitle=input_file) +
2020-11-06 02:59:47 +08:00
# And set the subtitle font size a bit smaller, so it fits nicely
theme(plot.subtitle=element_text(size=8))
2020-11-06 02:59:47 +08:00
# Then, we save the plot both in png and pdf
ggsave("time.png", plot=p, width=w, height=h, dpi=dpi)
ggsave("time.pdf", plot=p, width=w, height=h, dpi=dpi)
2020-11-06 02:59:47 +08:00