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.14 by greg, Mon Aug 5 19:51:18 2024 UTC vs.
Revision 2.22 by greg, Wed Nov 13 02:43:51 2024 UTC

# Line 106 | Line 106 | check_special(const char *s)
106  
107   // Append program line to header
108   bool
109 < RadSimulManager::AddHeader(int ac, const char *av[])
109 > RadSimulManager::AddHeader(int ac, char *av[])
110   {
111          if ((ac <= 0) | !av) return false;
112          int     len = 0;
# Line 141 | Line 141 | RadSimulManager::AddHeader(int ac, const char *av[])
141          return true;
142   }
143  
144 + // Look for specific header keyword, return value
145 + const char *
146 + RadSimulManager::GetHeadStr(const char *key, bool inOK) const
147 + {
148 +        if (!key | !hlen || strchr(key, '\n'))
149 +                return NULL;
150 +        if (inOK)                       // skip leading spaces?
151 +                while (isspace(*key)) key++;
152 +
153 +        const int       klen = strlen(key);
154 +        if (!klen)
155 +                return NULL;
156 +        const char *    cp = header;
157 +        while (*cp) {
158 +                if (inOK) {             // skip leading spaces?
159 +                        while (isspace(*cp) && *cp++ != '\n')
160 +                                ;
161 +                        if (cp[-1] == '\n')
162 +                                continue;
163 +                }
164 +                if (!strncmp(cp, key, klen))
165 +                        return cp+klen; // found it!
166 +
167 +                while (*cp && *cp++ != '\n')
168 +                        ;
169 +        }
170 +        return NULL;
171 + }
172 +
173   // How many processors are available?
174   int
175   RadSimulManager::GetNCores()
# Line 167 | Line 196 | RadSimulManager::SetThreadCount(int nt)
196          return NThreads();
197   }
198  
170 // Assign ray to subthread (fails if NThreads()<2)
171 bool
172 RadSimulManager::SplitRay(RAY *r)
173 {
174        if (!ray_pnprocs || ThreadsAvailable() < 1)
175                return false;
176
177        return (ray_psend(r) > 0);
178 }
179
199   // Process a ray (in subthread), optional result
200 < bool
200 > int
201   RadSimulManager::ProcessRay(RAY *r)
202   {
203          if (!Ready()) return false;
# Line 186 | Line 205 | RadSimulManager::ProcessRay(RAY *r)
205          if (!ray_pnprocs) {     // single-threaded mode?
206                  samplendx++;
207                  rayvalue(r);
208 <                return true;
208 >                return 1;
209          }
210 <        int     rv = ray_pqueue(r);
192 <        if (rv < 0) {
193 <                error(WARNING, "ray tracing process(es) died");
194 <                return false;
195 <        }
196 <        return (rv > 0);
210 >        return ray_pqueue(r);
211   }
212  
213   // Wait for next result (or fail)
# Line 210 | Line 224 | RadSimulManager::WaitResult(RAY *r)
224   int
225   RadSimulManager::Cleanup(bool everything)
226   {
227 +        if (ray_pnprocs < 0)
228 +                return 0;               // skip in child process
229          NewHeader();
230          if (!ray_pnprocs)
231                  ray_done(everything);
# Line 218 | Line 234 | RadSimulManager::Cleanup(bool everything)
234          return 0;
235   }
236  
221 // How many threads are currently unoccupied?
222 int
223 RadSimulManager::ThreadsAvailable() const
224 {
225        if (!ray_pnprocs) return 1;
226
227        return ray_pnidle;
228 }
229
237   // Global pointer to simulation manager for trace call-back (only one)
238   static const RtraceSimulManager *       ourRTsimMan = NULL;
239  
# Line 248 | Line 255 | RtraceSimulManager::Rfifout(RAY *r)
255   bool
256   RtraceSimulManager::UpdateMode()
257   {
251        rtFlags &= RTmask;
258          if (!cookedCall)
259                  rtFlags &= ~RTdoFIFO;
260          if (!traceCall)
# Line 256 | Line 262 | RtraceSimulManager::UpdateMode()
262          if (rtFlags & RTimmIrrad)
263                  rtFlags &= ~RTlimDist;
264  
265 <        int     misMatch = rtFlags ^ curFlags;
265 >        int     misMatch = (rtFlags ^ curFlags) & RTmask;
266                                  // updates based on toggled flags
267 <        if (misMatch & RTtraceSources) {
267 >        if (((misMatch & RTtraceSources) != 0) & (nsources > 0)) {
268 >                int     nt = NThreads();
269 >                if (nt > 1) {
270 >                        if (FlushQueue() < 0)
271 >                                return false;
272 >                        SetThreadCount(1);
273 >                }
274 >                int     sn = nsources;
275                  if (rtFlags & RTtraceSources) {
276 <                        for (int sn = 0; sn < nsources; sn++)
276 >                        srcFollowed.NewBitMap(nsources);
277 >                        while (sn--) {
278 >                                if (source[sn].sflags & SFOLLOW)
279 >                                        continue;
280                                  source[sn].sflags |= SFOLLOW;
281 <                } else          // cannot undo this...
282 <                        rtFlags |= RTtraceSources;
281 >                                srcFollowed.Set(sn);
282 >                        }
283 >                } else {
284 >                        while (sn--)
285 >                                if (srcFollowed.Check(sn))
286 >                                        source[sn].sflags &= ~SFOLLOW;
287 >                        srcFollowed.NewBitMap(0);
288 >                }
289 >                if (nt > 1) SetThreadCount(nt);
290          }
291          if (misMatch & RTdoFIFO && FlushQueue() < 0)
292                  return false;
# Line 341 | Line 364 | RtraceSimulManager::EnqueueBundle(const FVECT orig_dir
364          while (n-- > 0) {               // queue each ray
365                  VCOPY(res.rorg, orig_direc[0]);
366                  VCOPY(res.rdir, orig_direc[1]);
367 +                res.rmax = .0;
368                  orig_direc += 2;
369                  rayorigin(&res, PRIMARY, NULL, NULL);
370                  res.rno = rID0 ? (lastRayID = rID0++) : ++lastRayID;
# Line 357 | Line 381 | RtraceSimulManager::EnqueueBundle(const FVECT orig_dir
381                                  if (ray_fifo_in(&res) < 0)
382                                          return -1;
383                                  sendRes = false;
384 <                        } else
385 <                                sendRes &= ProcessRay(&res);
384 >                        } else {
385 >                                int     rv = ProcessRay(&res);
386 >                                if (rv < 0)
387 >                                        return -1;
388 >                                sendRes &= (rv > 0);
389 >                        }
390                  } else if (ThreadsAvailable() < NThreads() &&
391                                  FlushQueue() < 0)
392                          return -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines