1 ## Usage: launch R, and then: source("script.r")
3 ## load dataset (variable is "ds")
6 ## extract data for plain algorithms, in real mode
7 #ds.base <- subset(ds, Mode == "R" & grepl("[lt]_plain", Algo))
9 ## extract data for one experiment
11 # Mode == "R" & Distrib == 1 & Ratio == "1:1" &
12 # Platform == "cluster" & Size == 16 & Topo == "line")
16 draw <- function(dset = ds,
20 draw_platform = "cluster",
21 draw_topo = "hcube") {
23 ## extract desired data
25 Mode == draw_mode & Distrib == draw_distrib &
27 Platform == draw_platform & Topo == draw_topo)
29 ## reorder lines (first "plain", then "bookkeeping")
30 dset <- rbind(subset(dset, grepl("plain", Algo)),
31 subset(dset, grepl("bookkeeping", Algo)))
32 dset <- dset[order(dset$Size), ]
34 ## finally, add an "Index" attribute(, for further processing
35 dset <- cbind(dset, Index=seq(1, length(dset$Size))) # FIXME
39 ## save the graphical parameters
40 p <- par(no.readonly=TRUE)
43 ### - add some spacing between each size
44 ### - fill in empty rows (e.g. with large size)
45 ### - add a label telling the size
47 par(mar=c(13, 4, 4, 4) + 0.1, # change margins
50 par(las=3) # always draw labels vertically
52 ## compute the time range: 0..max+20%
53 time_range <- c(0, range(dset$Conv_max)[2] * 1.2)
55 ## first draw the bars
56 barplot(dset$Conv_max, axes=FALSE, col="red",
59 barplot(dset$Conv_avg, axes=FALSE, col="green",
61 barplot(dset$Idle_avg, axes=FALSE, col="blue",
64 ## draw the time axis on the left
66 mtext("Simulated Time (s)", side=2, line=2.5)
68 title(xlab="Algorithms")
70 ## compute the data range
71 x_data_range <- c(0.6, length(dset$Algo) + 0.4)
72 data_range <- c(0, range(dset$Data_amnt)[2] * 1.04)
74 ## draw the data amnt line graphs
75 for (alg in unique(dset$Algo)) {
77 dset.da <- subset(dset, Algo == alg)
78 ## start a new graph, but drawn on the same device
80 plot(dset.da$Index, dset.da$Data_amnt, axes=FALSE, xlab="", type="b",
82 yaxs="i", ylim=data_range)
85 ## draw the data amnt axis on the right
87 mtext("Data amount (relative)", side=4, line=2.5)
90 t <- paste0(dset$Mode[1], dset$Distrib[1], " / ",
92 dset$Platform[1], " / ", dset$Topo[1])
95 ## restore the graphical parameters
101 draw2 <- function(dset) {
102 ## Extract useful data
103 x.1 <- data.frame(Algo=dset$Algo, Size=dset$Size,
104 Idle_avg=dset$Idle_avg,
105 Conv_avg=dset$Conv_avg,
106 Conv_max=dset$Conv_max)
108 ## Reshape data -> wide
109 x.2 <- reshape(x.1, direction="wide", idvar="Algo", timevar="Size")
112 rownames(x.2) <- x.2$Algo
113 #colnames(x.2) <- sub("^[^.]*\\.", "", colnames(x.2))
115 ## Remove first column ("Algo")
116 x.3 <- as.matrix(x.2[-1])
118 x.4 <- x.3[, c(FALSE,FALSE,TRUE)]
119 barplot(x.4, beside=TRUE,
120 names.arg=sub("^[^.]*\\.", "", colnames(x.4)),
121 col=rainbow(nrow(x.3), s=.5))
123 x.4 <- x.3[, c(FALSE,TRUE,FALSE)]
124 barplot(x.4, beside=TRUE,
125 axes=FALSE, axisnames=FALSE, add=TRUE,
127 col=rainbow(nrow(x.3)))
129 x.4 <- x.3[, c(TRUE,FALSE,FALSE)]
130 barplot(x.4, beside=TRUE,
131 axes=FALSE, axisnames=FALSE, add=TRUE,
132 col=rainbow(nrow(x.3), v=.5))
134 ## finally, set titles
135 t <- paste0(dset$Mode[1], dset$Distrib[1], " / ",
136 dset$Ratio[1], " / ",
137 dset$Platform[1], " / ", dset$Topo[1])
138 title(xlab="Platform Size",
139 ylab="Simulated Time (s)",
144 msg <- function(text,
147 readline("Press <Enter> to continue\n")
151 msg("First test, with algorithms \"plain\"...", wait = FALSE);
152 xx <- draw(subset(ds, grepl("[lt]_plain", Algo)),
155 msg("... with draw2()...")
158 msg("Second test, with algorithms \"bookkeeping\"...");
159 xx <- draw(subset(ds, grepl("[lt]_bookkeeping", Algo)),
162 msg("... with draw2()...")
165 msg("Third test, with all algorithms...");
166 xx <- draw(draw_distrib="N")
168 msg("... with draw2()...")