random.r 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. list <- handle_size(size, sched);
  45. gflopstab <- c(gflopstab, list);
  46. sizetab <- c(sizetab, array(size, c(length(list))));
  47. }
  48. return(
  49. data.frame(gflops=gflopstab, size=sizetab, sched=array(sched, c(length(gflopstab)) ))
  50. );
  51. }
  52. handle_sched_mean <- function(sched)
  53. {
  54. meantab <- NULL;
  55. sizetab <- NULL;
  56. for (size in sizelist) {
  57. list <- mean(handle_size(size, sched));
  58. meantab <- c(meantab, list);
  59. sizetab <- c(sizetab, array(size, c(length(list))));
  60. }
  61. return(
  62. data.frame(gflops=meantab, size=sizetab, sched=array(sched, c(length(meantab)) ))
  63. # meantab
  64. );
  65. }
  66. handle_sched_max <- function(sched)
  67. {
  68. gflopstab <- NULL;
  69. sizetab <- NULL;
  70. for (size in sizelist) {
  71. prout <- handle_size(size, sched);
  72. list <- max(prout);
  73. print(list);
  74. gflopstab <- c(gflopstab, list);
  75. sizetab <- c(sizetab, size);
  76. }
  77. return(
  78. data.frame(gflops=gflopstab, size=sizetab, sched=array(sched, c(length(gflopstab)) ))
  79. );
  80. }
  81. handle_sched_min <- function(sched)
  82. {
  83. gflopstab <- NULL;
  84. sizetab <- NULL;
  85. for (size in sizelist) {
  86. list <- min((handle_size(size, sched)));
  87. print("MIN"); print( list);
  88. gflopstab <- c(gflopstab, list);
  89. sizetab <- c(sizetab, size);
  90. }
  91. return(
  92. data.frame(gflops=gflopstab, size=sizetab, sched=array(sched, c(length(gflopstab)) ))
  93. );
  94. }
  95. trace_sched <- function(sched, color, style, prout)
  96. {
  97. #lines(handle_sched_mean(sched)$size, handle_sched_mean(sched)$gflops, col=color, legend.text=TRUE);
  98. if (length(handle_sched_mean(sched)))
  99. {
  100. if (prout)
  101. {
  102. #for (size in sizelist)
  103. #{
  104. # #lines(array(size, c(length( handle_size(size, sched) )) ), handle_size(size, sched));
  105. #}
  106. convexx <- NULL;
  107. convexy <- NULL;
  108. for (point in (handle_sched_min(sched)$size))
  109. {
  110. convexx <- c(convexx, point);
  111. }
  112. for (point in (handle_sched_min(sched)$gflops))
  113. {
  114. convexy <- c(convexy, point);
  115. }
  116. for (point in (handle_sched_max(sched)$size))
  117. {
  118. convexx <- c(point, convexx);
  119. }
  120. for (point in (handle_sched_max(sched)$gflops))
  121. {
  122. convexy <- c(point, convexy);
  123. }
  124. #lines(handle_sched_min(sched)$size, handle_sched_min(sched)$gflops);
  125. #lines(handle_sched_max(sched)$size, handle_sched_max(sched)$gflops);
  126. polygon(convexx, convexy, col="light gray", border=-1);
  127. lines(handle_sched_mean(sched)$size, handle_sched_mean(sched)$gflops, col=color, type = "o", pch=style, lty=2, lwd=2);
  128. }
  129. else
  130. {
  131. lines(handle_sched_mean(sched)$size, handle_sched_mean(sched)$gflops, col=color, type = "o", pch=style, lwd=2);
  132. }
  133. };
  134. }
  135. display_sched <- function()
  136. {
  137. xlist <- range(sizelist);
  138. ylist <- range(c(0,110));
  139. plot.new();
  140. plot.window(xlist, ylist);
  141. trace_sched("random", "blue",1, 1);
  142. #trace_sched("dm", "black", 0, 0);
  143. trace_sched("greedy", "red", 2, 0);
  144. axis(1, at=sizelist)
  145. axis(2, at=seq(0, 120, 10), tck=1, cex=1.6)
  146. # axis(4, at=seq(0, 120, 10))
  147. box(bty="u", cex=1.6)
  148. labels <- c("greedy", "weighted random (mean)")
  149. 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)
  150. mtext("matrix size", side=1, line=2, cex=1.6)
  151. mtext("GFlops", side=2, line=2, las=0, cex=1.6)
  152. title("Matrix Multiplication");
  153. }
  154. display_sched()