https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
ParallelRayStudy Class Referenceabstract

#include <ParallelRayStudy.h>

Inheritance diagram for ParallelRayStudy:
[legend]

Public Types

typedef MooseUtils::Buffer< std::shared_ptr< Ray > >::iterator work_iterator
 
typedef MooseUtils::Buffer< std::shared_ptr< Ray > >::iterator parallel_data_iterator
 

Public Member Functions

 ParallelRayStudy (RayTracingStudy &study, const std::vector< std::shared_ptr< TraceRay >> &threaded_trace_ray)
 
void preExecute ()
 Pre-execute method that MUST be called before execute() and before adding work. More...
 
void execute ()
 Execute method. More...
 
MooseUtils::SharedPool< Ray >::PtrType acquireParallelData (const THREAD_ID tid, Args &&... args)
 Acquire a parallel data object from the pool. More...
 
void moveParallelDataToBuffer (std::shared_ptr< Ray > &data, const processor_id_type dest_pid)
 Moves parallel data objects to the send buffer to be communicated to processor dest_pid. More...
 
const ReceiveBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > & receiveBuffer () const
 Gets the receive buffer. More...
 
const MooseUtils::Buffer< std::shared_ptr< Ray > > & workBuffer () const
 Gets the work buffer. More...
 
unsigned long long int sendBufferPoolCreated () const
 Gets the total number of send buffer pools created. More...
 
unsigned long long int parallelDataSent () const
 Gets the total number of parallel data objects sent from this processor. More...
 
unsigned long long int buffersSent () const
 Gets the total number of buffers sent from this processor. More...
 
unsigned long long int poolParallelDataCreated () const
 Gets the total number of parallel data created in all of the threaded pools. More...
 
unsigned long long int localWorkStarted () const
 Gets the total amount of work started from this processor. More...
 
unsigned long long int localWorkExecuted () const
 Gets the total amount of work executed on this processor. More...
 
unsigned long long int totalWorkCompleted () const
 Gets the total amount of work completeed across all processors. More...
 
unsigned long long int localChunksExecuted () const
 Gets the total number of chunks of work executed on this processor. More...
 
bool currentlyExecuting () const
 Whether or not this object is currently in execute(). More...
 
bool currentlyPreExecuting () const
 Whether or not this object is between preExecute() and execute(). More...
 
unsigned int maxBufferSize () const
 Gets the max buffer size. More...
 
unsigned int chunkSize () const
 Gets the chunk size. More...
 
unsigned int clicksPerCommunication () const
 Gets the number of iterations to wait before communicating. More...
 
unsigned int clicksPerRootCommunication () const
 Gets the number of iterations to wait before communicating with root. More...
 
unsigned int clicksPerReceive () const
 Gets the number of iterations to wait before checking for new parallel data. More...
 
ParallelStudyMethod method () const
 Gets the method. More...
 
void reserveBuffer (const std::size_t size)
 Reserve size entries in the work buffer. More...
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
RayTracingStudyrayTracingStudy ()
 Get the RayTracingStudy associated with this ParallelRayStudy. More...
 
const RayTracingStudyrayTracingStudy () const
 
void moveWorkToBuffer (std::shared_ptr< Ray > &work, const THREAD_ID tid)
 Adds work to the buffer to be executed. More...
 
void moveWorkToBuffer (const work_iterator begin, const work_iterator end, const THREAD_ID tid)
 
void moveWorkToBuffer (std::vector< std::shared_ptr< Ray > > &work, const THREAD_ID tid)
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Types

enum  MoveWorkError
 Enum for providing useful errors during work addition in moveWorkError(). More...
 

Protected Member Functions

void executeWork (const std::shared_ptr< Ray > &ray, const THREAD_ID tid) override
 Pure virtual to be overridden that executes a single object of work on a given thread. More...
 
void moveWorkError (const MoveWorkError error, const std::shared_ptr< Ray > *ray) const override
 
void postReceiveParallelData (const parallel_data_iterator begin, const parallel_data_iterator end) override
 
bool workIsComplete (const std::shared_ptr< Ray > &ray) override
 Can be overridden to denote if a piece of work is not complete yet. More...
 
void postExecuteChunk (const work_iterator begin, const work_iterator end) override
 
virtual std::unique_ptr< MooseUtils::Buffer< std::shared_ptr< Ray > > > createWorkBuffer ()
 Creates the work buffer. More...
 
virtual void moveWorkError (const MoveWorkError error, const std::shared_ptr< Ray > *work=nullptr) const
 Virtual that allows for the customization of error text for moving work into the buffer. More...
 
virtual bool alternateSmartEndingCriteriaMet ()
 Insertion point for derived classes to provide an alternate ending criteria for SMART execution. More...
 
virtual void postExecuteChunk (const work_iterator, const work_iterator)
 Insertion point for acting on work that was just executed. More...
 
virtual void preReceiveAndExecute ()
 Insertion point called just after trying to receive work and just before beginning work on the work buffer. More...
 
virtual void postReceiveParallelData (const parallel_data_iterator begin, const parallel_data_iterator end)=0
 Pure virtual for acting on parallel data that has JUST been received and filled into the buffer. More...
 
bool buffersAreEmpty () const
 Whether or not ALL of the buffers are empty: Working buffer, threaded buffers, receive buffer, and send buffers. More...
 
void moveContinuingWorkToBuffer (std::shared_ptr< Ray > &Work)
 Moves work that is considered continuing for the purposes of the execution algorithm into the buffer. More...
 
void moveContinuingWorkToBuffer (const work_iterator begin, const work_iterator end)
 

Protected Attributes

RayTracingStudy_ray_tracing_study
 The RayTracingStudy. More...
 
const std::vector< std::shared_ptr< TraceRay > > & _threaded_trace_ray
 The TraceRay objects that do the tracing for each thread. More...
 
const processor_id_type _pid
 This rank. More...
 
const std::string _name
 Name for this object for use in error handling. More...
 
const InputParameters_params
 The InputParameters. More...
 
const ParallelStudyMethod _method
 The study method. More...
 
bool _has_alternate_ending_criteria
 Whether or not this object has alternate ending criteria. More...
 
const Parallel::Communicator & _communicator
 

Detailed Description

Definition at line 21 of file ParallelRayStudy.h.

Member Typedef Documentation

◆ parallel_data_iterator

typedef MooseUtils::Buffer<std::shared_ptr<Ray > >::iterator ParallelStudy< std::shared_ptr< Ray > , Ray >::parallel_data_iterator
inherited

Definition at line 34 of file ParallelStudy.h.

◆ work_iterator

typedef MooseUtils::Buffer<std::shared_ptr< Ray > >::iterator ParallelStudy< std::shared_ptr< Ray > , Ray >::work_iterator
inherited

Definition at line 32 of file ParallelStudy.h.

Member Enumeration Documentation

◆ MoveWorkError

enum ParallelStudy::MoveWorkError
protectedinherited

Constructor & Destructor Documentation

◆ ParallelRayStudy()

ParallelRayStudy::ParallelRayStudy ( RayTracingStudy study,
const std::vector< std::shared_ptr< TraceRay >> &  threaded_trace_ray 
)

Definition at line 16 of file ParallelRayStudy.C.

20  ray_tracing_study.comm(), ray_tracing_study.parameters(), "ParallelRayStudy"),
21  _ray_tracing_study(ray_tracing_study),
22  _threaded_trace_ray(threaded_trace_ray)
23 {
24 }
const std::vector< std::shared_ptr< TraceRay > > & _threaded_trace_ray
The TraceRay objects that do the tracing for each thread.
Basic datastructure for a ray that will traverse the mesh.
Definition: Ray.h:56
RayTracingStudy & _ray_tracing_study
The RayTracingStudy.

Member Function Documentation

◆ acquireParallelData()

MooseUtils::SharedPool<Ray >::PtrType ParallelStudy< std::shared_ptr< Ray > , Ray >::acquireParallelData ( const THREAD_ID  tid,
Args &&...  args 
)
inlineinherited

Acquire a parallel data object from the pool.

Definition at line 73 of file ParallelStudy.h.

74  {
75  return _parallel_data_pools[tid].acquire(std::forward<Args>(args)...);
76  }
std::vector< MooseUtils::SharedPool< Ray > > _parallel_data_pools
Pools for re-using destructed parallel data objects (one for each thread)

◆ alternateSmartEndingCriteriaMet()

bool ParallelStudy< std::shared_ptr< Ray > , Ray >::alternateSmartEndingCriteriaMet ( )
protectedvirtualinherited

Insertion point for derived classes to provide an alternate ending criteria for SMART execution.

Only called when _has_alternate_ending_criteria == true.

Definition at line 1202 of file ParallelStudy.h.

1203 {
1204  mooseError(_name, ": Unimplemented alternateSmartEndingCriteriaMet()");
1205 }
void mooseError(Args &&... args)
const std::string _name
Name for this object for use in error handling.

◆ buffersAreEmpty()

bool ParallelStudy< std::shared_ptr< Ray > , Ray >::buffersAreEmpty ( ) const
protectedinherited

Whether or not ALL of the buffers are empty: Working buffer, threaded buffers, receive buffer, and send buffers.

Definition at line 1209 of file ParallelStudy.h.

1210 {
1211  if (!_work_buffer->empty())
1212  return false;
1213  for (const auto & threaded_buffer : _temp_threaded_work)
1214  if (!threaded_buffer.empty())
1215  return false;
1216  if (_receive_buffer->currentlyReceiving())
1217  return false;
1218  for (const auto & map_pair : _send_buffers)
1219  if (map_pair.second->currentlySending() || map_pair.second->currentlyBuffered())
1220  return false;
1221 
1222  return true;
1223 }
const std::unique_ptr< ReceiveBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > > _receive_buffer
The receive buffer.
std::vector< std::vector< std::shared_ptr< Ray > > > _temp_threaded_work
Threaded temprorary storage for work added while we&#39;re using the _work_buffer (one for each thread) ...
const std::unique_ptr< MooseUtils::Buffer< std::shared_ptr< Ray > > > _work_buffer
Buffer for executing work.
std::unordered_map< processor_id_type, std::unique_ptr< SendBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > > > _send_buffers
Send buffers for each processor.

◆ buffersSent()

unsigned long long int ParallelStudy< std::shared_ptr< Ray > , Ray >::buffersSent ( ) const
inherited

Gets the total number of buffers sent from this processor.

Definition at line 1178 of file ParallelStudy.h.

1179 {
1180  unsigned long long int total_sent = 0;
1181 
1182  for (const auto & buffer : _send_buffers)
1183  total_sent += buffer.second->buffersSent();
1184 
1185  return total_sent;
1186 }
std::unordered_map< processor_id_type, std::unique_ptr< SendBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > > > _send_buffers
Send buffers for each processor.

◆ chunkSize()

unsigned int ParallelStudy< std::shared_ptr< Ray > , Ray >::chunkSize ( ) const
inlineinherited

Gets the chunk size.

Definition at line 148 of file ParallelStudy.h.

148 { return _chunk_size; }
const unsigned int _chunk_size
Number of objects to execute at once during communication.

◆ clicksPerCommunication()

unsigned int ParallelStudy< std::shared_ptr< Ray > , Ray >::clicksPerCommunication ( ) const
inlineinherited

Gets the number of iterations to wait before communicating.

Definition at line 153 of file ParallelStudy.h.

153 { return _clicks_per_communication; }
const unsigned int _clicks_per_communication
Iterations to wait before communicating.

◆ clicksPerReceive()

unsigned int ParallelStudy< std::shared_ptr< Ray > , Ray >::clicksPerReceive ( ) const
inlineinherited

Gets the number of iterations to wait before checking for new parallel data.

Definition at line 161 of file ParallelStudy.h.

161 { return _clicks_per_receive; }
const unsigned int _clicks_per_receive
Iterations to wait before checking for new objects.

◆ clicksPerRootCommunication()

unsigned int ParallelStudy< std::shared_ptr< Ray > , Ray >::clicksPerRootCommunication ( ) const
inlineinherited

Gets the number of iterations to wait before communicating with root.

Definition at line 157 of file ParallelStudy.h.

const unsigned int _clicks_per_root_communication
Iterations to wait before communicating with root.

◆ createWorkBuffer()

std::unique_ptr< MooseUtils::Buffer< std::shared_ptr< Ray > > > ParallelStudy< std::shared_ptr< Ray > , Ray >::createWorkBuffer ( )
protectedvirtualinherited

Creates the work buffer.

This is virtual so that derived classes can use their own specialized buffers

Definition at line 419 of file ParallelStudy.h.

420 {
421  std::unique_ptr<MooseUtils::Buffer<WorkType>> buffer;
422 
423  const auto buffer_type = _params.get<MooseEnum>("work_buffer_type");
424  if (buffer_type == "lifo")
425  buffer = std::make_unique<MooseUtils::LIFOBuffer<WorkType>>();
426  else if (buffer_type == "circular")
427  buffer = std::make_unique<MooseUtils::CircularBuffer<WorkType>>();
428  else
429  mooseError("Unknown work buffer type");
430 
431  return buffer;
432 }
void mooseError(Args &&... args)
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const InputParameters & _params
The InputParameters.

◆ currentlyExecuting()

bool ParallelStudy< std::shared_ptr< Ray > , Ray >::currentlyExecuting ( ) const
inlineinherited

Whether or not this object is currently in execute().

Definition at line 135 of file ParallelStudy.h.

135 { return _currently_executing; }
bool _currently_executing
Whether we are within execute()

◆ currentlyPreExecuting()

bool ParallelStudy< std::shared_ptr< Ray > , Ray >::currentlyPreExecuting ( ) const
inlineinherited

Whether or not this object is between preExecute() and execute().

Definition at line 139 of file ParallelStudy.h.

139 { return _currently_pre_executing; }
bool _currently_pre_executing
Whether we are between preExecute() and execute()

◆ execute()

void ParallelStudy< std::shared_ptr< Ray > , Ray >::execute ( )
inherited

Execute method.

Definition at line 988 of file ParallelStudy.h.

989 {
991  mooseError(_name, ": preExecute() was not called before execute()");
992 
993  _currently_pre_executing = false;
994  _currently_executing = true;
995 
996  switch (_method)
997  {
999  smartExecute();
1000  break;
1002  harmExecute();
1003  break;
1005  bsExecute();
1006  break;
1007  default:
1008  mooseError("Unknown ParallelStudyMethod");
1009  }
1010 
1011  _currently_executing = false;
1012 
1013  // Sanity checks on if we're really done
1014  comm().barrier();
1015 
1016  if (!buffersAreEmpty())
1017  mooseError(_name, ": Buffers are not empty after execution");
1018 }
void mooseError(Args &&... args)
bool _currently_pre_executing
Whether we are between preExecute() and execute()
const std::string _name
Name for this object for use in error handling.
const Parallel::Communicator & comm() const
bool _currently_executing
Whether we are within execute()
const ParallelStudyMethod _method
The study method.
void smartExecute()
Execute work using SMART.
bool buffersAreEmpty() const
Whether or not ALL of the buffers are empty: Working buffer, threaded buffers, receive buffer...
void harmExecute()
Execute work using HARM.
void bsExecute()
Execute work using BS.

◆ executeWork()

void ParallelRayStudy::executeWork ( const std::shared_ptr< Ray > &  work,
const THREAD_ID  tid 
)
overrideprotectedvirtual

Pure virtual to be overridden that executes a single object of work on a given thread.

Implements ParallelStudy< std::shared_ptr< Ray >, Ray >.

Definition at line 64 of file ParallelRayStudy.C.

65 {
66  mooseAssert(ray->shouldContinue(), "Tracing Ray that should not continue");
67 
68  // If this is false, it means we have a Ray that is banked to go onto another processor
69  if (ray->currentElem()->processor_id() == _pid)
70  _threaded_trace_ray[tid]->trace(ray);
71 }
const std::vector< std::shared_ptr< TraceRay > > & _threaded_trace_ray
The TraceRay objects that do the tracing for each thread.
const processor_id_type _pid
This rank.

◆ localChunksExecuted()

unsigned long long int ParallelStudy< std::shared_ptr< Ray > , Ray >::localChunksExecuted ( ) const
inlineinherited

Gets the total number of chunks of work executed on this processor.

Definition at line 130 of file ParallelStudy.h.

130 { return _local_chunks_executed; }
unsigned long long int _local_chunks_executed
Number of chunks of work executed on this processor.

◆ localWorkExecuted()

unsigned long long int ParallelStudy< std::shared_ptr< Ray > , Ray >::localWorkExecuted ( ) const
inlineinherited

Gets the total amount of work executed on this processor.

Definition at line 122 of file ParallelStudy.h.

122 { return _local_work_executed; }
unsigned long long int _local_work_executed
Amount of work executed on this processor.

◆ localWorkStarted()

unsigned long long int ParallelStudy< std::shared_ptr< Ray > , Ray >::localWorkStarted ( ) const
inlineinherited

Gets the total amount of work started from this processor.

Definition at line 118 of file ParallelStudy.h.

118 { return _local_work_started; }
unsigned long long int _local_work_started
Amount of work started on this processor.

◆ maxBufferSize()

unsigned int ParallelStudy< std::shared_ptr< Ray > , Ray >::maxBufferSize ( ) const
inlineinherited

Gets the max buffer size.

Definition at line 144 of file ParallelStudy.h.

144 { return _max_buffer_size; }
const unsigned int _max_buffer_size
Number of objects to buffer before communication.

◆ method()

ParallelStudyMethod ParallelStudy< std::shared_ptr< Ray > , Ray >::method ( ) const
inlineinherited

Gets the method.

Definition at line 166 of file ParallelStudy.h.

166 { return _method; }
const ParallelStudyMethod _method
The study method.

◆ moveContinuingWorkToBuffer() [1/2]

void ParallelStudy< std::shared_ptr< Ray > , Ray >::moveContinuingWorkToBuffer ( std::shared_ptr< Ray > &  Work)
protectedinherited

Moves work that is considered continuing for the purposes of the execution algorithm into the buffer.

Definition at line 1128 of file ParallelStudy.h.

Referenced by postReceiveParallelData().

1129 {
1132 
1133  _work_buffer->move(work);
1134 }
const std::unique_ptr< MooseUtils::Buffer< std::shared_ptr< Ray > > > _work_buffer
Buffer for executing work.
virtual void moveWorkError(const MoveWorkError error, const std::shared_ptr< Ray > *work=nullptr) const
Virtual that allows for the customization of error text for moving work into the buffer.
bool _currently_executing_work
Whether or not we are currently within executeAndBuffer()

◆ moveContinuingWorkToBuffer() [2/2]

void ParallelStudy< std::shared_ptr< Ray > , Ray >::moveContinuingWorkToBuffer ( const work_iterator  begin,
const work_iterator  end 
)
protectedinherited

Definition at line 1138 of file ParallelStudy.h.

1140 {
1143 
1144  const auto size = std::distance(begin, end);
1145  if (_work_buffer->capacity() < _work_buffer->size() + size)
1146  _work_buffer->setCapacity(_work_buffer->size() + size);
1147 
1148  for (auto it = begin; it != end; ++it)
1149  _work_buffer->move(*it);
1150 }
const std::unique_ptr< MooseUtils::Buffer< std::shared_ptr< Ray > > > _work_buffer
Buffer for executing work.
virtual void moveWorkError(const MoveWorkError error, const std::shared_ptr< Ray > *work=nullptr) const
Virtual that allows for the customization of error text for moving work into the buffer.
bool _currently_executing_work
Whether or not we are currently within executeAndBuffer()

◆ moveParallelDataToBuffer()

void ParallelStudy< std::shared_ptr< Ray > , Ray >::moveParallelDataToBuffer ( std::shared_ptr< Ray > &  data,
const processor_id_type  dest_pid 
)
inherited

Moves parallel data objects to the send buffer to be communicated to processor dest_pid.

Definition at line 576 of file ParallelStudy.h.

Referenced by postExecuteChunk().

578 {
579  mooseAssert(comm().size() > dest_pid, "Invalid processor ID");
580  mooseAssert(_pid != dest_pid, "Processor ID is self");
581 
583  mooseError(_name, ": Cannot sendParallelData() when not executing");
584 
585  // Get the send buffer for the proc this object is going to
586  auto find_pair = _send_buffers.find(dest_pid);
587  // Need to create a send buffer for said processor
588  if (find_pair == _send_buffers.end())
590  .emplace(dest_pid,
591  std::make_unique<
593  comm(),
594  this,
595  dest_pid,
596  _method,
602  .first->second->moveObject(data);
603  // Send buffer exists for this processor
604  else
605  find_pair->second->moveObject(data);
606 }
const unsigned int _max_buffer_size
Number of objects to buffer before communication.
const Real _buffer_shrink_multiplier
Multiplier for the buffer size for shrinking the buffer.
const unsigned int _min_buffer_size
Minimum size of a SendBuffer.
void mooseError(Args &&... args)
bool _currently_pre_executing
Whether we are between preExecute() and execute()
const std::string _name
Name for this object for use in error handling.
const Parallel::Communicator & comm() const
bool _currently_executing
Whether we are within execute()
const processor_id_type _pid
This rank.
const Real _buffer_growth_multiplier
Multiplier for the buffer size for growing the buffer.
const ParallelStudyMethod _method
The study method.
Parallel::MessageTag _parallel_data_buffer_tag
MessageTag for sending parallel data.
std::unordered_map< processor_id_type, std::unique_ptr< SendBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > > > _send_buffers
Send buffers for each processor.

◆ moveWorkError() [1/2]

void ParallelRayStudy::moveWorkError ( const MoveWorkError  error,
const std::shared_ptr< Ray > *  ray 
) const
overrideprotected

Definition at line 74 of file ParallelRayStudy.C.

75 {
76  std::stringstream oss;
77  oss << "In method " << _ray_tracing_study.type() << "::addRay(s)ToBuffer:\n";
78 
79  if (error == MoveWorkError::DURING_EXECUTION_DISABLED)
80  {
81  oss << "Rays are being added to the buffer during propagation.\n\n";
82  oss << "This capability must be enabled by setting the parameter\n";
83  oss << "'allow_new_work_during_execution' to true.";
84  }
85  else if (error == MoveWorkError::PRE_EXECUTION_AND_EXECUTION_ONLY)
86  oss << "Rays can only be added to the buffer during generateRays() and tracing.";
87  else if (error == MoveWorkError::PRE_EXECUTION_ONLY)
88  oss << "Rays can only be added to the buffer during generateRays().";
89  else if (error == MoveWorkError::PRE_EXECUTION_THREAD_0_ONLY)
90  oss << "Rays can only be added on thread 0 during generateRays() (not thread safe)";
91  else if (error == CONTINUING_DURING_EXECUTING_WORK)
93 
94  if (ray)
95  oss << "\n\n" << (*ray)->getInfo();
96 
97  mooseError(oss.str());
98 }
void mooseError(Args &&... args)
void moveWorkError(const MoveWorkError error, const std::shared_ptr< Ray > *ray) const override
const std::string & type() const
Basic datastructure for a ray that will traverse the mesh.
Definition: Ray.h:56
RayTracingStudy & _ray_tracing_study
The RayTracingStudy.

◆ moveWorkError() [2/2]

void ParallelStudy< std::shared_ptr< Ray > , Ray >::moveWorkError ( const MoveWorkError  error,
const std::shared_ptr< Ray > *  work = nullptr 
) const
protectedvirtualinherited

Virtual that allows for the customization of error text for moving work into the buffer.

Definition at line 1022 of file ParallelStudy.h.

1024 {
1026  mooseError(_name,
1027  ": The moving of new work into the buffer during work execution requires\n",
1028  "that the parameter 'allow_new_work_during_execution = true'");
1030  mooseError(
1031  _name,
1032  ": Can only move work into the buffer in the pre-execution and execution phase\n(between "
1033  "preExecute() and the end of execute()");
1034  if (error == MoveWorkError::PRE_EXECUTION_ONLY)
1035  mooseError(_name,
1036  ": Can only move work into the buffer in the pre-execution phase\n(between "
1037  "preExecute() and execute()");
1039  mooseError(_name,
1040  ": Can only move work into the buffer in the pre-execution phase\n(between "
1041  "preExecute() and execute()) on thread 0");
1042  if (error == CONTINUING_DURING_EXECUTING_WORK)
1043  mooseError(_name, ": Cannot move continuing work into the buffer during executeAndBuffer()");
1044 
1045  mooseError("Unknown MoveWorkError");
1046 }
void mooseError(Args &&... args)
const std::string _name
Name for this object for use in error handling.

◆ moveWorkToBuffer() [1/3]

void ParallelStudy< std::shared_ptr< Ray > , Ray >::moveWorkToBuffer ( std::shared_ptr< Ray > &  work,
const THREAD_ID  tid 
)
inherited

Adds work to the buffer to be executed.

This will move the work into the buffer (with std::move), therefore the passed in work will be invalid after this call. For the purposes of the completion algorithm, this added work is considered NEW work.

During pre-execution (between preExecute() and execute()), this method can ONLY be called on thread 0.

During execute(), this method is thread safe and can be used to add work during execution.

Definition at line 1070 of file ParallelStudy.h.

1071 {
1072  // Error checks for moving work into the buffer at unallowed times
1073  canMoveWorkCheck(tid);
1074 
1075  // Can move directly into the work buffer on thread 0 when we're not executing work
1076  if (!_currently_executing_work && tid == 0)
1077  {
1078  ++_local_work_started; // must ALWAYS increment when adding new work to the working buffer
1079  _work_buffer->move(work);
1080  }
1081  // Objects added during execution go into a temporary threaded vector (is thread safe) to be
1082  // moved into the working buffer when possible
1083  else
1084  _temp_threaded_work[tid].emplace_back(std::move(work));
1085 }
std::vector< std::vector< std::shared_ptr< Ray > > > _temp_threaded_work
Threaded temprorary storage for work added while we&#39;re using the _work_buffer (one for each thread) ...
void canMoveWorkCheck(const THREAD_ID tid)
Internal check for if it is allowed to currently add work in moveWorkToBuffer().
const std::unique_ptr< MooseUtils::Buffer< std::shared_ptr< Ray > > > _work_buffer
Buffer for executing work.
unsigned long long int _local_work_started
Amount of work started on this processor.
bool _currently_executing_work
Whether or not we are currently within executeAndBuffer()

◆ moveWorkToBuffer() [2/3]

void ParallelStudy< std::shared_ptr< Ray > , Ray >::moveWorkToBuffer ( const work_iterator  begin,
const work_iterator  end,
const THREAD_ID  tid 
)
inherited

Definition at line 1089 of file ParallelStudy.h.

1092 {
1093  // Error checks for moving work into the buffer at unallowed times
1094  canMoveWorkCheck(tid);
1095 
1096  // Get work size beforehand so we can resize
1097  const auto size = std::distance(begin, end);
1098 
1099  // Can move directly into the work buffer on thread 0 when we're not executing work
1100  if (!_currently_executing_work && tid == 0)
1101  {
1102  if (_work_buffer->capacity() < _work_buffer->size() + size)
1103  _work_buffer->setCapacity(_work_buffer->size() + size);
1104  _local_work_started += size;
1105  }
1106  else
1107  _temp_threaded_work[tid].reserve(_temp_threaded_work[tid].size() + size);
1108 
1109  // Move the objects
1110  if (!_currently_executing_work && tid == 0)
1111  for (auto it = begin; it != end; ++it)
1112  _work_buffer->move(*it);
1113  else
1114  for (auto it = begin; it != end; ++it)
1115  _temp_threaded_work[tid].emplace_back(std::move(*it));
1116 }
std::vector< std::vector< std::shared_ptr< Ray > > > _temp_threaded_work
Threaded temprorary storage for work added while we&#39;re using the _work_buffer (one for each thread) ...
void canMoveWorkCheck(const THREAD_ID tid)
Internal check for if it is allowed to currently add work in moveWorkToBuffer().
const std::unique_ptr< MooseUtils::Buffer< std::shared_ptr< Ray > > > _work_buffer
Buffer for executing work.
unsigned long long int _local_work_started
Amount of work started on this processor.
bool _currently_executing_work
Whether or not we are currently within executeAndBuffer()

◆ moveWorkToBuffer() [3/3]

void ParallelStudy< std::shared_ptr< Ray > , Ray >::moveWorkToBuffer ( std::vector< std::shared_ptr< Ray > > &  work,
const THREAD_ID  tid 
)
inherited

Definition at line 1120 of file ParallelStudy.h.

1122 {
1123  moveWorkToBuffer(work_vector.begin(), work_vector.end(), tid);
1124 }
void moveWorkToBuffer(std::shared_ptr< Ray > &work, const THREAD_ID tid)
Adds work to the buffer to be executed.

◆ parallelDataSent()

unsigned long long int ParallelStudy< std::shared_ptr< Ray > , Ray >::parallelDataSent ( ) const
inherited

Gets the total number of parallel data objects sent from this processor.

Definition at line 1166 of file ParallelStudy.h.

1167 {
1168  unsigned long long int total_sent = 0;
1169 
1170  for (const auto & buffer : _send_buffers)
1171  total_sent += buffer.second->objectsSent();
1172 
1173  return total_sent;
1174 }
std::unordered_map< processor_id_type, std::unique_ptr< SendBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > > > _send_buffers
Send buffers for each processor.

◆ poolParallelDataCreated()

unsigned long long int ParallelStudy< std::shared_ptr< Ray > , Ray >::poolParallelDataCreated ( ) const
inherited

Gets the total number of parallel data created in all of the threaded pools.

Definition at line 1190 of file ParallelStudy.h.

1191 {
1192  unsigned long long int num_created = 0;
1193 
1194  for (const auto & pool : _parallel_data_pools)
1195  num_created += pool.num_created();
1196 
1197  return num_created;
1198 }
std::vector< MooseUtils::SharedPool< Ray > > _parallel_data_pools
Pools for re-using destructed parallel data objects (one for each thread)

◆ postExecuteChunk() [1/2]

void ParallelRayStudy::postExecuteChunk ( const work_iterator  begin,
const work_iterator  end 
)
overrideprotected

Definition at line 27 of file ParallelRayStudy.C.

28 {
29  for (auto it = begin; it != end; ++it)
30  {
31  std::shared_ptr<Ray> & ray = *it;
32 
33  // The Ray is done tracing
34  if (!ray->shouldContinue())
35  {
37  continue;
38  }
39 
40  // Going to another processor
41  mooseAssert(ray->currentElem()->processor_id() != _pid,
42  "Continuing Ray not going to another processor");
43  moveParallelDataToBuffer(ray, ray->currentElem()->processor_id());
44  }
45 }
virtual void onCompleteRay(const std::shared_ptr< Ray > &ray)
Entry point for acting on a ray when it is completed (shouldContinue() == false)
const processor_id_type _pid
This rank.
void moveParallelDataToBuffer(std::shared_ptr< Ray > &data, const processor_id_type dest_pid)
Moves parallel data objects to the send buffer to be communicated to processor dest_pid.
RayTracingStudy & _ray_tracing_study
The RayTracingStudy.

◆ postExecuteChunk() [2/2]

virtual void ParallelStudy< std::shared_ptr< Ray > , Ray >::postExecuteChunk ( const work_iterator  ,
const work_iterator   
)
inlineprotectedvirtualinherited

Insertion point for acting on work that was just executed.

This is not called in threads.

Definition at line 219 of file ParallelStudy.h.

219 {}

◆ postReceiveParallelData() [1/2]

void ParallelRayStudy::postReceiveParallelData ( const parallel_data_iterator  begin,
const parallel_data_iterator  end 
)
overrideprotected

Definition at line 55 of file ParallelRayStudy.C.

57 {
58  // Move all of the parallel data (Rays that are continuing to be traced on this processor)
59  // directly into the work buffer
60  moveContinuingWorkToBuffer(begin, end);
61 }
void moveContinuingWorkToBuffer(std::shared_ptr< Ray > &Work)
Moves work that is considered continuing for the purposes of the execution algorithm into the buffer...

◆ postReceiveParallelData() [2/2]

virtual void ParallelStudy< std::shared_ptr< Ray > , Ray >::postReceiveParallelData ( const parallel_data_iterator  begin,
const parallel_data_iterator  end 
)
protectedpure virtualinherited

Pure virtual for acting on parallel data that has JUST been received and filled into the buffer.

The parallel data in the range passed here will have its use count reduced by one if it still exists after this call.

◆ preExecute()

void ParallelStudy< std::shared_ptr< Ray > , Ray >::preExecute ( )
inherited

Pre-execute method that MUST be called before execute() and before adding work.

Definition at line 964 of file ParallelStudy.h.

965 {
966  if (!buffersAreEmpty())
967  mooseError(_name, ": Buffers are not empty in preExecute()");
968 
969  // Clear communication buffers
970  for (auto & send_buffer_pair : _send_buffers)
971  send_buffer_pair.second->clear();
972  _send_buffers.clear();
973  _receive_buffer->clear();
974 
975  // Clear counters
982 
984 }
const std::unique_ptr< ReceiveBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > > _receive_buffer
The receive buffer.
void mooseError(Args &&... args)
bool _currently_pre_executing
Whether we are between preExecute() and execute()
unsigned long long int _local_work_executed
Amount of work executed on this processor.
const std::string _name
Name for this object for use in error handling.
unsigned long long int _local_work_completed
Amount of work completed on this processor.
bool buffersAreEmpty() const
Whether or not ALL of the buffers are empty: Working buffer, threaded buffers, receive buffer...
unsigned long long int _local_chunks_executed
Number of chunks of work executed on this processor.
unsigned long long int _total_work_completed
Amount of work completed on all processors.
unsigned long long int _local_work_started
Amount of work started on this processor.
unsigned long long int _total_work_started
Amount of work started on all processors.
std::unordered_map< processor_id_type, std::unique_ptr< SendBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > > > _send_buffers
Send buffers for each processor.

◆ preReceiveAndExecute()

virtual void ParallelStudy< std::shared_ptr< Ray > , Ray >::preReceiveAndExecute ( )
inlineprotectedvirtualinherited

Insertion point called just after trying to receive work and just before beginning work on the work buffer.

Definition at line 225 of file ParallelStudy.h.

225 {}

◆ rayTracingStudy() [1/2]

RayTracingStudy& ParallelRayStudy::rayTracingStudy ( )
inline

Get the RayTracingStudy associated with this ParallelRayStudy.

Definition at line 31 of file ParallelRayStudy.h.

31 { return _ray_tracing_study; }
RayTracingStudy & _ray_tracing_study
The RayTracingStudy.

◆ rayTracingStudy() [2/2]

const RayTracingStudy& ParallelRayStudy::rayTracingStudy ( ) const
inline

Definition at line 32 of file ParallelRayStudy.h.

32 { return _ray_tracing_study; }
RayTracingStudy & _ray_tracing_study
The RayTracingStudy.

◆ receiveBuffer()

const ReceiveBuffer<Ray , ParallelStudy<std::shared_ptr< Ray > , Ray > >& ParallelStudy< std::shared_ptr< Ray > , Ray >::receiveBuffer ( ) const
inlineinherited

Gets the receive buffer.

Definition at line 88 of file ParallelStudy.h.

89  {
90  return *_receive_buffer;
91  }
const std::unique_ptr< ReceiveBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > > _receive_buffer
The receive buffer.

◆ reserveBuffer()

void ParallelStudy< std::shared_ptr< Ray > , Ray >::reserveBuffer ( const std::size_t  size)
inherited

Reserve size entries in the work buffer.

This can only be used during the pre-execution phase (between preExecute() and execute()).

This is particularly useful when one wants to move many work objects into the buffer using moveWorkToBuffer() and wants to allocate the space ahead of time.

Definition at line 618 of file ParallelStudy.h.

619 {
621  mooseError(_name, ": Can only reserve in object buffer during pre-execution");
622 
623  // We don't ever want to decrease the capacity, so only set if we need more entries
624  if (_work_buffer->capacity() < size)
625  _work_buffer->setCapacity(size);
626 }
void mooseError(Args &&... args)
bool _currently_pre_executing
Whether we are between preExecute() and execute()
const std::string _name
Name for this object for use in error handling.
const std::unique_ptr< MooseUtils::Buffer< std::shared_ptr< Ray > > > _work_buffer
Buffer for executing work.

◆ sendBufferPoolCreated()

unsigned long long int ParallelStudy< std::shared_ptr< Ray > , Ray >::sendBufferPoolCreated ( ) const
inherited

Gets the total number of send buffer pools created.

Definition at line 1154 of file ParallelStudy.h.

1155 {
1156  unsigned long long int total = 0;
1157 
1158  for (const auto & buffer : _send_buffers)
1159  total += buffer.second->bufferPoolCreated();
1160 
1161  return total;
1162 }
std::unordered_map< processor_id_type, std::unique_ptr< SendBuffer< Ray, ParallelStudy< std::shared_ptr< Ray >, Ray > > > > _send_buffers
Send buffers for each processor.

◆ totalWorkCompleted()

unsigned long long int ParallelStudy< std::shared_ptr< Ray > , Ray >::totalWorkCompleted ( ) const
inlineinherited

Gets the total amount of work completeed across all processors.

Definition at line 126 of file ParallelStudy.h.

126 { return _total_work_completed; }
unsigned long long int _total_work_completed
Amount of work completed on all processors.

◆ validParams()

InputParameters ParallelStudy< std::shared_ptr< Ray > , Ray >::validParams ( )
staticinherited

Definition at line 436 of file ParallelStudy.h.

Referenced by RayTracingStudy::validParams().

437 {
438  auto params = emptyInputParameters();
439 
440  params.addRangeCheckedParam<unsigned int>(
441  "send_buffer_size", 100, "send_buffer_size > 0", "The size of the send buffer");
442  params.addRangeCheckedParam<unsigned int>(
443  "chunk_size",
444  100,
445  "chunk_size > 0",
446  "The number of objects to process at one time during execution");
447  params.addRangeCheckedParam<unsigned int>("clicks_per_communication",
448  10,
449  "clicks_per_communication >= 0",
450  "Iterations to wait before communicating");
451  params.addRangeCheckedParam<unsigned int>("clicks_per_root_communication",
452  10,
453  "clicks_per_root_communication > 0",
454  "Iterations to wait before communicating with root");
455  params.addRangeCheckedParam<unsigned int>("clicks_per_receive",
456  1,
457  "clicks_per_receive > 0",
458  "Iterations to wait before checking for new objects");
459 
460  params.addParam<unsigned int>("min_buffer_size",
461  "The initial size of the SendBuffer and the floor for shrinking "
462  "it. This defaults to send_buffer_size if not set (i.e. the "
463  "buffer won't change size)");
464  params.addParam<Real>("buffer_growth_multiplier",
465  2.,
466  "How much to grow a SendBuffer by if the buffer completely fills and "
467  "dumps. Will max at send_buffer_size");
468  params.addRangeCheckedParam<Real>("buffer_shrink_multiplier",
469  0.5,
470  "0 < buffer_shrink_multiplier <= 1.0",
471  "Multiplier (between 0 and 1) to apply to the current buffer "
472  "size if it is force dumped. Will stop at "
473  "min_buffer_size.");
474 
475  params.addParam<bool>(
476  "allow_new_work_during_execution",
477  true,
478  "Whether or not to allow the addition of new work to the work buffer during execution");
479 
480  MooseEnum methods("smart harm bs", "smart");
481  params.addParam<MooseEnum>("method", methods, "The algorithm to use");
482 
483  MooseEnum work_buffers("lifo circular", "circular");
484  params.addParam<MooseEnum>("work_buffer_type", work_buffers, "The work buffer type to use");
485 
486  params.addParamNamesToGroup(
487  "send_buffer_size chunk_size clicks_per_communication clicks_per_root_communication "
488  "clicks_per_receive min_buffer_size buffer_growth_multiplier buffer_shrink_multiplier method "
489  "work_buffer_type allow_new_work_during_execution",
490  "Advanced");
491 
492  return params;
493 }
InputParameters emptyInputParameters()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ workBuffer()

const MooseUtils::Buffer<std::shared_ptr< Ray > >& ParallelStudy< std::shared_ptr< Ray > , Ray >::workBuffer ( ) const
inlineinherited

Gets the work buffer.

Definition at line 96 of file ParallelStudy.h.

96 { return *_work_buffer; }
const std::unique_ptr< MooseUtils::Buffer< std::shared_ptr< Ray > > > _work_buffer
Buffer for executing work.

◆ workIsComplete()

bool ParallelRayStudy::workIsComplete ( const std::shared_ptr< Ray > &  )
overrideprotectedvirtual

Can be overridden to denote if a piece of work is not complete yet.

The complete terminology is used within the execution algorithms to determine if the study is complete.

Reimplemented from ParallelStudy< std::shared_ptr< Ray >, Ray >.

Definition at line 48 of file ParallelRayStudy.C.

49 {
50  // "Work" (a Ray) is considered complete in the parallel algorithm when it is done tracing
51  return !ray->shouldContinue();
52 }

Member Data Documentation

◆ _has_alternate_ending_criteria

bool ParallelStudy< std::shared_ptr< Ray > , Ray >::_has_alternate_ending_criteria
protectedinherited

Whether or not this object has alternate ending criteria.

Definition at line 269 of file ParallelStudy.h.

◆ _method

const ParallelStudyMethod ParallelStudy< std::shared_ptr< Ray > , Ray >::_method
protectedinherited

The study method.

Definition at line 267 of file ParallelStudy.h.

◆ _name

const std::string ParallelStudy< std::shared_ptr< Ray > , Ray >::_name
protectedinherited

Name for this object for use in error handling.

Definition at line 263 of file ParallelStudy.h.

◆ _params

const InputParameters& ParallelStudy< std::shared_ptr< Ray > , Ray >::_params
protectedinherited

The InputParameters.

Definition at line 265 of file ParallelStudy.h.

◆ _pid

const processor_id_type ParallelStudy< std::shared_ptr< Ray > , Ray >::_pid
protectedinherited

This rank.

Definition at line 261 of file ParallelStudy.h.

Referenced by executeWork(), and postExecuteChunk().

◆ _ray_tracing_study

RayTracingStudy& ParallelRayStudy::_ray_tracing_study
protected

The RayTracingStudy.

Definition at line 44 of file ParallelRayStudy.h.

Referenced by moveWorkError(), postExecuteChunk(), and rayTracingStudy().

◆ _threaded_trace_ray

const std::vector<std::shared_ptr<TraceRay> >& ParallelRayStudy::_threaded_trace_ray
protected

The TraceRay objects that do the tracing for each thread.

Definition at line 46 of file ParallelRayStudy.h.

Referenced by executeWork().


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