-# Usage: launch R, and then: source("script.r")
+## Usage: launch R, and then: source("script.r")
-# load dataset (variable is "ds")
+## save, and chane default options
+osp <- options("scipen")
+options(scipen=3)
+
+## load dataset (variable is "ds")
load("data.rda")
-# extract data for plain algorithms, in real mode
-ds.base <- subset(ds, Mode == "R" & grepl("[lt]_plain", Algo))
+## extract data for plain algorithms, in real mode
+#ds.base <- subset(ds, Mode == "R" & grepl("[lt]_plain", Algo))
-# extract data for one experiment
+## extract data for one experiment
#xx <- subset(ds,
# Mode == "R" & Distrib == 1 & Ratio == "1:1" &
# Platform == "cluster" & Size == 16 & Topo == "line")
-xx <- subset(ds,
- Mode == "R" & Distrib == "N" & Ratio == "1:1" &
- Platform == "cluster" & Topo == "hcube")
-# only keep plain algorithms with default value for k...
-xx <- subset(xx, grepl("[lt]_plain", Algo))
-# reorder lines (first "plain", then "bookkeeping")
-xx <- rbind(subset(xx, grepl("plain", Algo)),
- subset(xx, grepl("bookkeeping", Algo)))
-xx <- xx[order(xx$Size), ]
+draw <- function(dset = ds,
+ draw_mode = "R",
+ draw_distrib = 1,
+ draw_ratio = "1:1",
+ draw_platform = "cluster",
+ draw_topo = "hcube") {
+
+ ## extract desired data
+ dset <- subset(dset,
+ Mode == draw_mode & Distrib == draw_distrib &
+ Ratio == draw_ratio &
+ Platform == draw_platform & Topo == draw_topo)
+
+ ## reorder lines (first "plain", then "bookkeeping")
+ dset <- rbind(subset(dset, grepl("plain", Algo)),
+ subset(dset, grepl("bookkeeping", Algo)))
+ dset <- dset[order(dset$Size), ]
+
+ ## finally, add an "Index" attribute(, for further processing
+ dset <- cbind(dset, Index=seq(1, length(dset$Size))) # FIXME
-# finally, add an "Index" attribute(, for further processing
-xx <- cbind(xx, Index=c(1:length(xx$Size)))
+ #print(dset)
-# save the graphical parameters
-p <- par(no.readonly=TRUE)
+ ## save the graphical parameters
+ p <- par(no.readonly=TRUE)
+ par(mar=c(13, 4, 4, 4) + 0.1, # change margins
+ mgp=c(11, 1, 0))
-### TODO
-### - add some spacing between each size
-### - fill in empty rows (e.g. with large size)
-### - add a label telling the size
+ par(las=3) # always draw labels vertically
-par(mar=c(13, 4, 4, 4) + 0.1, # change margins
- mgp=c(11, 1, 0))
+ ## compute the time range: 0..max+20%
+ time_range <- c(0, range(dset$Conv_max)[2] * 1.2)
-par(las=3) # always draw labels vertically
+ ## first draw the bars
+ barplot(dset$Conv_max, axes=FALSE, col="red",
+ names=dset$Algo,
+ ylim=time_range)
+ barplot(dset$Conv_avg, axes=FALSE, col="green",
+ add=TRUE)
+ barplot(dset$Idle_avg, axes=FALSE, col="blue",
+ add=TRUE)
-# compute the time range: 0..max+20%
-time_range <- c(0, range(xx$Conv_max)[2] * 1.2)
+ ## draw the time axis on the left
+ axis(2, labels=TRUE)
+ mtext("Simulated time (s)", side=2, line=2.5)
-# first draw the bars
-barplot(xx$Conv_max, axes=FALSE, col="red",
- names=xx$Algo,
- ylim=time_range)
-barplot(xx$Conv_avg, axes=FALSE, col="green",
- add=TRUE)
-barplot(xx$Idle_avg, axes=FALSE, col="blue",
- add=TRUE)
+ title(xlab="Algorithms")
-# draw the time axis on the left
-axis(2, labels=TRUE)
-mtext("Time (s)", side=2, line=2.5)
+ ## compute the data range
+ x_data_range <- c(0.6, length(dset$Algo) + 0.4)
+ data_range <- c(0, range(dset$Data_amnt)[2] * 1.04)
-title(xlab="Algorithms")
+ ## draw the data amnt line graphs
+ for (alg in unique(dset$Algo)) {
+ print(alg);
+ dset.da <- subset(dset, Algo == alg)
+ ## start a new graph, but drawn on the same device
+ par(new=TRUE)
+ plot(dset.da$Index, dset.da$Data_amnt, axes=FALSE, xlab="", type="b",
+ xlim=x_data_range,
+ yaxs="i", ylim=data_range)
+ }
-# start a new graph, but drawn on the same device
+ ## draw the data amnt axis on the right
+ axis(4, labels=TRUE)
+ mtext("Data amount (relative)", side=4, line=2.5)
+
+ ## finally, set title
+ t <- paste0(dset$Mode[1], dset$Distrib[1], " / ",
+ dset$Ratio[1], " / ",
+ dset$Platform[1], " / ", dset$Topo[1])
+ title(main=t)
+
+ ## restore the graphical parameters
+ par(p)
+
+ return(dset)
+}
-# compute the data range
-x_data_range <- c(0.6, length(xx$Algo) + 0.4)
-data_range <- c(0, range(xx$Data_amnt)[2] * 1.04)
+draw2 <- function(dset = ds,
+ draw_mode = "R",
+ draw_distrib = 1,
+ draw_ratio = "1:1",
+ draw_platform = "cluster",
+ draw_topo = "hcube") {
+
+ ## extract desired data
+ dset <- subset(dset,
+ Mode == draw_mode & Distrib == draw_distrib &
+ Ratio == draw_ratio &
+ Platform == draw_platform & Topo == draw_topo)
+
+ ## reorder lines (first "plain", then "bookkeeping")
+ dset <- rbind(subset(dset, grepl("plain", Algo)),
+ subset(dset, grepl("bookkeeping", Algo)))
+ dset <- dset[order(dset$Size), ]
+
+ ## keep only useful data
+ dset.long <- data.frame(Algo=dset$Algo, Size=dset$Size,
+ Idle_avg=dset$Idle_avg,
+ Conv_avg=dset$Conv_avg,
+ Conv_max=dset$Conv_max)
+
+ ## reshape data -> wide
+ dset.wide <- reshape(dset.long, direction="wide",
+ idvar="Algo", timevar="Size")
+
+ ## rename rows
+ rownames(dset.wide) <- sub("bookkeeping", "virtual", dset.wide$Algo)
+ #colnames(dset.wide) <- sub("^[^.]*\\.", "", colnames(dset.wide))
+
+ ## remove first column (aka "Algo")
+ dset.mat <- as.matrix(dset.wide[-1])
+
+ dset.plot <- dset.mat[, c(FALSE,FALSE,TRUE)]
+ barplot(dset.plot, beside=TRUE,
+ names.arg=sub("^[^.]*\\.", "", colnames(dset.plot)),
+ col=rainbow(nrow(dset.mat), s=.5))
+
+ dset.plot <- dset.mat[, c(FALSE,TRUE,FALSE)]
+ barplot(dset.plot, beside=TRUE,
+ axes=FALSE, axisnames=FALSE, add=TRUE,
+ legend.text=TRUE,
+ args.legend=list(x="topleft", inset=c(.02,0), title="Algorithms"),
+ col=rainbow(nrow(dset.mat)))
+
+ dset.plot <- dset.mat[, c(TRUE,FALSE,FALSE)]
+ barplot(dset.plot, beside=TRUE,
+ axes=FALSE, axisnames=FALSE, add=TRUE,
+ col=rainbow(nrow(dset.mat), v=.5))
+
+ ## finally, set titles
+ t <- paste0(dset$Mode[1], dset$Distrib[1], " / ",
+ dset$Ratio[1], " / ",
+ dset$Platform[1], " / ", dset$Topo[1])
+ title(xlab="Platform size",
+ ylab="Simulated time (s)",
+ main=t)
-# draw the data amnt line graph
-#par(new=TRUE)
-#plot(xx$Data_amnt, axes=FALSE, xlab="", type="b",
-# xlim=x_data_range,
-# yaxs="i", ylim=data_range)
+}
-for (alg in unique(xx$Algo)) {
- print(alg);
- yy <- subset(xx, Algo == alg)
- par(new=TRUE)
- plot(yy$Index, yy$Data_amnt, axes=FALSE, xlab="", type="b",
- xlim=x_data_range,
- yaxs="i", ylim=data_range)
+msg <- function(text,
+ wait = TRUE) {
+ if (wait)
+ readline("Press <Enter> to continue\n")
+ message(text)
}
-# draw the data amnt axis on the right
-axis(4, labels=TRUE)
-mtext("Data amount (relative)", side=4, line=2.5)
+if (FALSE) {
+msg("First test, with algorithms \"plain\"...", wait = FALSE);
+draw(subset(ds, grepl("[lt]_plain", Algo)), draw_distrib="N")
+
+msg("... with draw2()...")
+draw2(subset(ds, grepl("[lt]_plain", Algo)), draw_distrib="N")
+
+msg("Second test, with algorithms \"bookkeeping\"...");
+draw(subset(ds, grepl("[lt]_bookkeeping", Algo)), draw_distrib="N")
+
+msg("... with draw2()...")
+draw2(subset(ds, grepl("[lt]_bookkeeping", Algo)), draw_distrib="N")
-# finally, set title
-t <- paste0(xx$Mode[1], xx$Distrib[1], " / ", xx$Ratio[1], " / ",
- xx$Platform[1], " / ", xx$Topo[1])
-title(main=t)
+msg("Third test, with all algorithms...");
+draw(draw_distrib="N")
+
+msg("... with draw2()...")
+draw2(draw_distrib="N")
+}
+
+system("mkdir -pv graphs")
+for (m in c("R", "I")) {
+ for (d in c("1", "N")) {
+ for (r in c("10:1", "1:1", "1:10")) {
+ for (t in c("line", "torus", "hcube")) {
+ for (p in c("grid", "cluster")) {
+ message(sprintf(">>> Drawing: %s%s / %s / %s / %s", m, d, r, p, t))
+ pdf(file=sprintf("graphs/%s%s-%s-%s-%s.pdf", m, d, r, p, t))
+ draw2(#subset(ds, grepl("[lt]_plain", Algo)),
+ draw_mode=m, draw_distrib=d, draw_ratio=r,
+ draw_topo=t, draw_platform=p)
+ dev.off()
+ }
+ }
+ }
+ }
+}
-# restore the graphical parameters
-par(p)
+## restore default options
+options(scipen=osp)