1 ## Usage: launch R, and then: source("script.r")
3 ## save, and chane default options
4 osp <- options("scipen")
7 ## load dataset (variable is "ds")
10 ## extract data for plain algorithms, in real mode
11 #ds.base <- subset(ds, Mode == "R" & grepl("[lt]_plain", Algo))
13 ## extract data for one experiment
15 # Mode == "R" & Distrib == 1 & Ratio == "1:1" &
16 # Platform == "cluster" & Size == 16 & Topo == "line")
20 draw <- function(dset = ds,
24 draw_platform = "cluster",
25 draw_topo = "hcube") {
27 ## extract desired data
29 Mode == draw_mode & Distrib == draw_distrib &
31 Platform == draw_platform & Topo == draw_topo)
33 ## reorder lines (first "plain", then "bookkeeping")
34 dset <- rbind(subset(dset, grepl("plain", Algo)),
35 subset(dset, grepl("bookkeeping", Algo)))
36 dset <- dset[order(dset$Size), ]
38 ## finally, add an "Index" attribute(, for further processing
39 dset <- cbind(dset, Index=seq(1, length(dset$Size))) # FIXME
43 ## save the graphical parameters
44 p <- par(no.readonly=TRUE)
46 par(mar=c(13, 4, 4, 4) + 0.1, # change margins
49 par(las=3) # always draw labels vertically
51 ## compute the time range: 0..max+20%
52 time_range <- c(0, range(dset$Conv_max)[2] * 1.2)
54 ## first draw the bars
55 barplot(dset$Conv_max, axes=FALSE, col="red",
58 barplot(dset$Conv_avg, axes=FALSE, col="green",
60 barplot(dset$Idle_avg, axes=FALSE, col="blue",
63 ## draw the time axis on the left
65 mtext("Simulated time (s)", side=2, line=2.5)
67 title(xlab="Algorithms")
69 ## compute the data range
70 x_data_range <- c(0.6, length(dset$Algo) + 0.4)
71 data_range <- c(0, range(dset$Data_amnt)[2] * 1.04)
73 ## draw the data amnt line graphs
74 for (alg in unique(dset$Algo)) {
76 dset.da <- subset(dset, Algo == alg)
77 ## start a new graph, but drawn on the same device
79 plot(dset.da$Index, dset.da$Data_amnt, axes=FALSE, xlab="", type="b",
81 yaxs="i", ylim=data_range)
84 ## draw the data amnt axis on the right
86 mtext("Data amount (relative)", side=4, line=2.5)
89 t <- paste0(dset$Mode[1], dset$Distrib[1], " / ",
91 dset$Platform[1], " / ",
95 ## restore the graphical parameters
101 draw2 <- function(dset = ds,
105 draw_platform = "cluster",
106 draw_topo = "hcube") {
108 ## extract desired data
110 Algo != "makhoul_bookkeeping" & #HIDE#
111 Mode == draw_mode & Distrib == draw_distrib &
112 Ratio == draw_ratio &
113 Platform == draw_platform & Topo == draw_topo)
115 ## reorder lines (first "plain", then "bookkeeping")
116 dset <- rbind(subset(dset, grepl("plain", Algo)),
117 subset(dset, grepl("bookkeeping", Algo)))
118 dset <- dset[order(dset$Size), ]
120 ## keep only useful data
121 dset.long <- data.frame(Algo=dset$Algo, Size=dset$Size,
122 Idle_avg=dset$Idle_avg,
123 Conv_avg=dset$Conv_avg,
124 Conv_max=dset$Conv_max)
126 ## reshape data -> wide
127 dset.wide <- reshape(dset.long, direction="wide",
128 idvar="Algo", timevar="Size")
131 names <- dset.wide$Algo
132 #HIDE# names <- sub("makhoul_plain", "a: Bertsekas and Tsitsiklis, plain", names)
133 names <- sub("makhoul_plain", "a: Bertsekas and Tsitsiklis", names)
134 names <- sub("besteffort_plain", "b: best effort, plain", names)
135 names <- sub("besteffort-k2_plain", "c: best effort, k=2, plain", names)
136 names <- sub("besteffort-k4_plain", "d: best effort, k=4, plain", names)
137 #HIDE# names <- sub("makhoul_bookkeeping", "e: Bertsekas and Tsitsiklis, virtual", names)
138 #HIDE# names <- sub("besteffort_bookkeeping", "f: best effort, virtual", names)
139 #HIDE# names <- sub("besteffort-k2_bookkeeping", "g: best effort, k=2, virtual", names)
140 #HIDE# names <- sub("besteffort-k4_bookkeeping", "h: best effort, k=4, virtual", names)
141 names <- sub("besteffort_bookkeeping", "e: best effort, virtual", names)
142 names <- sub("besteffort-k2_bookkeeping", "f: best effort, k=2, virtual", names)
143 names <- sub("besteffort-k4_bookkeeping", "g: best effort, k=4, virtual", names)
144 rownames(dset.wide) <- names
145 #colnames(dset.wide) <- sub("^[^.]*\\.", "", colnames(dset.wide))
147 ## remove first column (aka "Algo")
148 dset.mat <- as.matrix(dset.wide[-1])
151 dset.plot <- dset.mat[, c(FALSE,FALSE,TRUE)]
152 barplot(dset.plot, beside=TRUE,
154 # names.arg=sub("^[^.]*\\.", "", colnames(dset.plot)),
156 # col=rainbow(nc, s=.5)
159 dset.plot <- dset.mat[, c(FALSE,TRUE,FALSE)]
160 barplot(dset.plot, beside=TRUE,
161 axes=FALSE, axisnames=FALSE, add=TRUE,
163 args.legend=list(x="topleft", inset=c(.02,0), x.intersp=0.5, title="Algorithms"),
168 dset.plot <- dset.mat[, c(TRUE,FALSE,FALSE)]
169 barplot(dset.plot, beside=TRUE,
170 axes=FALSE, axisnames=FALSE, add=TRUE,
172 # col=gray.colors(nc)
173 # col=rainbow(nc, v=.5)
176 ## finally, set titles
177 c <- ncol(dset.plot) - 1
179 t <- intToUtf8(utf8ToInt("a") + l)
180 for (a in 1.5 + l + 8 * 0:c)
181 mtext(t, side=1, at=a)
184 for (s in sub("^[^.]*\\.", "", colnames(dset.plot))) {
185 mtext(s, side=1, line=1.5, at=a)
190 #HIDE# dset$Distrib[1], " / ",
191 dset$Ratio[1], " / ",
192 #HIDE# dset$Platform[1], " / ",
194 t <- sub("hcube", "hypercube", t)
195 title(xlab="Platform size",
196 ylab="Simulated time (s)",
204 draw2(draw_distrib="1")
205 draw2(draw_distrib="N")
207 msg <- function(text, wait = TRUE) {
209 readline("Press <Enter> to continue\n")
213 msg("First test, with algorithms \"plain\"...", wait = FALSE);
214 draw(subset(ds, grepl("[lt]_plain", Algo)), draw_distrib="N")
216 msg("... with draw2()...")
217 draw2(subset(ds, grepl("[lt]_plain", Algo)), draw_distrib="N")
219 msg("Second test, with algorithms \"bookkeeping\"...");
220 draw(subset(ds, grepl("[lt]_bookkeeping", Algo)), draw_distrib="N")
222 msg("... with draw2()...")
223 draw2(subset(ds, grepl("[lt]_bookkeeping", Algo)), draw_distrib="N")
225 msg("Third test, with all algorithms...");
226 draw(draw_distrib="N")
228 msg("... with draw2()...")
229 draw2(draw_distrib="N")
234 pdf.options(colormodel="grey")
235 system("mkdir -pv graphs")
236 for (m in c("R", "I")) {
237 for (d in c("1", "N")) {
238 for (r in c("10:1", "1:1", "1:10")) {
239 for (t in c("line", "torus", "hcube")) {
240 for (p in c("grid", "cluster")) {
241 message(sprintf(">>> Drawing: %s%s / %s / %s / %s", m, d, r, p, t))
242 filename <- sprintf("graphs/%s%s-%s-%s-%s.pdf", m, d, r, p, t)
244 draw2(#subset(ds, grepl("[lt]_plain", Algo)),
245 draw_mode=m, draw_distrib=d, draw_ratio=r,
246 draw_topo=t, draw_platform=p)
248 embedFonts(file=filename, options="-dPDFSETTINGS=/prepress")
255 ## restore default options