2013-04-14 76 views
1

嘗試使用與我在使用TBB(線程構建塊)運行時所用的代碼相同的代碼(排序)。MandelBrot set使用openCL

我對OpenCL沒有太多的經驗,但我認爲大部分主代碼是正確的。我相信這些錯誤在.cl文件中,它在數學上做了些什麼。

這裏是TBB我曼德爾布羅代碼:

Mandelbrot TBB

這是我在OpenCL的

Mandelbrot OpenCL

代碼的任何幫助,將不勝感激。

+0

將我的答案張貼到這個現在它的工作,不久 –

回答

1

我在內核中改變了代碼,並運行良好。我的新內核代碼如下:

// 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); 
} 

你也可以在這裏找到:

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

1

看到這個鏈接。它由@ eric-bainville開發。原生CPU和OpenCL的CPU代碼並不是最優的(它不使用SSE/AVX),但我認爲GPU代碼可能是好的。對於CPU,您可以通過使用AVX並一次操作八個像素來加速代碼。

http://www.bealto.com/mp-mandelbrot.html

+0

太好了,我會採取看看。謝謝! –