Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "ParallelRayStudy.h" 11 : 12 : // Local includes 13 : #include "TraceRay.h" 14 : #include "RayTracingStudy.h" 15 : 16 3827 : ParallelRayStudy::ParallelRayStudy( 17 : RayTracingStudy & ray_tracing_study, 18 3827 : const std::vector<std::shared_ptr<TraceRay>> & threaded_trace_ray) 19 : : ParallelStudy<std::shared_ptr<Ray>, Ray>( 20 : ray_tracing_study.comm(), ray_tracing_study.parameters(), "ParallelRayStudy"), 21 3827 : _ray_tracing_study(ray_tracing_study), 22 3827 : _threaded_trace_ray(threaded_trace_ray) 23 : { 24 3827 : } 25 : 26 : void 27 62509 : ParallelRayStudy::postExecuteChunk(const work_iterator begin, const work_iterator end) 28 : { 29 5442679 : for (auto it = begin; it != end; ++it) 30 : { 31 : std::shared_ptr<Ray> & ray = *it; 32 : 33 : // The Ray is done tracing 34 5380170 : if (!ray->shouldContinue()) 35 : { 36 4120844 : _ray_tracing_study.onCompleteRay(ray); 37 4120844 : continue; 38 : } 39 : 40 : // Going to another processor 41 : mooseAssert(ray->currentElem()->processor_id() != _pid, 42 : "Continuing Ray not going to another processor"); 43 1259326 : moveParallelDataToBuffer(ray, ray->currentElem()->processor_id()); 44 : } 45 62509 : } 46 : 47 : bool 48 5380170 : ParallelRayStudy::workIsComplete(const std::shared_ptr<Ray> & ray) 49 : { 50 : // "Work" (a Ray) is considered complete in the parallel algorithm when it is done tracing 51 5380170 : return !ray->shouldContinue(); 52 : } 53 : 54 : void 55 7019 : ParallelRayStudy::postReceiveParallelData(const parallel_data_iterator begin, 56 : const parallel_data_iterator end) 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 7019 : moveContinuingWorkToBuffer(begin, end); 61 7019 : } 62 : 63 : void 64 5380196 : ParallelRayStudy::executeWork(const std::shared_ptr<Ray> & ray, const THREAD_ID tid) 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 5380196 : if (ray->currentElem()->processor_id() == _pid) 70 5380196 : _threaded_trace_ray[tid]->trace(ray); 71 5380170 : } 72 : 73 : void 74 0 : ParallelRayStudy::moveWorkError(const MoveWorkError error, const std::shared_ptr<Ray> * ray) const 75 : { 76 0 : std::stringstream oss; 77 0 : oss << "In method " << _ray_tracing_study.type() << "::addRay(s)ToBuffer:\n"; 78 : 79 : if (error == MoveWorkError::DURING_EXECUTION_DISABLED) 80 : { 81 0 : oss << "Rays are being added to the buffer during propagation.\n\n"; 82 0 : oss << "This capability must be enabled by setting the parameter\n"; 83 0 : oss << "'allow_new_work_during_execution' to true."; 84 : } 85 : else if (error == MoveWorkError::PRE_EXECUTION_AND_EXECUTION_ONLY) 86 0 : oss << "Rays can only be added to the buffer during generateRays() and tracing."; 87 : else if (error == MoveWorkError::PRE_EXECUTION_ONLY) 88 0 : oss << "Rays can only be added to the buffer during generateRays()."; 89 : else if (error == MoveWorkError::PRE_EXECUTION_THREAD_0_ONLY) 90 0 : oss << "Rays can only be added on thread 0 during generateRays() (not thread safe)"; 91 : else if (error == CONTINUING_DURING_EXECUTING_WORK) 92 0 : ParallelStudy<std::shared_ptr<Ray>, Ray>::moveWorkError(error, ray); 93 : 94 0 : if (ray) 95 0 : oss << "\n\n" << (*ray)->getInfo(); 96 : 97 0 : mooseError(oss.str()); 98 0 : }