nbody: add simple test figure

This commit is contained in:
Rodrigo Arias 2020-10-23 10:53:39 +02:00
parent 8ce88ef046
commit fd1229ddc0
2 changed files with 76 additions and 49 deletions

View File

@ -1,37 +1,53 @@
library(ggplot2) library(ggplot2)
library(dplyr) library(dplyr)
library(scales) library(scales)
library(jsonlite)
# Load the dataset args=commandArgs(trailingOnly=TRUE)
df=read.table("data.csv", col.names=c("blocksize", "time"))
bs_unique = unique(df$blocksize) # Read the timetable from args[1]
nbs=length(bs_unique) 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)
df$blocksPerCpuFactor = as.factor(df$blocksPerCpu)
# Normalize the time by the median # Normalize the time by the median
D=group_by(df, blocksize) %>% D=group_by(df, nblocks) %>%
mutate(tnorm = time / median(time) - 1) # %>% mutate(tnorm = time / median(time) - 1)
# mutate(bad = (abs(tnorm) >= 0.01)) %>%
# mutate(color = ifelse(bad,"red","black"))
D$bad = cut(abs(D$tnorm), breaks=c(-Inf, 0.01, +Inf), labels=c("good", "bad")) bs_unique = unique(df$nblocks)
nbs=length(bs_unique)
print(D) print(D)
#ppi=300 ppi=300
#h=5 h=5
#w=5 w=5
#png("box.png", width=w*ppi, height=h*ppi, res=ppi)
png("box.png", width=w*ppi, height=h*ppi, res=ppi)
# #
# #
# #
# Create the plot with the normalized time vs blocksize # Create the plot with the normalized time vs nblocks
p = ggplot(D, aes(x=blocksize, y=tnorm)) + p = ggplot(data=D, aes(x=blocksPerCpuFactor, y=tnorm)) +
# Labels # Labels
labs(x="Block size", y="Normalized time", labs(x="Blocks/CPU", y="Normalized time",
title="Nbody normalized time", title=sprintf("Nbody normalized time. Particles=%d", particles),
subtitle="@expResult@") + subtitle=input_file) +
# Center the title # Center the title
#theme(plot.title = element_text(hjust = 0.5)) + #theme(plot.title = element_text(hjust = 0.5)) +
@ -39,44 +55,49 @@ p = ggplot(D, aes(x=blocksize, y=tnorm)) +
# Black and white mode (useful for printing) # Black and white mode (useful for printing)
#theme_bw() + #theme_bw() +
# Draw boxplots # Add the maximum allowed error lines
geom_boxplot(aes(group=blocksize)) + geom_hline(yintercept=c(-0.01, 0.01),
linetype="dashed", color="red") +
# Use log2 scale in x # Draw boxplots
scale_x_continuous(trans=log2_trans(), geom_boxplot() +
breaks=bs_unique) +
scale_y_continuous(breaks = scales::pretty_breaks(n = 10)) + scale_y_continuous(breaks = scales::pretty_breaks(n = 10)) +
# Add the maximum allowed error lines theme_bw() +
geom_hline(yintercept=c(-0.01, 0.01),
linetype="dashed", color="red") theme(plot.subtitle=element_text(size=8)) +
theme(legend.position = c(0.85, 0.85)) #+
# Place each variant group in one separate plot
#facet_wrap(~jemalloc)
# Render the plot # Render the plot
print(p) 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 blocksize ## Save the png image
#p = ggplot(D, aes(x=blocksize, y=time, color=bad)) + dev.off()
# #
# labs(x="Blocksize", y="Time (s)", png("scatter.png", width=w*ppi, height=h*ppi, res=ppi)
# title="Nbody granularity",
# subtitle="@expResult@") +
# #
# geom_point(shape=21, size=1.5) + ## Create the plot with the normalized time vs nblocks
# scale_color_manual(values=c("black", "red")) + p = ggplot(D, aes(x=blocksPerCpuFactor, y=time)) +
# scale_x_continuous(trans=log2_trans(),
# breaks=bs_unique) + labs(x="Blocks/CPU", y="Time (s)",
# scale_y_continuous(trans=log2_trans()) title=sprintf("Nbody granularity. Particles=%d", particles),
# subtitle=input_file) +
## Render the plot theme_bw() +
#print(p) theme(plot.subtitle=element_text(size=8)) +
theme(legend.position = c(0.5, 0.88)) +
geom_point(shape=21, size=3) +
scale_y_continuous(trans=log2_trans())
# Render the plot
print(p)
# Save the png image # Save the png image
#dev.off() dev.off()

View File

@ -335,10 +335,11 @@ let
}; };
# Datasets used in the figures # Datasets used in the figures
ds = with self.bsc.garlic; { ds = with self.bsc.garlic; with pp; {
nbody = { nbody = with exp.nbody; {
jemalloc = with exp.nbody; pp.merge [ baseline jemalloc ]; test = merge [ baseline ];
freeCpu = with exp.nbody; pp.merge [ baseline freeCpu ]; jemalloc = merge [ baseline jemalloc ];
freeCpu = merge [ baseline freeCpu ];
}; };
}; };
@ -346,6 +347,11 @@ let
fig = with self.bsc.garlic; { fig = with self.bsc.garlic; {
nbody = { nbody = {
test = pp.rPlot {
script = ./garlic/fig/nbody/test.R;
dataset = ds.nbody.test;
};
jemalloc = pp.rPlot { jemalloc = pp.rPlot {
script = ./garlic/fig/nbody/jemalloc.R; script = ./garlic/fig/nbody/jemalloc.R;
dataset = ds.nbody.jemalloc; dataset = ds.nbody.jemalloc;