0

I try to calculate a fractal image, and as the calculation could be long as the resolution increase, I was wondering if I could use Hyper Threading to calculate "tiles" of my final image and then have the result. But all my tries to split Threads or Tasks ended by a slower calculation than the way I showed below (just brute force all values in a for loop).

Also, I don't have NVidia GPU, and I wonder I that kind of calculation could be fasten up by OpenCL ?

For now all whay I have is creating a Bitmap with a given resolution and number of dots per side.

    Image Generate() {
      DateTime n = DateTime.Now;
      Console.WriteLine("Generating...");
      
      Image img = new Bitmap(resolution, resolution);
      Graphics g = Graphics.FromImage(img);

      double step = ((px - mx) / points) * 0.5d;
      for (double x = mx; x < px; x += step) {
        for (double y = my; y < py; y += step) {
          ParseDot(CreateDot(new Complex(x, y)), g);
        }
      }

      Console.WriteLine("Dots parsed (" + (DateTime.Now - n).TotalMilliseconds + ")");

      pictureBox1.BackgroundImage = img;
      pictureBox1.Refresh();
      isComputing = false;
      return img;
    }

My result so far

Thanks for any tips :)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Neoz
  • 11

2 Answers2

0

With OpenCL you can do the mandelbrot zoom in real time, several hundred times faster than with CPU multithreading. The idea is to compute each pixel on the Bitmap with 1 GPU thread, i.e. parallelize your nested x and y loops. Example source code (Java & OpenCL via Aparapi) as well as executable .jar samples are on my website.

ProjectPhysX
  • 4,535
  • 2
  • 14
  • 34
0

Thanks, I finally found a way to hyper thread, I'll defintly have a look about OpenCL later, but for now I manage to divide calculation time by 5 using Parallel.For() :

      double span = (Form1.px - Form1.mx);
      int parallels = 50;
      List<Dot>[] dots = new List<Dot>[parallels];

      Parallel.For(0,
        parallels,
        (iteration, state) => {
          dots[iteration] = new List<Dot>();
          for (double x = Form1.mx + (span / parallels) * iteration; x < Form1.mx + (span / parallels) * (iteration + 1); x += step) {
            for (double y = Form1.my; y < Form1.py; y += step) {
              dots[iteration].Add(CreateDot(new Complex(x, y)));
            }
          }
        });
Neoz
  • 11