OmniSciDB  91042dcc5b
 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 x_min,
const x_max,
const y_min,
const 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 omnisci.dtypes::T.

126  {
127  if (max_iterations < 1) {
128  return mgr.ERROR_MESSAGE("max_iterations must be a positive integer");
129  }
130  if (x_pixels < 1 || y_pixels < 1) {
131  return mgr.ERROR_MESSAGE("x_pixels and y_pixels must be positive integers");
132  }
133  if (x_max <= x_min || y_max <= y_min) {
134  return mgr.ERROR_MESSAGE(
135  "Max x and y bounds must be greater than min x and y bounds");
136  }
137 
138  const T x_scale = get_scale(x_min, x_max, x_pixels);
139  const T y_scale = get_scale(y_min, y_max, y_pixels);
140 
141  const int32_t num_pixels = x_pixels * y_pixels;
142  mgr.set_output_row_size(num_pixels);
143 #ifdef HAVE_TBB
144  tbb::parallel_for(tbb::blocked_range<int32_t>(0, y_pixels),
145  [&](const tbb::blocked_range<int32_t>& y_itr) {
146  const int32_t y_begin = y_itr.begin();
147  const int32_t y_end = y_itr.end();
148 #else
149  const int32_t y_begin = 0;
150  const int32_t y_end = y_pixels;
151 #endif
152  mandelbrot_impl(x_pixels,
153  y_begin,
154  y_end,
155  x_min,
156  y_min,
157  x_scale,
158  y_scale,
159  max_iterations,
160  output_x,
161  output_y,
162  output_num_iterations);
163 #ifdef HAVE_TBB
164  });
165 #endif
166  return num_pixels;
167 }
void set_output_row_size(int64_t num_rows)
Definition: OmniSciTypes.h:334
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 x_min,
const y_min,
const x_scale,
const 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 omnisci.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 cx,
const cy,
const int32_t  max_iterations 
)

Definition at line 33 of file ExampleTableFunctions.cpp.

References omnisci.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: