random.r 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2010 Université de Bordeaux 1
  4. # Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. #
  6. # StarPU is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU Lesser General Public License as published by
  8. # the Free Software Foundation; either version 2.1 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # StarPU is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. #
  15. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. schedlist <- c("greedy", "random");
  17. sizelist <- seq(2048, 16384, 1024);
  18. #sizelist <- seq(2048, 16384, 2048);
  19. print(schedlist);
  20. print(sizelist);
  21. gflops <- function (x, size)
  22. {
  23. (2*size*size*size)/(1000000*x);
  24. }
  25. parse <- function (size, sched)
  26. {
  27. filename = paste("timings-sched/sched", sched, size, sep=".");
  28. if (file.exists(filename))
  29. { ret <- scan(paste("timings-sched/sched", sched, size, sep="."));
  30. return(ret);
  31. };
  32. return(NULL);
  33. }
  34. handle_size <- function (size, sched)
  35. {
  36. gflops <- gflops(parse(size, sched), size);
  37. return(gflops);
  38. }
  39. handle_sched <- function(sched)
  40. {
  41. gflopstab <- NULL;
  42. sizetab <- NULL;
  43. for (size in sizelist)
  44. {
  45. list <- handle_size(size, sched);
  46. gflopstab <- c(gflopstab, list);
  47. sizetab <- c(sizetab, array(size, c(length(list))));
  48. }
  49. return(
  50. data.frame(gflops=gflopstab, size=sizetab, sched=array(sched, c(length(gflopstab)) ))
  51. );
  52. }
  53. handle_sched_mean <- function(sched)
  54. {
  55. meantab <- NULL;
  56. sizetab <- NULL;
  57. for (size in sizelist)
  58. {
  59. list <- mean(handle_size(size, sched));
  60. meantab <- c(meantab, list);
  61. sizetab <- c(sizetab, array(size, c(length(list))));
  62. }
  63. return(
  64. data.frame(gflops=meantab, size=sizetab, sched=array(sched, c(length(meantab)) ))
  65. # meantab
  66. );
  67. }
  68. handle_sched_max <- function(sched)
  69. {
  70. gflopstab <- NULL;
  71. sizetab <- NULL;
  72. for (size in sizelist)
  73. {
  74. prout <- handle_size(size, sched);
  75. list <- max(prout);
  76. print(list);
  77. gflopstab <- c(gflopstab, list);
  78. sizetab <- c(sizetab, size);
  79. }
  80. return(
  81. data.frame(gflops=gflopstab, size=sizetab, sched=array(sched, c(length(gflopstab)) ))
  82. );
  83. }
  84. handle_sched_min <- function(sched)
  85. {
  86. gflopstab <- NULL;
  87. sizetab <- NULL;
  88. for (size in sizelist)
  89. {
  90. list <- min((handle_size(size, sched)));
  91. print("MIN"); print( list);
  92. gflopstab <- c(gflopstab, list);
  93. sizetab <- c(sizetab, size);
  94. }
  95. return(
  96. data.frame(gflops=gflopstab, size=sizetab, sched=array(sched, c(length(gflopstab)) ))
  97. );
  98. }
  99. trace_sched <- function(sched, color, style, prout)
  100. {
  101. #lines(handle_sched_mean(sched)$size, handle_sched_mean(sched)$gflops, col=color, legend.text=TRUE);
  102. if (length(handle_sched_mean(sched)))
  103. {
  104. if (prout)
  105. {
  106. #for (size in sizelist)
  107. #{
  108. # #lines(array(size, c(length( handle_size(size, sched) )) ), handle_size(size, sched));
  109. #}
  110. convexx <- NULL;
  111. convexy <- NULL;
  112. for (point in (handle_sched_min(sched)$size))
  113. {
  114. convexx <- c(convexx, point);
  115. }
  116. for (point in (handle_sched_min(sched)$gflops))
  117. {
  118. convexy <- c(convexy, point);
  119. }
  120. for (point in (handle_sched_max(sched)$size))
  121. {
  122. convexx <- c(point, convexx);
  123. }
  124. for (point in (handle_sched_max(sched)$gflops))
  125. {
  126. convexy <- c(point, convexy);
  127. }
  128. #lines(handle_sched_min(sched)$size, handle_sched_min(sched)$gflops);
  129. #lines(handle_sched_max(sched)$size, handle_sched_max(sched)$gflops);
  130. polygon(convexx, convexy, col="light gray", border=-1);
  131. lines(handle_sched_mean(sched)$size, handle_sched_mean(sched)$gflops, col=color, type = "o", pch=style, lty=2, lwd=2);
  132. }
  133. else
  134. {
  135. lines(handle_sched_mean(sched)$size, handle_sched_mean(sched)$gflops, col=color, type = "o", pch=style, lwd=2);
  136. }
  137. };
  138. }
  139. display_sched <- function()
  140. {
  141. xlist <- range(sizelist);
  142. ylist <- range(c(0,110));
  143. plot.new();
  144. plot.window(xlist, ylist);
  145. trace_sched("random", "blue",1, 1);
  146. #trace_sched("dm", "black", 0, 0);
  147. trace_sched("greedy", "red", 2, 0);
  148. axis(1, at=sizelist)
  149. axis(2, at=seq(0, 120, 10), tck=1, cex=1.6)
  150. # axis(4, at=seq(0, 120, 10))
  151. box(bty="u", cex=1.6)
  152. labels <- c("greedy", "weighted random (mean)")
  153. legend("bottomright", inset=.05, title="Scheduling policy", labels, lwd=2, pch=c(2, 1),lty=c(1, 2), col=c("red", "blue" ), bty="y", bg="white", cex=1.6)
  154. mtext("matrix size", side=1, line=2, cex=1.6)
  155. mtext("GFlops", side=2, line=2, las=0, cex=1.6)
  156. title("Matrix Multiplication");
  157. }
  158. display_sched()