OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mandelbrot Namespace Reference

Functions

template<typename T >
TEMPLATE_INLINE int32_t mandelbrot_pixel (const T cx, const T cy, const int32_t max_iterations)
 
DEVICE double get_scale (const double domain_min, const double domain_max, const int32_t num_bins)
 
template<typename T >
TEMPLATE_NOINLINE void mandelbrot_impl (const int32_t x_pixels, const int32_t y_begin, const int32_t y_end, const T x_min, const T y_min, const T x_scale, const T y_scale, const int32_t max_iterations, Column< T > &output_x, Column< T > &output_y, Column< int32_t > &output_num_iterations)
 
template<typename T >
TEMPLATE_NOINLINE int32_t mandelbrot_cpu_template (TableFunctionManager &mgr, const int32_t x_pixels, const int32_t y_pixels, const T x_min, const T x_max, const T y_min, const T y_max, const int32_t max_iterations, Column< T > &output_x, Column< T > &output_y, Column< int32_t > &output_num_iterations)
 

Function Documentation

DEVICE double Mandelbrot::get_scale ( const double  domain_min,
const double  domain_max,
const int32_t  num_bins 
)
inline

Definition at line 63 of file ExampleTableFunctions.cpp.

Referenced by mandelbrot_cpu_template().

65  {
66  return (domain_max - domain_min) / num_bins;
67 }

+ Here is the caller graph for this function:

template<typename T >
TEMPLATE_NOINLINE int32_t Mandelbrot::mandelbrot_cpu_template ( TableFunctionManager mgr,
const int32_t  x_pixels,
const int32_t  y_pixels,
const T  x_min,
const T  x_max,
const T  y_min,
const T  y_max,
const int32_t  max_iterations,
Column< T > &  output_x,
Column< T > &  output_y,
Column< int32_t > &  output_num_iterations 
)

Definition at line 116 of file ExampleTableFunctions.cpp.

References get_scale(), mandelbrot_impl(), threading_serial::parallel_for(), TableFunctionManager::set_output_row_size(), and heavydb.dtypes::T.

126  {
127 
128  const T x_scale = get_scale(x_min, x_max, x_pixels);
129  const T y_scale = get_scale(y_min, y_max, y_pixels);
130 
131  const int32_t num_pixels = x_pixels * y_pixels;
132  mgr.set_output_row_size(num_pixels);
133 #ifdef HAVE_TBB
134  tbb::parallel_for(tbb::blocked_range<int32_t>(0, y_pixels),
135  [&](const tbb::blocked_range<int32_t>& y_itr) {
136  const int32_t y_begin = y_itr.begin();
137  const int32_t y_end = y_itr.end();
138 #else
139  const int32_t y_begin = 0;
140  const int32_t y_end = y_pixels;
141 #endif
142  mandelbrot_impl(x_pixels,
143  y_begin,
144  y_end,
145  x_min,
146  y_min,
147  x_scale,
148  y_scale,
149  max_iterations,
150  output_x,
151  output_y,
152  output_num_iterations);
153 #ifdef HAVE_TBB
154  });
155 #endif
156  return num_pixels;
157 }
void set_output_row_size(int64_t num_rows)
Definition: heavydbTypes.h:373
DEVICE double get_scale(const double domain_min, const double domain_max, const int32_t num_bins)
TEMPLATE_NOINLINE void mandelbrot_impl(const int32_t x_pixels, const int32_t y_begin, const int32_t y_end, const T x_min, const T y_min, const T x_scale, const T y_scale, const int32_t max_iterations, Column< T > &output_x, Column< T > &output_y, Column< int32_t > &output_num_iterations)
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())

+ Here is the call graph for this function:

template<typename T >
TEMPLATE_NOINLINE void Mandelbrot::mandelbrot_impl ( const int32_t  x_pixels,
const int32_t  y_begin,
const int32_t  y_end,
const T  x_min,
const T  y_min,
const T  x_scale,
const T  y_scale,
const int32_t  max_iterations,
Column< T > &  output_x,
Column< T > &  output_y,
Column< int32_t > &  output_num_iterations 
)

Definition at line 77 of file ExampleTableFunctions.cpp.

References mandelbrot_pixel(), and heavydb.dtypes::T.

Referenced by mandelbrot_cpu_template().

87  {
88  // scanning every point in that rectangular area.
89  // each point represents a complex number (x + yi).
90  // iterate that complex number
91 
92  for (int32_t y = y_begin; y < y_end; ++y) {
93  // c_imaginary
94  const T cy = y * y_scale + y_min;
95  for (int32_t x = 0; x < x_pixels; ++x) {
96  // c_real
97  const T cx = x * x_scale + x_min;
98  const int32_t output_pixel = y * x_pixels + x;
99  output_x[output_pixel] = cx;
100  output_y[output_pixel] = cy;
101  output_num_iterations[output_pixel] = mandelbrot_pixel(cx, cy, max_iterations);
102  }
103  }
104 }
TEMPLATE_INLINE int32_t mandelbrot_pixel(const T cx, const T cy, const int32_t max_iterations)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
TEMPLATE_INLINE int32_t Mandelbrot::mandelbrot_pixel ( const T  cx,
const T  cy,
const int32_t  max_iterations 
)

Definition at line 33 of file ExampleTableFunctions.cpp.

References heavydb.dtypes::T.

Referenced by mandelbrot_impl().

35  {
36  // z_real
37  T zx = 0;
38  // z_imaginary
39  T zy = 0;
40  int32_t num_iterations = 0;
41  // Calculate whether c(c_real + c_imaginary) belongs
42  // to the Mandelbrot set or not and draw a pixel
43  // at coordinates (x, y) accordingly
44  // If you reach the Maximum number of iterations
45  // and If the distance from the origin is
46  // greater terthan 2 exit the loop
47  while ((zx * zx + zy * zy < 4) && (num_iterations < max_iterations)) {
48  // Calculate Mandelbrot function
49  // z = z*z + c where z is a complex number
50  // tempx = z_real*_real - z_imaginary*z_imaginary + c_real
51  const T temp_x = zx * zx - zy * zy + cx;
52  // 2*z_real*z_imaginary + c_imaginary
53  zy = 2 * zx * zy + cy;
54  // Updating z_real = tempx
55  zx = temp_x;
56 
57  // Increment counter
58  ++num_iterations;
59  }
60  return num_iterations;
61 }

+ Here is the caller graph for this function: