ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/RtraceSimulManager.cpp
(Generate patch)

Comparing ray/src/rt/RtraceSimulManager.cpp (file contents):
Revision 2.17 by greg, Mon Sep 16 19:18:32 2024 UTC vs.
Revision 2.23 by greg, Wed Nov 13 18:47:01 2024 UTC

# Line 181 | Line 181 | RadSimulManager::GetNCores()
181   int
182   RadSimulManager::SetThreadCount(int nt)
183   {
184 <        if (!Ready())
185 <                return 0;
184 >        if (!Ready()) return 0;
185  
186          if (nt <= 0) nt = castonly ? 1 : GetNCores();
187  
# Line 196 | Line 195 | RadSimulManager::SetThreadCount(int nt)
195          return NThreads();
196   }
197  
199 // Assign ray to subthread (fails if NThreads()<2)
200 bool
201 RadSimulManager::SplitRay(RAY *r)
202 {
203        if (!ray_pnprocs || ThreadsAvailable() < 1)
204                return false;
205
206        return (ray_psend(r) > 0);
207 }
208
198   // Process a ray (in subthread), optional result
199 < bool
199 > int
200   RadSimulManager::ProcessRay(RAY *r)
201   {
202 <        if (!Ready()) return false;
202 >        if (!Ready()) return -1;
203  
204          if (!ray_pnprocs) {     // single-threaded mode?
205                  samplendx++;
206                  rayvalue(r);
207 <                return true;
207 >                return 1;
208          }
209 <        int     rv = ray_pqueue(r);
221 <        if (rv < 0) {
222 <                error(WARNING, "ray tracing process(es) died");
223 <                return false;
224 <        }
225 <        return (rv > 0);
209 >        return ray_pqueue(r);
210   }
211  
212   // Wait for next result (or fail)
# Line 239 | Line 223 | RadSimulManager::WaitResult(RAY *r)
223   int
224   RadSimulManager::Cleanup(bool everything)
225   {
226 +        if (ray_pnprocs < 0)
227 +                return 0;               // skip in child process
228          NewHeader();
229          if (!ray_pnprocs)
230                  ray_done(everything);
# Line 247 | Line 233 | RadSimulManager::Cleanup(bool everything)
233          return 0;
234   }
235  
250 // How many threads are currently unoccupied?
251 int
252 RadSimulManager::ThreadsAvailable() const
253 {
254        if (!ray_pnprocs) return 1;
255
256        return ray_pnidle;
257 }
258
236   // Global pointer to simulation manager for trace call-back (only one)
237   static const RtraceSimulManager *       ourRTsimMan = NULL;
238  
# Line 277 | Line 254 | RtraceSimulManager::Rfifout(RAY *r)
254   bool
255   RtraceSimulManager::UpdateMode()
256   {
280        rtFlags &= RTmask;
257          if (!cookedCall)
258                  rtFlags &= ~RTdoFIFO;
259          if (!traceCall)
# Line 285 | Line 261 | RtraceSimulManager::UpdateMode()
261          if (rtFlags & RTimmIrrad)
262                  rtFlags &= ~RTlimDist;
263  
264 <        int     misMatch = rtFlags ^ curFlags;
264 >        int     misMatch = (rtFlags ^ curFlags) & RTmask;
265                                  // updates based on toggled flags
266 <        if (misMatch & RTtraceSources) {
266 >        if (((misMatch & RTtraceSources) != 0) & (nsources > 0)) {
267 >                int     nt = NThreads();
268 >                if (nt > 1) {
269 >                        if (FlushQueue() < 0)
270 >                                return false;
271 >                        SetThreadCount(1);
272 >                }
273 >                int     sn = nsources;
274                  if (rtFlags & RTtraceSources) {
275 <                        for (int sn = 0; sn < nsources; sn++)
275 >                        srcFollowed.NewBitMap(nsources);
276 >                        while (sn--) {
277 >                                if (source[sn].sflags & SFOLLOW)
278 >                                        continue;
279                                  source[sn].sflags |= SFOLLOW;
280 <                } else          // cannot undo this...
281 <                        rtFlags |= RTtraceSources;
280 >                                srcFollowed.Set(sn);
281 >                        }
282 >                } else {
283 >                        while (sn--)
284 >                                if (srcFollowed.Check(sn))
285 >                                        source[sn].sflags &= ~SFOLLOW;
286 >                        srcFollowed.NewBitMap(0);
287 >                }
288 >                if (nt > 1) SetThreadCount(nt);
289          }
290          if (misMatch & RTdoFIFO && FlushQueue() < 0)
291                  return false;
# Line 355 | Line 348 | RtraceSimulManager::EnqueueBundle(const FVECT orig_dir
348          int     nqueued = 0;
349          RAY     res;
350  
351 <        if (!Ready())
359 <                return -1;
351 >        if (!Ready()) return -1;
352  
353          if (castonly && !cookedCall)
354                  error(INTERNAL, "EnqueueBundle() called in castonly mode without cookedCall");
# Line 387 | Line 379 | RtraceSimulManager::EnqueueBundle(const FVECT orig_dir
379                                  if (ray_fifo_in(&res) < 0)
380                                          return -1;
381                                  sendRes = false;
382 <                        } else
383 <                                sendRes &= ProcessRay(&res);
382 >                        } else {
383 >                                int     rv = ProcessRay(&res);
384 >                                if (rv < 0)
385 >                                        return -1;
386 >                                sendRes &= (rv > 0);
387 >                        }
388                  } else if (ThreadsAvailable() < NThreads() &&
389                                  FlushQueue() < 0)
390                          return -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines