Paul Heidmann Fractal Example
1.0
|
This class splits the work of computing a given fractal amoung several threads. More...
#include <threadedFractalEngine.hpp>
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... | |
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.
floatType | The underlying floating point type to be used in all computations. This will also be the type used to instantiate all complex numbers. |
Definition at line 58 of file threadedFractalEngine.hpp.
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.
|
delete |
|
inline |
The class destructor.
Definition at line 69 of file threadedFractalEngine.hpp.
|
inline |
This is the constructor that must be used to create instances of this class.
fParams | The parameters used to generate the given fractal. |
pngFact | The PNG factory class used to create the PNG image. |
Definition at line 75 of file threadedFractalEngine.hpp.
|
inline |
This method is called to compute the given fractal.
Definition at line 86 of file threadedFractalEngine.hpp.
References fractal::threadedFractalEngine< floatType >::m_fParams, fractal::threadedFractalEngine< floatType >::m_numThreads, fractal::threadedFractalEngine< floatType >::m_rowQueue, fractal::threadedFractalEngine< floatType >::m_rowQueueGuard, fractal::threadedFractalEngine< floatType >::m_tenthOfRange, and fractal::threadedFractalEngine< floatType >::m_threads.
Referenced by main().
|
inlineprivate |
This method is the main (top level) method of each of the fractal computation threads.
Definition at line 171 of file threadedFractalEngine.hpp.
References fractal::threadedFractalEngine< floatType >::m_fParams, fractal::threadedFractalEngine< floatType >::m_pngFact, fractal::threadedFractalEngine< floatType >::m_pngFactGuard, fractal::threadedFractalEngine< floatType >::m_rowQueue, fractal::threadedFractalEngine< floatType >::m_rowQueueGuard, fractal::threadedFractalEngine< floatType >::m_tenthOfRange, and fractal::threadedFractalEngine< floatType >::m_tenthStatusPrinted.
|
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().
|
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().
|
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().
|
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().
|
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().
|
private |
This attribute holds the mutex that guards access to the row queue.
Definition at line 153 of file threadedFractalEngine.hpp.
Referenced by fractal::threadedFractalEngine< floatType >::doFractal(), and fractal::threadedFractalEngine< floatType >::fractalWorkerThread().
|
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().
|
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().
|
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().