OpenWalnut  1.5.0dev
Public Member Functions | Private Attributes | List of all members
WTuringPatternCreator::PatternThread Class Reference

A thread calculating the reaction for a certain part of the domain. More...

+ Inheritance diagram for WTuringPatternCreator::PatternThread:
+ Collaboration diagram for WTuringPatternCreator::PatternThread:

Public Member Functions

 PatternThread (std::size_t id, std::size_t max, std::shared_ptr< WCondition > const mainThreadContinueCondition, std::shared_ptr< WCondition > const waitForMainThreadCondition, WCounter *const counter)
 Constructor. More...
 
 ~PatternThread ()
 Destructor. More...
 
void setDomainSize (std::size_t sizeX, std::size_t sizeY, std::size_t sizeZ)
 Set the domain size. More...
 
void setSpotFactor (float spotFactor)
 Set the spot factor. More...
 
void setDiffusionConstants (float d1, float d2)
 Set the diffusion constants. More...
 
void setBufferPointers (std::vector< float > const *concentration1, std::vector< float > const *concentration2, std::vector< float > const *noise, std::vector< float > *delta1, std::vector< float > *delta2)
 Set the pointers to the buffer all threads share. More...
 
virtual void threadMain ()
 The entry point for the thread. More...
 
void finish ()
 Tells the thread to finish. More...
 
- Public Member Functions inherited from WThreadedRunner
 WThreadedRunner ()
 Default constructor. More...
 
virtual ~WThreadedRunner ()
 Destructor. More...
 
virtual void run ()
 Run thread. More...
 
void run (THREADFUNCTION f)
 Run thread. More...
 
void wait (bool requestFinish=false)
 Wait for the thread to be finished. More...
 
virtual void requestStop ()
 This method's purpose is to request a stop without waiting for it. More...
 
virtual boost::signals2::connection subscribeSignal (THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier)
 Connects a specified notify function with a signal this thread instance is offering. More...
 
const WBoolFlagisCrashed () const
 Checks whether this thread has been crashed. More...
 
const std::string & getCrashMessage () const
 Get the message of the exception finally causing the crash. More...
 
void setThreadName (std::string name)
 Set the name of the thread. More...
 
std::string getThreadName () const
 Returns the current thread name. More...
 

Private Attributes

std::size_t m_id
 The number of this thread. More...
 
std::size_t m_maxThreads
 The maximum number of threads. More...
 
std::size_t m_sizeX
 The size of the domain in x-direction. More...
 
std::size_t m_sizeY
 The size of the domain in y-direction. More...
 
std::size_t m_sizeZ
 The size of the domain in z-direction. More...
 
float m_spotFactor
 The spot factor. More...
 
float m_diffusionConstant1
 The first diffusion constant. More...
 
float m_diffusionConstant2
 The second diffusion constant. More...
 
std::vector< float > const * m_concentration1
 The buffer for the concentration of the first substance. More...
 
std::vector< float > const * m_concentration2
 The buffer for the concentration of the second substance. More...
 
std::vector< float > const * m_noise
 A constant buffer containing a random value per voxel. More...
 
std::vector< float > * m_delta1
 A buffer that will store the change in concentration for the first substance. More...
 
std::vector< float > * m_delta2
 A buffer that will store the change in concentration for the second substance. More...
 
std::shared_ptr< WConditionm_mainThreadContinueCondition
 The condition used to tell the main thread we are done for this iteration. More...
 
std::shared_ptr< WConditionm_waitForMainThreadCondition
 The condition used by the main thread to notify we are ready to start the next iteration. More...
 
WCounter *const m_counter
 Counts the number of threads done with the current iteration. More...
 
bool m_stop
 Whether we are to stop the thread. More...
 

Additional Inherited Members

- Public Types inherited from WThreadedRunner
typedef std::shared_ptr< WThreadedRunnerSPtr
 Abbreviation to a shared_ptr to this type. More...
 
typedef std::shared_ptr< const WThreadedRunnerConstSPtr
 Abbreviation to a const shared_ptr to this type. More...
 
typedef boost::function< void(void) > THREADFUNCTION
 Type used for simple thread functions. More...
 
- Static Public Member Functions inherited from WThreadedRunner
static void setThisThreadName (std::string name)
 Static function to set the name of the calling thread. More...
 
- Protected Member Functions inherited from WThreadedRunner
virtual void notifyStop ()
 Gets called when the thread should be stopped. More...
 
void yield () const
 Give remaining execution timeslice to another thread. More...
 
void sleep (const int32_t t) const
 Sets thread asleep. More...
 
void msleep (const int32_t t) const
 Sets thread asleep. More...
 
void waitForStop ()
 Let the thread sleep until a stop request was given. More...
 
virtual void onThreadException (const WException &e)
 This method is called if an exception was caught, which came from the custom thread code. More...
 
void handleDeadlyException (const WException &e, std::string sender="WThreadedRunner")
 Handle the specified exception which was not caught in the thread, which basically means the thread has crashed. More...
 
- Protected Attributes inherited from WThreadedRunner
boost::thread m_thread
 Thread instance. More...
 
WBoolFlag m_shutdownFlag
 Condition getting fired whenever the thread should quit. More...
 
WBoolFlag m_isCrashed
 True whenever an exception is thrown during threadMain. More...
 
std::string m_crashMessage
 The crash message. More...
 

Detailed Description

A thread calculating the reaction for a certain part of the domain.

The thread is constructed once. Using the conditions provided to the constructor, we can synchronize the pattern threads and the main thread.

Definition at line 98 of file WTuringPatternCreator.h.

Constructor & Destructor Documentation

◆ PatternThread()

WTuringPatternCreator::PatternThread::PatternThread ( std::size_t  id,
std::size_t  max,
std::shared_ptr< WCondition > const  mainThreadContinueCondition,
std::shared_ptr< WCondition > const  waitForMainThreadCondition,
WCounter *const  counter 
)

Constructor.

Parameters
idThe id of the thread. Must be smaller than max.
maxThe number of threads.
mainThreadContinueConditionThe condition we use to tell the main thread we are done for the current iteration.
waitForMainThreadConditionThe condition used to wait for the main thread to prepare the next iteration.
counterA counter used by all threads to signal how many have finished the current iteration.

Definition at line 158 of file WTuringPatternCreator.cpp.

◆ ~PatternThread()

WTuringPatternCreator::PatternThread::~PatternThread ( )

Destructor.

Definition at line 178 of file WTuringPatternCreator.cpp.

Member Function Documentation

◆ finish()

void WTuringPatternCreator::PatternThread::finish ( )

Tells the thread to finish.

Note that the waiting condition also needs to be notified for the thread to actually finish.

Definition at line 306 of file WTuringPatternCreator.cpp.

◆ setBufferPointers()

void WTuringPatternCreator::PatternThread::setBufferPointers ( std::vector< float > const *  concentration1,
std::vector< float > const *  concentration2,
std::vector< float > const *  noise,
std::vector< float > *  delta1,
std::vector< float > *  delta2 
)

Set the pointers to the buffer all threads share.

Parameters
concentration1The buffer for the concentration of the first substance.
concentration2The buffer for the concentration of the second substance.
noiseA constant buffer containing a random value per voxel.
delta1A buffer that will store the change in concentration for the first substance.
delta2A buffer that will store the change in concentration for the second substance.

Definition at line 289 of file WTuringPatternCreator.cpp.

◆ setDiffusionConstants()

void WTuringPatternCreator::PatternThread::setDiffusionConstants ( float  d1,
float  d2 
)

Set the diffusion constants.

Parameters
d1First diffusion constant.
d2Second diffusion constant.

Definition at line 182 of file WTuringPatternCreator.cpp.

◆ setDomainSize()

void WTuringPatternCreator::PatternThread::setDomainSize ( std::size_t  sizeX,
std::size_t  sizeY,
std::size_t  sizeZ 
)

Set the domain size.

Parameters
sizeXThe size of the 3D regular domain in x-direction.
sizeYThe size of the 3D regular domain in y-direction.
sizeZThe size of the 3D regular domain in z-direction.

Definition at line 198 of file WTuringPatternCreator.cpp.

◆ setSpotFactor()

void WTuringPatternCreator::PatternThread::setSpotFactor ( float  spotFactor)

Set the spot factor.

Parameters
spotFactorThe spot factor.

Definition at line 191 of file WTuringPatternCreator.cpp.

◆ threadMain()

void WTuringPatternCreator::PatternThread::threadMain ( )
virtual

The entry point for the thread.

Reimplemented from WThreadedRunner.

Definition at line 209 of file WTuringPatternCreator.cpp.

Member Data Documentation

◆ m_concentration1

std::vector< float > const* WTuringPatternCreator::PatternThread::m_concentration1
private

The buffer for the concentration of the first substance.

Definition at line 192 of file WTuringPatternCreator.h.

◆ m_concentration2

std::vector< float > const* WTuringPatternCreator::PatternThread::m_concentration2
private

The buffer for the concentration of the second substance.

Definition at line 195 of file WTuringPatternCreator.h.

◆ m_counter

WCounter* const WTuringPatternCreator::PatternThread::m_counter
private

Counts the number of threads done with the current iteration.

Definition at line 213 of file WTuringPatternCreator.h.

◆ m_delta1

std::vector< float >* WTuringPatternCreator::PatternThread::m_delta1
private

A buffer that will store the change in concentration for the first substance.

Definition at line 201 of file WTuringPatternCreator.h.

◆ m_delta2

std::vector< float >* WTuringPatternCreator::PatternThread::m_delta2
private

A buffer that will store the change in concentration for the second substance.

Definition at line 204 of file WTuringPatternCreator.h.

◆ m_diffusionConstant1

float WTuringPatternCreator::PatternThread::m_diffusionConstant1
private

The first diffusion constant.

Definition at line 186 of file WTuringPatternCreator.h.

◆ m_diffusionConstant2

float WTuringPatternCreator::PatternThread::m_diffusionConstant2
private

The second diffusion constant.

Definition at line 189 of file WTuringPatternCreator.h.

◆ m_id

std::size_t WTuringPatternCreator::PatternThread::m_id
private

The number of this thread.

Definition at line 168 of file WTuringPatternCreator.h.

◆ m_mainThreadContinueCondition

std::shared_ptr< WCondition > WTuringPatternCreator::PatternThread::m_mainThreadContinueCondition
private

The condition used to tell the main thread we are done for this iteration.

Definition at line 207 of file WTuringPatternCreator.h.

◆ m_maxThreads

std::size_t WTuringPatternCreator::PatternThread::m_maxThreads
private

The maximum number of threads.

Definition at line 171 of file WTuringPatternCreator.h.

◆ m_noise

std::vector< float > const* WTuringPatternCreator::PatternThread::m_noise
private

A constant buffer containing a random value per voxel.

Definition at line 198 of file WTuringPatternCreator.h.

◆ m_sizeX

std::size_t WTuringPatternCreator::PatternThread::m_sizeX
private

The size of the domain in x-direction.

Definition at line 174 of file WTuringPatternCreator.h.

◆ m_sizeY

std::size_t WTuringPatternCreator::PatternThread::m_sizeY
private

The size of the domain in y-direction.

Definition at line 177 of file WTuringPatternCreator.h.

◆ m_sizeZ

std::size_t WTuringPatternCreator::PatternThread::m_sizeZ
private

The size of the domain in z-direction.

Definition at line 180 of file WTuringPatternCreator.h.

◆ m_spotFactor

float WTuringPatternCreator::PatternThread::m_spotFactor
private

The spot factor.

Definition at line 183 of file WTuringPatternCreator.h.

◆ m_stop

bool WTuringPatternCreator::PatternThread::m_stop
private

Whether we are to stop the thread.

Definition at line 216 of file WTuringPatternCreator.h.

◆ m_waitForMainThreadCondition

std::shared_ptr< WCondition > WTuringPatternCreator::PatternThread::m_waitForMainThreadCondition
private

The condition used by the main thread to notify we are ready to start the next iteration.

Definition at line 210 of file WTuringPatternCreator.h.


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