-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot_update.cu
37 lines (33 loc) · 896 Bytes
/
mandelbrot_update.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <cuComplex.h>
#define MAX_SHARED_MEMORY 1000
__global__ void mandelbrot_update(
int N, int M, int ghost, int kmax, double rho, int ***dev_escape,
double ax, double ay, double dx, double dy
)
{
int **escape;
escape = *dev_escape;
int i = blockIdx.x*blockDim.x + threadIdx.x;
int j = blockIdx.y*blockDim.y + threadIdx.y;
if(i < N && j < M)
{
double zreal = ax + i*dx + dx/2;
double zimag = ay + j*dy + dy/2;
cuDoubleComplex z = make_cuDoubleComplex(zreal,zimag);
cuDoubleComplex z0 = z;
for(int k = 0; k < kmax; k++)
{
if(cuCabs(z) > rho && escape[i][j] == 0)
{
escape[i][j] = k;
}
else
{
z = cuCadd(cuCmul(z,z), z0);
}
}
}
}