cpu_mandelbrot_between.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2019 Mael Keryell
  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. */
  17. #include <stdio.h>
  18. #include <stdint.h>
  19. #include <starpu.h>
  20. struct Params
  21. {
  22. float cr;
  23. float ci;
  24. unsigned taskx;
  25. unsigned tasky;
  26. unsigned width;
  27. unsigned height;
  28. };
  29. static inline long long jlstarpu_max(long long a, long long b)
  30. {
  31. return (a > b) ? a : b;
  32. }
  33. static inline long long jlstarpu_interval_size(long long start, long long step, long long stop)
  34. {
  35. if (stop >= start){
  36. return jlstarpu_max(0, (stop - start + 1) / step);
  37. } else {
  38. return jlstarpu_max(0, (stop - start - 1) / step);
  39. }
  40. }
  41. void mandelbrot(void** buffers_86BwRM71, void* cl_arg_86BwRM71)
  42. {
  43. uint32_t ld_o2BQqRir = (uint32_t) (STARPU_MATRIX_GET_LD(buffers_86BwRM71[(1) - (1)]));
  44. int64_t* ptr_o2BQqRir = (int64_t*) (STARPU_MATRIX_GET_PTR(buffers_86BwRM71[(1) - (1)]));
  45. //ARRAY PAR
  46. double* ptr_Ul4Ys0Mt = (double*) (STARPU_VECTOR_GET_PTR(buffers_86BwRM71[(2) - (1)]));
  47. int64_t* ptr_cE3zj60d = (int64_t*) (STARPU_VECTOR_GET_PTR(buffers_86BwRM71[(3) - (1)]));
  48. //
  49. int64_t local_width = (int64_t) (STARPU_MATRIX_GET_NY(buffers_86BwRM71[(1) - (1)]));
  50. int64_t local_height = (int64_t) (STARPU_MATRIX_GET_NX(buffers_86BwRM71[(1) - (1)]));
  51. double conv_limit = (double) (2.0);
  52. //STRUCT PAR
  53. /* struct Params *params = cl_arg_86BwRM71; */
  54. /* double centerr = params->cr; */
  55. /* double centeri = params->ci; */
  56. /* unsigned Idx = params->taskx; */
  57. /* unsigned Idy = params->tasky; */
  58. /* unsigned width = params->width; */
  59. /* unsigned height = params->height; */
  60. /* /\* printf("cr / ci: %f / %f\n", centerr, centeri); *\/ */
  61. /* int64_t zoom = width * 0.25296875; */
  62. /* int64_t max_iterations = (width/2) * 0.049715909 * log10(zoom); */
  63. //
  64. int64_t start_qxJwMzwA = (int64_t) (1);
  65. int64_t stop_qxJwMzwA = (int64_t) (local_width);
  66. int64_t x;
  67. for (x = start_qxJwMzwA ; x <= stop_qxJwMzwA ; x += 1)
  68. {
  69. int64_t start_ekV9GHK1 = (int64_t) (1);
  70. int64_t stop_ekV9GHK1 = (int64_t) (local_height);
  71. int64_t y;
  72. for (y = start_ekV9GHK1 ; y <= stop_ekV9GHK1 ; y += 1)
  73. {
  74. //ARRAY PAR
  75. double max_iterations = (double) (ptr_Ul4Ys0Mt[(5) - (1)]);
  76. double zoom = (double) ((ptr_Ul4Ys0Mt[(3) - (1)]) * (0.25296875));
  77. //
  78. //STRUCT PAR
  79. /* double X = x + Idy*local_width; */
  80. /* double Y = y + Idx*local_height; */
  81. /* double cr = centerr + (X - (width / 2))/zoom; */
  82. /* double ci = centeri + (Y - (height / 2))/zoom; */
  83. //
  84. //ARRAY PAR
  85. int64_t X = (int64_t) ((x) + ((local_width) * ((ptr_cE3zj60d[(2) - (1)]) - (1))));
  86. int64_t Y = (int64_t) ((y) + ((local_height) * ((ptr_cE3zj60d[(1) - (1)]) - (1))));
  87. double cr = (double) ((ptr_Ul4Ys0Mt[(1) - (1)]) + (((X) - ((ptr_Ul4Ys0Mt[(3) - (1)]) / (2))) / (zoom)));
  88. double ci = (double) ((ptr_Ul4Ys0Mt[(2) - (1)]) + (((Y) - ((ptr_Ul4Ys0Mt[(4) - (1)]) / (2))) / (zoom)));
  89. //
  90. double zi = (double) (ci);
  91. double zr = (double) (cr);
  92. int64_t n = (int64_t) (0);
  93. float m = zr * zr + zi * zi;
  94. /* int64_t b1 = (int64_t) (((n) < (max_iterations)) + ((((zr) * (zr)) + ((zi) * (zi))) < ((conv_limit) * (conv_limit)))); */
  95. /* while ((b1) >= (2)) */
  96. /* printf("%d\n", max_iterations); */
  97. for (n = 0; n < max_iterations && m < conv_limit * conv_limit; n++)
  98. {
  99. double tmp = (double) ((((zr) * (zr)) - ((zi) * (zi))) + (cr));
  100. zi = ((2) * (zr) * (zi)) + (ci);
  101. zr = tmp;
  102. /* n = (n) + (1); */
  103. m = zr*zr + zi*zi;
  104. /* b1 = ((n) <= (max_iterations)) + ((((zr) * (zr)) + ((zi) * (zi))) <= ((conv_limit) * (conv_limit))); */
  105. }
  106. ;
  107. /* printf("n: %d\n max_iter: %d\n", n, max_iterations); */
  108. if ((n) < (max_iterations))
  109. {
  110. ptr_o2BQqRir[((y) + (((x) - (1)) * (ld_o2BQqRir))) - (1)] = 255 * (1.0 * n / (max_iterations));
  111. } else
  112. {
  113. ptr_o2BQqRir[((y) + (((x) - (1)) * (ld_o2BQqRir))) - (1)] = 0;
  114. }
  115. ;
  116. }
  117. ;
  118. }
  119. ;
  120. }