使用openCL设置MandelBrot [英] MandelBrot set Using openCL

查看:114
本文介绍了使用openCL设置MandelBrot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用与使用TBB(线程构建块)运行时所用的相同的代码(某种).

Trying to use the same code (sort of) as what I have used when running using TBB (threading building blocks).

我在OpenCL方面没有很多经验,但是我认为大多数主要代码都是正确的.我相信错误出现在.cl文件中,该文件在其中进行数学计算.

I don't have a great deal of experience with OpenCL, but I think most of the main code is correct. I believe the errors are in the .cl file, where it does the math.

这是我在TBB中的mandelbrot代码:

Here is my mandelbrot code in TBB:

Mandelbrot TBB

这是我在OpenCL中的代码

Here is my code in OpenCL

Mandelbrot OpenCL

任何帮助将不胜感激.

Any help would be greatly appreciated.

推荐答案

我更改了内核中的代码,并且运行良好.我的新内核代码如下:

I changed the code in the kernel, and it ran fine. My new kernel code is the following:

// voronoi kernels

//
// local memory version
//
kernel void voronoiL(write_only image2d_t outputImage)
{
    // get id of element in array
    int x = get_global_id(0);
    int y = get_global_id(1);
    int w = get_global_size(0);
    int h = get_global_size(1);

    float4 result = (float4)(0.0f,0.0f,0.0f,1.0f);
    float MinRe = -2.0f;
    float MaxRe = 1.0f;
    float MinIm = -1.5f;
    float MaxIm = MinIm+(MaxRe-MinRe)*h/w;
    float Re_factor = (MaxRe-MinRe)/(w-1);
    float Im_factor = (MaxIm-MinIm)/(h-1);
    float MaxIterations = 50;


    //C imaginary
    float c_im = MaxIm - y*Im_factor;

    //C real
    float c_re = MinRe + x*Re_factor;

    //Z real
    float Z_re = c_re, Z_im = c_im;

    bool isInside = true;
    bool col2 = false;
    bool col3 = false;
    int iteration =0;

    for(int n=0; n<MaxIterations; n++)
    {
        // Z - real and imaginary
        float Z_re2 = Z_re*Z_re, Z_im2 = Z_im*Z_im;

        //if Z real squared plus Z imaginary squared is greater than c squared
        if(Z_re2 + Z_im2 > 4)
        {
            if(n >= 0 && n <= (MaxIterations/2-1))
            {
                col2 = true;
                isInside = false;
                break;
            }
            else if(n >= MaxIterations/2 && n <= MaxIterations-1)
            {
                col3 = true;
                isInside = false;
                break;
            }
        }
        Z_im = 2*Z_re*Z_im + c_im;
        Z_re = Z_re2 - Z_im2 + c_re;
        iteration++;
    }
    if(col2) 
    { 
        result = (float4)(iteration*0.05f,0.0f, 0.0f, 1.0f);
    }
    else if(col3)
    {
        result = (float4)(255, iteration*0.05f, iteration*0.05f, 1.0f);
    }
    else if(isInside)
    {
        result = (float4)(0.0f, 0.0f, 0.0f, 1.0f);
    }


    write_imagef(outputImage, (int2)(x, y), result);
}

您也可以在这里找到它:

You can also find it here:

https://docs.google.com/file/d/0B6DBARvnB__iUjNSTWJubFhUSDA/edit

这篇关于使用openCL设置MandelBrot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆