cpu_mandelbrot_between.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <starpu.h>
  4. struct Params
  5. {
  6. float cr;
  7. float ci;
  8. unsigned taskx;
  9. unsigned tasky;
  10. unsigned width;
  11. unsigned height;
  12. };
  13. static inline long long jlstarpu_max(long long a, long long b)
  14. {
  15. return (a > b) ? a : b;
  16. }
  17. static inline long long jlstarpu_interval_size(long long start, long long step, long long stop)
  18. {
  19. if (stop >= start){
  20. return jlstarpu_max(0, (stop - start + 1) / step);
  21. } else {
  22. return jlstarpu_max(0, (stop - start - 1) / step);
  23. }
  24. }
  25. void mandelbrot(void** buffers_86BwRM71, void* cl_arg_86BwRM71)
  26. {
  27. uint32_t ld_o2BQqRir = (uint32_t) (STARPU_MATRIX_GET_LD(buffers_86BwRM71[(1) - (1)]));
  28. int64_t* ptr_o2BQqRir = (int64_t*) (STARPU_MATRIX_GET_PTR(buffers_86BwRM71[(1) - (1)]));
  29. //ARRAY PAR
  30. double* ptr_Ul4Ys0Mt = (double*) (STARPU_VECTOR_GET_PTR(buffers_86BwRM71[(2) - (1)]));
  31. int64_t* ptr_cE3zj60d = (int64_t*) (STARPU_VECTOR_GET_PTR(buffers_86BwRM71[(3) - (1)]));
  32. //
  33. int64_t local_width = (int64_t) (STARPU_MATRIX_GET_NY(buffers_86BwRM71[(1) - (1)]));
  34. int64_t local_height = (int64_t) (STARPU_MATRIX_GET_NX(buffers_86BwRM71[(1) - (1)]));
  35. double conv_limit = (double) (2.0);
  36. //STRUCT PAR
  37. /* struct Params *params = cl_arg_86BwRM71; */
  38. /* double centerr = params->cr; */
  39. /* double centeri = params->ci; */
  40. /* unsigned Idx = params->taskx; */
  41. /* unsigned Idy = params->tasky; */
  42. /* unsigned width = params->width; */
  43. /* unsigned height = params->height; */
  44. /* /\* printf("cr / ci: %f / %f\n", centerr, centeri); *\/ */
  45. /* int64_t zoom = width * 0.25296875; */
  46. /* int64_t max_iterations = (width/2) * 0.049715909 * log10(zoom); */
  47. //
  48. int64_t start_qxJwMzwA = (int64_t) (1);
  49. int64_t stop_qxJwMzwA = (int64_t) (local_width);
  50. int64_t x;
  51. for (x = start_qxJwMzwA ; x <= stop_qxJwMzwA ; x += 1)
  52. {
  53. int64_t start_ekV9GHK1 = (int64_t) (1);
  54. int64_t stop_ekV9GHK1 = (int64_t) (local_height);
  55. int64_t y;
  56. for (y = start_ekV9GHK1 ; y <= stop_ekV9GHK1 ; y += 1)
  57. {
  58. //ARRAY PAR
  59. double max_iterations = (double) (ptr_Ul4Ys0Mt[(5) - (1)]);
  60. double zoom = (double) ((ptr_Ul4Ys0Mt[(3) - (1)]) * (0.25296875));
  61. //
  62. //STRUCT PAR
  63. /* double X = x + Idy*local_width; */
  64. /* double Y = y + Idx*local_height; */
  65. /* double cr = centerr + (X - (width / 2))/zoom; */
  66. /* double ci = centeri + (Y - (height / 2))/zoom; */
  67. //
  68. //ARRAY PAR
  69. int64_t X = (int64_t) ((x) + ((local_width) * ((ptr_cE3zj60d[(2) - (1)]) - (1))));
  70. int64_t Y = (int64_t) ((y) + ((local_height) * ((ptr_cE3zj60d[(1) - (1)]) - (1))));
  71. double cr = (double) ((ptr_Ul4Ys0Mt[(1) - (1)]) + (((X) - ((ptr_Ul4Ys0Mt[(3) - (1)]) / (2))) / (zoom)));
  72. double ci = (double) ((ptr_Ul4Ys0Mt[(2) - (1)]) + (((Y) - ((ptr_Ul4Ys0Mt[(4) - (1)]) / (2))) / (zoom)));
  73. //
  74. double zi = (double) (ci);
  75. double zr = (double) (cr);
  76. int64_t n = (int64_t) (0);
  77. float m = zr * zr + zi * zi;
  78. /* int64_t b1 = (int64_t) (((n) < (max_iterations)) + ((((zr) * (zr)) + ((zi) * (zi))) < ((conv_limit) * (conv_limit)))); */
  79. /* while ((b1) >= (2)) */
  80. /* printf("%d\n", max_iterations); */
  81. for (n = 0; n < max_iterations && m < conv_limit * conv_limit; n++)
  82. {
  83. double tmp = (double) ((((zr) * (zr)) - ((zi) * (zi))) + (cr));
  84. zi = ((2) * (zr) * (zi)) + (ci);
  85. zr = tmp;
  86. /* n = (n) + (1); */
  87. m = zr*zr + zi*zi;
  88. /* b1 = ((n) <= (max_iterations)) + ((((zr) * (zr)) + ((zi) * (zi))) <= ((conv_limit) * (conv_limit))); */
  89. }
  90. ;
  91. /* printf("n: %d\n max_iter: %d\n", n, max_iterations); */
  92. if ((n) < (max_iterations))
  93. {
  94. ptr_o2BQqRir[((y) + (((x) - (1)) * (ld_o2BQqRir))) - (1)] = 255 * (1.0 * n / (max_iterations));
  95. } else
  96. {
  97. ptr_o2BQqRir[((y) + (((x) - (1)) * (ld_o2BQqRir))) - (1)] = 0;
  98. }
  99. ;
  100. }
  101. ;
  102. }
  103. ;
  104. }