mandelbrot_def.jl 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. include("mandelbrot.jl")
  2. function mandelbrot_with_starpu(A ::Matrix{Int64}, params ::Vector{Float64}, nslicesx ::Int64, nslicesy ::Int64) #mettre params en matrice. (pour que starpu le traite en matrice et non vecteur)
  3. vert = StarpuDataFilter(STARPU_MATRIX_FILTER_VERTICAL_BLOCK, nslicesy)
  4. horiz = StarpuDataFilter(STARPU_MATRIX_FILTER_BLOCK, nslicesx)
  5. @starpu_block let
  6. hA = starpu_data_register(A)
  7. hP = starpu_data_register(params)
  8. starpu_data_map_filters(hA, vert, horiz)
  9. @starpu_sync_tasks for tasky in (1:nslicesy)
  10. for taskx in (1 : nslicesx)
  11. @starpu_block let
  12. v = Int64[tasky, taskx] #C'est le x qu'on augmente en fonction du nombre de slicey. Si il y a trois colonnes, x sera coupé en 3. Donc on inverse dans v.
  13. hV = starpu_data_register(v)
  14. @starpu_async_cl cl(hA[tasky, taskx], hP, hV)
  15. end
  16. end
  17. end
  18. end
  19. return nothing
  20. end
  21. function mandelbrot_with_starpu_cpu(A ::Matrix{Int64}, params ::Vector{Float64}, nslicesx ::Int64, nslicesy ::Int64) #mettre params en matrice. (pour que starpu le traite en matrice et non vecteur)
  22. vert = StarpuDataFilter(STARPU_MATRIX_FILTER_VERTICAL_BLOCK, nslicesy)
  23. horiz = StarpuDataFilter(STARPU_MATRIX_FILTER_BLOCK, nslicesx)
  24. @starpu_block let
  25. hA = starpu_data_register(A)
  26. hP = starpu_data_register(params)
  27. starpu_data_map_filters(hA, vert, horiz)
  28. @starpu_sync_tasks for tasky in (1:nslicesy)
  29. for taskx in (1 : nslicesx)
  30. v = Int64[tasky, taskx] #C'est le x qu'on augmente en fonction du nombre de slicey. Si il y a trois colonnes, x sera coupé en 3. Donc on inverse dans v.
  31. hV = starpu_data_register(v)
  32. @starpu_async_cl clcpu(hA[tasky, taskx], hP, hV)
  33. end
  34. end
  35. end
  36. return nothing
  37. end
  38. function mandelbrot_with_starpu_gpu(A ::Matrix{Int64}, params ::Vector{Float64}, nslicesx ::Int64, nslicesy ::Int64) #mettre params en matrice. (pour que starpu le traite en matrice et non vecteur)
  39. vert = StarpuDataFilter(STARPU_MATRIX_FILTER_VERTICAL_BLOCK, nslicesx)
  40. horiz = StarpuDataFilter(STARPU_MATRIX_FILTER_BLOCK, nslicesy)
  41. @starpu_block let
  42. hA = starpu_data_register(A)
  43. hP = starpu_data_register(params)
  44. starpu_data_map_filters(hA, vert, horiz)
  45. @starpu_sync_tasks for taskx in (1:nslicesx)
  46. for tasky in (1 : nslicesy)
  47. v = Int64[taskx, tasky] #C'est le x qu'on augmente en fonction du nombre de slicey. Si il y a trois colonnes, x sera coupé en 3. Donc on inverse dans v.
  48. hV = starpu_data_register(v)
  49. @starpu_async_cl clgpu(hA[taskx, tasky], hP, hV)
  50. end
  51. end
  52. end
  53. return nothing
  54. end
  55. function init_zero(Pixels ::Matrix{Int64}, width ::Int64, height ::Int64)
  56. for i in 1:height
  57. for j in 1:width
  58. Pixels[i,j] = 0
  59. end
  60. end
  61. end
  62. function graph_pixels(Pixels ::Matrix{Int64}, width ::Int64, height ::Int64, filename ::String)
  63. open(filename, "w") do f
  64. write(f, "P3\n$width $height\n255\n")
  65. for i = 1:height
  66. for j = 1:width
  67. write(f, "$(Pixels[i,j]) 0 0 ")
  68. end
  69. write(f, "\n")
  70. end
  71. end
  72. end
  73. function median_times(nbr_tests ::Int64, cr ::Float64, ci ::Float64, dim ::Int64, nslices ::Int64)
  74. exec_times_st ::Vector{Float64} = [0 for i = 1:nbr_tests]
  75. exec_times_cpu ::Vector{Float64} = [0 for i = 1:nbr_tests]
  76. exec_times_gpu ::Vector{Float64} = [0 for i = 1:nbr_tests]
  77. exec_times_jl ::Vector{Float64} = [0 for i = 1:nbr_tests]
  78. Pixels_st ::Matrix{Int64} = zeros(dim, dim)
  79. Pixels_cpu ::Matrix{Int64} = copy(Pixels_st)
  80. Pixels_gpu ::Matrix{Int64} = copy(Pixels_st)
  81. Pixels_jl ::Matrix{Int64} = copy(Pixels_st)
  82. max_iter ::Float64 = (dim/2) * 0.049715909 * log10(dim * 0.25296875)
  83. params = [cr, ci, dim, dim, max_iter]
  84. for i = 1:nbr_tests
  85. tic()
  86. mandelbrot_with_starpu(Pixels_st, params, nslices, nslices)
  87. t = toq()
  88. exec_times_st[i] = t
  89. # tic()
  90. # mandelbrot_with_starpu_cpu(Pixels_cpu, params, nslices, nslices)
  91. # t = toq()
  92. # exec_times_cpu[i] = t
  93. # tic()
  94. # mandelbrot_with_starpu_gpu(Pixels_gpu, params, nslices, nslices)
  95. # t = toq()
  96. # exec_times_gpu[i] = t
  97. # tic()
  98. # mandelbrotjl(Pixels_jl, cr, ci)
  99. # t = toq()
  100. # exec_times_jl[i] = t
  101. end
  102. # graph_pixels(Pixels_st, dim, dim, "../PPM/mandelbrotst$(dim).ppm")
  103. # graph_pixels(Pixels_cpu, dim, dim, "../PPM/mandelbrotcpu$(dim).ppm")
  104. # graph_pixels(Pixels_gpu, dim, dim, "../PPM/mandelbrotgpu$(dim).ppm")
  105. # graph_pixels(Pixels_jl, dim, dim, "../PPM/mandelbrotjl$(dim).ppm")
  106. sort!(exec_times_st)
  107. # sort!(exec_times_cpu)
  108. # sort!(exec_times_gpu)
  109. # sort!(exec_times_jl)
  110. results ::Vector{Float64} = [exec_times_st[1 + div(nbr_tests-1, 2)]]
  111. # results ::Vector{Float64} = [exec_times_st[1 + div(nbr_tests-1, 2)]]#, exec_times_cpu[1 + div(nbr_tests-1, 2)], exec_times_gpu[1 + div(nbr_tests-1, 2)]]#, exec_times_jl[1 + div(nbr_tests-1, 2)]]
  112. return results
  113. end
  114. function display_time(cr ::Float64, ci ::Float64, start_dim ::Int64, step_dim ::Int64, stop_dim ::Int64, nslices ::Int64, nbr_tests ::Int64)
  115. # mtc = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_c.dat") do f
  116. # readlines(f)
  117. # end)
  118. # mtgen = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_with_generated_times.dat") do f
  119. # readlines(f)
  120. # end)
  121. mtjl = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_jl_times.dat") do f
  122. readlines(f)
  123. end)
  124. # mtjlcpu = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_jl_cpu.dat") do f
  125. # readlines(f)
  126. # end)
  127. mtstruct = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_c_struct_times.dat") do f
  128. readlines(f)
  129. end)
  130. mtarray = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_c_array_times.dat") do f
  131. readlines(f)
  132. end)
  133. i = 1
  134. # open("../DAT/mandelbrot.dat", "w") do f
  135. # open("../DAT/mandelbrot_gen_times.dat", "w") do ft
  136. open("../DAT/mandelbrot_speedups.dat", "w") do f
  137. for dim in (start_dim : step_dim : stop_dim)
  138. println("Dimension: $dim")
  139. res ::Vector{Float64} = median_times(nbr_tests, cr, ci, dim, nslices)
  140. # println("C: $(mtc[i])")
  141. # println("C with generated: $(mtgen[i])")
  142. # println("Julia with starpu: $(res[1])")
  143. # println("cpu: $(res[2])")
  144. println("c_struct: $(mtstruct[i])")
  145. println("c_array: $(mtarray[i])")
  146. println("jl_st: $(res[1])")
  147. # println("cpu: $(res[1])")
  148. # write(ft, "$(dim) $(res[1]) $(mtgen[i])\n")
  149. # write(f, "$(dim) $(res[4]/res[1]) $(res[4]/res[2]) $(res[4]/res[3]) $(res[4]/mtc[i])\n")
  150. write(f, "$(dim) $(mtjl[i]/res[1]) $(mtjl[i]/mtstruct[i]) $(mtjl[i]/mtarray[i])\n")
  151. # write(f, "$(res[1])\n")
  152. i = i + 1
  153. end
  154. end
  155. end