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.4 by greg, Wed Aug 2 00:04:31 2023 UTC vs.
Revision 2.5 by greg, Tue Mar 12 16:54:51 2024 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9   *  Created by Greg Ward on 2/2/2023.
10   */
11  
12 + #include <unistd.h>
13   #include "RtraceSimulManager.h"
14   #include "source.h"
15  
# Line 30 | Line 31 | RadSimulManager::LoadOctree(const char *octn)
31          return true;
32   }
33  
34 < // How many processors are there?
34 > // How many processors are available?
35   int
36   RadSimulManager::GetNCores()
37   {
38 <        return 1;               // XXX temporary
38 >        return sysconf(_NPROCESSORS_ONLN);
39   }
40  
41   // Set number of computation threads (0 => #cores)
42   int
43   RadSimulManager::SetThreadCount(int nt)
44   {
45 <        return nThreads = 1;    // XXX temporary
45 >        if (nt <= 0) nt = GetNCores();
46 >
47 >        return nThreads = nt;
48   }
49  
50   // Assign ray to subthread (fails if NThreads()<2)
# Line 51 | Line 54 | RadSimulManager::SplitRay(RAY *r)
54          if (NThreads() < 2 || ThreadsAvailable() < 1)
55                  return false;
56  
57 <        return false;   // UNIMPLEMENTED
57 >        int     rv = ray_psend(r);
58 >        if (rv < 0)
59 >                nThreads = 1;   // someone died
60 >        return (rv > 0);
61   }
62  
63   // Process a ray (in subthread), optional result
# Line 71 | Line 77 | RadSimulManager::ProcessRay(RAY *r)
77          RAY     toDo = *r;
78          if (!WaitResult(r))     // need a free thread
79                  return false;
80 <        SplitRay(&toDo);        // queue up new ray
81 <        return true;            // return older result
80 >
81 >        return SplitRay(&toDo); // queue up new ray & return old
82   }
83  
84   // Wait for next result (or fail)
85   bool
86   RadSimulManager::WaitResult(RAY *r)
87   {
88 <        return false;   // UNIMPLEMENTED
88 >        int     rv = ray_presult(r, 0);
89 >        if (rv < 0)
90 >                nThreads = 1;   // someone died
91 >        return (rv > 0);
92   }
93  
94   // Close octree, free data, return status
95   int
96   RadSimulManager::Cleanup(bool everything)
97   {
98 <        ray_done(everything);
98 >        if (NThreads() > 1)
99 >                ray_pdone(everything);
100 >        else
101 >                ray_done(everything);
102          return 0;
103   }
104  
# Line 94 | Line 106 | RadSimulManager::Cleanup(bool everything)
106   int
107   RadSimulManager::ThreadsAvailable() const
108   {
109 <        return 1;       // XXX temporary
109 >        if (NThreads() == 1) return 1;
110 >        return ray_pnidle;
111   }
112  
113   // Global pointer to simulation manager for trace call-back (only one)
# Line 223 | Line 236 | RtraceSimulManager::EnqueueBundle(const FVECT orig_dir
236                  } else if (ThreadsAvailable() < NThreads() &&
237                                  FlushQueue() < 0)
238                          return -1;
239 +
240                  if (sendRes)            // may be dummy ray
241                          (*cookedCall)(&res, ccData);
242                  nqueued++;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines