]> AND Private Git Repository - loba-papers.git/blob - loba-besteffort/data/script.r
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Use grey levels for graphs.
[loba-papers.git] / loba-besteffort / data / script.r
1 ## Usage: launch R, and then: source("script.r")
2
3 ## save, and chane default options
4 osp <- options("scipen")
5 options(scipen=3)
6
7 ## load dataset (variable is "ds")
8 load("data.rda")
9
10 ## extract data for plain algorithms, in real mode
11 #ds.base <- subset(ds, Mode == "R" & grepl("[lt]_plain", Algo))
12
13 ## extract data for one experiment
14 #xx <- subset(ds,
15 #             Mode == "R" & Distrib == 1 & Ratio == "1:1" &
16 #             Platform == "cluster" & Size == 16 & Topo == "line")
17
18
19
20 draw <- function(dset = ds,
21                  draw_mode = "R",
22                  draw_distrib = 1,
23                  draw_ratio = "1:1",
24                  draw_platform = "cluster",
25                  draw_topo = "hcube") {
26
27   ## extract desired data
28   dset <- subset(dset,
29                  Mode == draw_mode & Distrib == draw_distrib &
30                  Ratio == draw_ratio &
31                  Platform == draw_platform & Topo == draw_topo)
32
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), ]
37
38   ## finally, add an "Index" attribute(, for further processing
39   dset <- cbind(dset, Index=seq(1, length(dset$Size))) # FIXME
40
41   #print(dset)
42
43   ## save the graphical parameters
44   p <- par(no.readonly=TRUE)
45
46   par(mar=c(13, 4, 4, 4) + 0.1,         # change margins
47       mgp=c(11, 1, 0))
48
49   par(las=3)                           # always draw labels vertically
50
51   ## compute the time range: 0..max+20%
52   time_range <- c(0, range(dset$Conv_max)[2] * 1.2)
53
54   ## first draw the bars
55   barplot(dset$Conv_max, axes=FALSE, col="red",
56           names=dset$Algo,
57           ylim=time_range)
58   barplot(dset$Conv_avg, axes=FALSE, col="green",
59           add=TRUE)
60   barplot(dset$Idle_avg, axes=FALSE, col="blue",
61           add=TRUE)
62
63   ## draw the time axis on the left
64   axis(2, labels=TRUE)
65   mtext("Simulated time (s)", side=2, line=2.5)
66
67   title(xlab="Algorithms")
68
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)
72
73   ## draw the data amnt line graphs
74   for (alg in unique(dset$Algo)) {
75     print(alg);
76     dset.da <- subset(dset, Algo == alg)
77     ## start a new graph, but drawn on the same device
78     par(new=TRUE)
79     plot(dset.da$Index, dset.da$Data_amnt, axes=FALSE, xlab="", type="b",
80          xlim=x_data_range,
81          yaxs="i", ylim=data_range)
82   }
83
84   ## draw the data amnt axis on the right
85   axis(4, labels=TRUE)
86   mtext("Data amount (relative)", side=4, line=2.5)
87
88   ## finally, set title
89   t <- paste0(dset$Mode[1], dset$Distrib[1], " / ",
90               dset$Ratio[1], " / ",
91               dset$Platform[1], " / ", dset$Topo[1])
92   title(main=t)
93
94   ## restore the graphical parameters
95   par(p)
96
97   return(dset)
98 }
99
100 draw2 <- function(dset = ds,
101                  draw_mode = "R",
102                  draw_distrib = 1,
103                  draw_ratio = "1:1",
104                  draw_platform = "cluster",
105                  draw_topo = "hcube") {
106
107   ## extract desired data
108   dset <- subset(dset,
109                  Mode == draw_mode & Distrib == draw_distrib &
110                  Ratio == draw_ratio &
111                  Platform == draw_platform & Topo == draw_topo)
112
113   ## reorder lines (first "plain", then "bookkeeping")
114   dset <- rbind(subset(dset, grepl("plain", Algo)),
115                 subset(dset, grepl("bookkeeping", Algo)))
116   dset <- dset[order(dset$Size), ]
117
118   ## keep only useful data
119   dset.long <- data.frame(Algo=dset$Algo, Size=dset$Size,
120                           Idle_avg=dset$Idle_avg,
121                           Conv_avg=dset$Conv_avg,
122                           Conv_max=dset$Conv_max)
123
124   ## reshape data -> wide
125   dset.wide <- reshape(dset.long, direction="wide",
126                        idvar="Algo", timevar="Size")
127
128   ## rename rows
129   rownames(dset.wide) <- sub("bookkeeping", "virtual", dset.wide$Algo)
130   #colnames(dset.wide) <- sub("^[^.]*\\.", "", colnames(dset.wide))
131
132   ## remove first column (aka "Algo")
133   dset.mat <- as.matrix(dset.wide[-1])
134   nc <- nrow(dset.mat)
135
136   dset.plot <- dset.mat[, c(FALSE,FALSE,TRUE)]
137   barplot(dset.plot, beside=TRUE,
138           names.arg=sub("^[^.]*\\.", "", colnames(dset.plot)),
139           col=gray.colors(nc)
140 #          col=rainbow(nc, s=.5)
141           )
142
143   dset.plot <- dset.mat[, c(FALSE,TRUE,FALSE)]
144   barplot(dset.plot, beside=TRUE,
145           axes=FALSE, axisnames=FALSE, add=TRUE,
146           legend.text=TRUE,
147           args.legend=list(x="topleft", inset=c(.02,0), title="Algorithms"),
148           col=gray.colors(nc)
149 #          col=rainbow(nc)
150           )
151
152   dset.plot <- dset.mat[, c(TRUE,FALSE,FALSE)]
153   barplot(dset.plot, beside=TRUE,
154           axes=FALSE, axisnames=FALSE, add=TRUE,
155           col="white"
156 #          col=rainbow(nc, v=.5)
157           )
158
159   ## finally, set titles
160   t <- paste0(dset$Mode[1], dset$Distrib[1], " / ",
161               dset$Ratio[1], " / ",
162               dset$Platform[1], " / ", dset$Topo[1])
163   title(xlab="Platform size",
164         ylab="Simulated time (s)",
165         main=t)
166
167 }
168
169 msg <- function(text,
170                 wait = TRUE) {
171   if (wait)
172     readline("Press <Enter> to continue\n")
173   message(text)
174 }
175
176 if (FALSE) {
177 msg("First test, with algorithms \"plain\"...", wait = FALSE);
178 draw(subset(ds, grepl("[lt]_plain", Algo)), draw_distrib="N")
179
180 msg("... with draw2()...")
181 draw2(subset(ds, grepl("[lt]_plain", Algo)), draw_distrib="N")
182
183 msg("Second test, with algorithms \"bookkeeping\"...");
184 draw(subset(ds, grepl("[lt]_bookkeeping", Algo)), draw_distrib="N")
185
186 msg("... with draw2()...")
187 draw2(subset(ds, grepl("[lt]_bookkeeping", Algo)), draw_distrib="N")
188
189 msg("Third test, with all algorithms...");
190 draw(draw_distrib="N")
191
192 msg("... with draw2()...")
193 draw2(draw_distrib="N")
194 }
195
196 pdf.options(colormodel="grey")
197 system("mkdir -pv graphs")
198 for (m in c("R", "I")) {
199   for (d in c("1", "N")) {
200     for (r in c("10:1", "1:1", "1:10")) {
201       for (t in c("line", "torus", "hcube")) {
202         for (p in c("grid", "cluster")) {
203           message(sprintf(">>> Drawing: %s%s / %s / %s / %s", m, d, r, p, t))
204           filename <- sprintf("graphs/%s%s-%s-%s-%s.pdf", m, d, r, p, t)
205           pdf(file=filename)
206           draw2(#subset(ds, grepl("[lt]_plain", Algo)),
207                 draw_mode=m, draw_distrib=d, draw_ratio=r,
208                 draw_topo=t, draw_platform=p)
209           dev.off()
210           embedFonts(file=filename, options="-dPDFSETTINGS=/prepress")
211         }
212       }
213     }
214   }
215 }
216
217 ## restore default options
218 options(scipen=osp)