我需要并行化并增加以下mandelbrot集的代码,而无需使用openmp。这是一个仅包含字符的简单实现。任何建议我如何实现最大加速。
到目前为止,所有解决方案都在实现openMP,但是我需要在没有openMP的情况下进行优化和加速。
#include <complex>
#include <iostream>
using namespace std;
int main() {
int max_row, max_column, max_n;
cin >> max_row;
cin >> max_column;
cin >> max_iterations;
char **mat = (char**)malloc(sizeof(char*) * max_row);
for (int i = 0; i < max_row; i++)
mat[i] = (char*)malloc(sizeof(char)*max_column);
for(int row = 0; row < max_row; ++row) {
for(int column = 0; column < max_column; ++column) {
complex<float> z;
int iterations = 0;
while(abs(z) < 2 && ++iterations < max_iterations)
z = pow(z, 2) + decltype(z)(
(float)column * 2 / max_column - 1.5,
(float)row * 2 / max_row - 1);
mat[row][column] = (iterations == max_iterations ? '#' : '.');
}
}
for(int row = 0; r < max_row; ++r) {
for(int column = 0; column < max_column; ++column)
std::cout << mat[row][column];
cout << '\n';
}
}