start implementing multithreading

This commit is contained in:
Akos Horvath 2022-07-05 19:04:49 +02:00
parent 061d66df13
commit 2d6b6a312f
2 changed files with 65 additions and 13 deletions

View File

@ -1,16 +1,56 @@
#include "mandelbrot.h" #include "mandelbrot.h"
#include "utils.h" #include "utils.h"
#include <cstdint>
#include <iostream>
uint32_t mandelbrot(const BigFloat &c, Vec2bf &ret) using namespace mpfr;
Mandelbrotc::Mandelbrotc(Vec2mp const &f, Vec2mp const &t, Vec2i const &s, uint32_t mi)
: f(f), t(t), s(s), max_iter(mi)
{
this->threads = std::vector<std::thread>();
this->screen = std::vector<std::vector<uint8_t>>();
}
void Mandelbrotc::start_threads()
{
}
void Mandelbrotc::calc(const uint8_t tid)
{
mpreal x, y;
for(double i = tid; i < this->s.x; i+=this->thread_count) {
for(double j = 0; j < this->s.y; j++) {
x = (mpfr::abs(this->f.x - this->t.x) * (i / this->s.x)) + this->f.x;
y = (mpfr::abs(this->f.y - this->t.y) * (j / this->s.y)) + this->f.y;
this->screen[i][j] = mandelbrot(Vec2mp(x, y));
}
}
}
uint32_t Mandelbrotc::mandelbrot(const Vec2mp &n)
{ {
uint32_t iter = 0; uint32_t iter = 0;
const uint32_t max_iter = 100;
BigFloat z = BigFloat(c.precision);
z.setValue(0.0);
while(z <= 2 || iter < max_iter) // BigFloat x = BigFloat(n.x.precision);
{ // x.setValue(0.0);
z = z*z+c; // BigFloat y = BigFloat(n.y.precision);
// y.setValue(0.0);
mpreal x = mpreal(0.0);
mpreal xtemp = mpreal(0.0);
mpreal y = mpreal(0.0);
mpreal x2 = mpreal(0.0);
mpreal y2 = mpreal(0.0);
while (x*x + y*y <= 4 && iter < max_iter) {
xtemp = x*x - y*y + n.x;
y = 2*x*y+n.y;
x = xtemp;
iter++; iter++;
} }

View File

@ -1,14 +1,26 @@
#pragma once #pragma once
#include <mpfr.h>
#include <cmath> #include <cmath>
#include "utils.h" #include "utils.h"
#include <cstdint>
#include <omp.h>
#include <thread>
#include <vector>
using namespace Util; using namespace Util;
namespace Mandelbrot class Mandelbrotc {
{ public:
Vec2mp f, t;
uint8_t thread_count;
std::vector<std::thread> threads;
Vec2i s;
std::vector<std::vector<uint8_t>> screen;
uint32_t max_iter;
uint32_t mandelbrot(const BigFloat &c, Vec2bf &ret); Mandelbrotc(Vec2mp const &f, Vec2mp const &t, Vec2i const &s, uint32_t mi);
void start_threads();
} void stop_threads();
uint32_t mandelbrot(const Vec2mp &n);
void calc(const uint8_t tid);
};