All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
Nektar::Thread::ThreadJob Class Referenceabstract

Base class for tasks to be sent to the ThreadManager to run. More...

#include <Thread.h>

Public Member Functions

 ThreadJob ()
 Base constructor. More...
virtual ~ThreadJob ()
 Base destructor. More...
virtual void Run ()=0
void SetWorkerNum (unsigned int num)
 Set number of worker threads. More...

Protected Member Functions

unsigned int GetWorkerNum ()

Private Attributes

unsigned int m_workerNum

Detailed Description

Base class for tasks to be sent to the ThreadManager to run.

For a parallel region the overall task should be divided into tasklets, each capable of running independently of other tasklets, in any order. Each of these tasklets should be represented by an instance of a subclass of ThreadJob.

Exactly how to partition the overall task will be problem dependent, but the ideal case is to have as many tasklets as there are worker threads (available through ThreadManager::GetNumWorkers() ) and for each tasklet to take the same amount of computational effort. Clearly, the tasklets should not overwrite one another's data, and data locations they are writing to should be sufficiently far apart to avoid cache ping pong.

Subclasses may define as many variables and functions as are necessary. Instance of the subclass will be destructed once the ThreadManager has finished the Run() method.

Definition at line 99 of file Thread.h.

Constructor & Destructor Documentation

Nektar::Thread::ThreadJob::ThreadJob ( )

Base constructor.

ThreadJob implementation.

Definition at line 61 of file Thread.cpp.

62 {
63  // empty
64 }
Nektar::Thread::ThreadJob::~ThreadJob ( )

Base destructor.

Definition at line 70 of file Thread.cpp.

71 {
72  // empty
73 }

Member Function Documentation

unsigned int Nektar::Thread::ThreadJob::GetWorkerNum ( )

Returns an integer identifying the worker thread the job is running on. Value will be 0...N, where N is the number of active worker threads.

Definition at line 90 of file Thread.cpp.

References m_workerNum.

91 {
92  return m_workerNum;
93 }
unsigned int m_workerNum
Definition: Thread.h:126
virtual void Nektar::Thread::ThreadJob::Run ( )
pure virtual

This method will be called when the task is loaded onto a worker thread and is ready to run. When Run has finished this instance will be destructed.

Referenced by Nektar::Thread::ThreadWorkerBoost::RunJobs().

void Nektar::Thread::ThreadJob::SetWorkerNum ( unsigned int  num)

Set number of worker threads.

Part of the thread interface. Do not use unless you're an implementation of ThreadManager.

Do not use: needs to be public so thread implementation can call it.

Definition at line 81 of file Thread.cpp.

References m_workerNum.

Referenced by Nektar::Thread::ThreadWorkerBoost::RunJobs().

82 {
83  m_workerNum = num;
84 }
unsigned int m_workerNum
Definition: Thread.h:126

Member Data Documentation

unsigned int Nektar::Thread::ThreadJob::m_workerNum

Definition at line 126 of file Thread.h.

Referenced by GetWorkerNum(), and SetWorkerNum().