Paul Heidmann Fractal Example  1.0
fractal::threadedFractalEngine< floatType > Class Template Reference

This class splits the work of computing a given fractal amoung several threads. More...

#include <threadedFractalEngine.hpp>

Inheritance diagram for fractal::threadedFractalEngine< floatType >:
Collaboration diagram for fractal::threadedFractalEngine< floatType >:

Public Types

typedef std::tuple
< std::uint8_t, std::uint8_t,
std::uint8_t > 
colorType
 This type is used to define variables that hold colors. The standard RGB color definition is used here. More...
 

Public Member Functions

 threadedFractalEngine ()=delete
 
 ~threadedFractalEngine ()
 The class destructor. More...
 
 threadedFractalEngine (const std::shared_ptr< fractal::fractalParams< floatType >> &fParams, const std::shared_ptr< png::pngFactory > &pngFact)
 This is the constructor that must be used to create instances of this class. More...
 
void doFractal (void)
 This method is called to compute the given fractal. More...
 

Private Member Functions

void fractalWorkerThread (void)
 This method is the main (top level) method of each of the fractal computation threads. More...
 

Private Attributes

const std::uint32_t m_numThreads
 This attribute holds the number of threads that this instance is to spawn to compute the given fractal. More...
 
const std::shared_ptr
< fractal::fractalParams
< floatType > > 
m_fParams
 This attribute holds a pointer to the class instance that contains the parameters used to generate the fractal. More...
 
const std::shared_ptr
< png::pngFactory
m_pngFact
 This attribute holds a pointer to the factory used to generate the PNG image. More...
 
std::mutex m_pngFactGuard
 This attribute holds a mutex used to serialize access to the PNG factory. More...
 
std::deque< floatType > m_rowQueue
 This attribute is the queue that holds the rows of the fractal yet to be computed. More...
 
std::mutex m_rowQueueGuard
 This attribute holds the mutex that guards access to the row queue. More...
 
std::vector< std::unique_ptr
< std::thread > > 
m_threads
 This attribute holds the thread objects used to compute the given fractal. More...
 
floatType m_tenthOfRange
 This attribute holds a tenth of the imaginary range (that is, a tenth of the rows). This is used in the status count. More...
 
std::bitset< 10 > m_tenthStatusPrinted
 This attribute holds ten booleans. These booleans are set when the corresponding status number has been printed. Note that the default constructor sets all bits to false, and this class takes advantage of this fact. More...
 

Detailed Description

template<typename floatType>
class fractal::threadedFractalEngine< floatType >

This class splits the work of computing a given fractal amoung several threads.

This class splits the work of computing a given fractal among several threads. This is done to take advantage of machines with multiple cores. The number of threads spawned is settable (see m_numThreads). The fractal is split by rows (that is, lines with a constant imaginary component in the complex plane), with each row being the unit of work for a thread. Computation continues by all threads until all rows are computed.

Template Parameters
floatTypeThe underlying floating point type to be used in all computations. This will also be the type used to instantiate all complex numbers.
Author
Paul S. Heidmann

Definition at line 58 of file threadedFractalEngine.hpp.

Member Typedef Documentation

template<typename floatType >
typedef std::tuple<std::uint8_t, std::uint8_t, std::uint8_t> fractal::threadedFractalEngine< floatType >::colorType

This type is used to define variables that hold colors. The standard RGB color definition is used here.

Definition at line 64 of file threadedFractalEngine.hpp.

Constructor & Destructor Documentation

template<typename floatType >
fractal::threadedFractalEngine< floatType >::threadedFractalEngine ( )
delete
template<typename floatType >
fractal::threadedFractalEngine< floatType >::~threadedFractalEngine ( )
inline

The class destructor.

Definition at line 69 of file threadedFractalEngine.hpp.

template<typename floatType >
fractal::threadedFractalEngine< floatType >::threadedFractalEngine ( const std::shared_ptr< fractal::fractalParams< floatType >> &  fParams,
const std::shared_ptr< png::pngFactory > &  pngFact 
)
inline

This is the constructor that must be used to create instances of this class.

Parameters
fParamsThe parameters used to generate the given fractal.
pngFactThe PNG factory class used to create the PNG image.

Definition at line 75 of file threadedFractalEngine.hpp.

Member Function Documentation

Member Data Documentation

template<typename floatType >
const std::shared_ptr<fractal::fractalParams<floatType> > fractal::threadedFractalEngine< floatType >::m_fParams
private

This attribute holds a pointer to the class instance that contains the parameters used to generate the fractal.

Definition at line 136 of file threadedFractalEngine.hpp.

Referenced by fractal::threadedFractalEngine< floatType >::doFractal(), and fractal::threadedFractalEngine< floatType >::fractalWorkerThread().

template<typename floatType >
const std::uint32_t fractal::threadedFractalEngine< floatType >::m_numThreads
private

This attribute holds the number of threads that this instance is to spawn to compute the given fractal.

Definition at line 132 of file threadedFractalEngine.hpp.

Referenced by fractal::threadedFractalEngine< floatType >::doFractal().

template<typename floatType >
const std::shared_ptr<png::pngFactory> fractal::threadedFractalEngine< floatType >::m_pngFact
private

This attribute holds a pointer to the factory used to generate the PNG image.

Definition at line 140 of file threadedFractalEngine.hpp.

Referenced by fractal::threadedFractalEngine< floatType >::fractalWorkerThread().

template<typename floatType >
std::mutex fractal::threadedFractalEngine< floatType >::m_pngFactGuard
private

This attribute holds a mutex used to serialize access to the PNG factory.

Definition at line 144 of file threadedFractalEngine.hpp.

Referenced by fractal::threadedFractalEngine< floatType >::fractalWorkerThread().

template<typename floatType >
std::deque<floatType> fractal::threadedFractalEngine< floatType >::m_rowQueue
private

This attribute is the queue that holds the rows of the fractal yet to be computed.

Definition at line 148 of file threadedFractalEngine.hpp.

Referenced by fractal::threadedFractalEngine< floatType >::doFractal(), and fractal::threadedFractalEngine< floatType >::fractalWorkerThread().

template<typename floatType >
std::mutex fractal::threadedFractalEngine< floatType >::m_rowQueueGuard
private

This attribute holds the mutex that guards access to the row queue.

See Also
m_rowQueue

Definition at line 153 of file threadedFractalEngine.hpp.

Referenced by fractal::threadedFractalEngine< floatType >::doFractal(), and fractal::threadedFractalEngine< floatType >::fractalWorkerThread().

template<typename floatType >
floatType fractal::threadedFractalEngine< floatType >::m_tenthOfRange
private

This attribute holds a tenth of the imaginary range (that is, a tenth of the rows). This is used in the status count.

Definition at line 161 of file threadedFractalEngine.hpp.

Referenced by fractal::threadedFractalEngine< floatType >::doFractal(), and fractal::threadedFractalEngine< floatType >::fractalWorkerThread().

template<typename floatType >
std::bitset<10> fractal::threadedFractalEngine< floatType >::m_tenthStatusPrinted
private

This attribute holds ten booleans. These booleans are set when the corresponding status number has been printed. Note that the default constructor sets all bits to false, and this class takes advantage of this fact.

Definition at line 167 of file threadedFractalEngine.hpp.

Referenced by fractal::threadedFractalEngine< floatType >::fractalWorkerThread().

template<typename floatType >
std::vector<std::unique_ptr<std::thread> > fractal::threadedFractalEngine< floatType >::m_threads
private

This attribute holds the thread objects used to compute the given fractal.

Definition at line 157 of file threadedFractalEngine.hpp.

Referenced by fractal::threadedFractalEngine< floatType >::doFractal().


The documentation for this class was generated from the following file: