Created
February 20, 2015 17:45
-
-
Save JerzySpendel/9d7f6e017d84c8ca4452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prg = cl.Program(ctx, """ | |
struct Complex{ | |
float x; | |
float y; | |
}; | |
struct Complex c_pow(const struct Complex c){ | |
struct Complex res; | |
res.x = c.x*c.x-c.y*c.y; | |
res.y = 2*c.x*c.y; | |
return res; | |
} | |
float c_abs(struct Complex c){ | |
return c.x*c.x+c.y*c.y; | |
} | |
struct Complex c_add(const struct Complex c1, const struct Complex c2){ | |
struct Complex c; | |
c.x = c1.x + c2.x; | |
c.y = c1.y + c2.y; | |
return c; | |
} | |
int check_point(const struct Complex c){ | |
struct Complex z; z.x = 0; z.y = 0; | |
const int ITERATIONS = 50; | |
int i; | |
for(i=0; i < ITERATIONS; i++){ | |
z = c_add(c_pow(z), c); | |
if(c_abs(z) > 4){ | |
return 0; | |
} | |
} | |
return 1; | |
} | |
__kernel void sum(__global const float2 *a_g , __global float *res_g){ | |
int gid = get_global_id(0); | |
struct Complex c; c.x = a_g[gid].x/500.0; c.y = a_g[gid].y/500.0; | |
res_g[gid] = check_point(c); | |
} | |
""").build() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment