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

Comparing ray/src/rt/pmapcontrib.c (file contents):
Revision 2.14 by rschregle, Mon Aug 14 21:12:10 2017 UTC vs.
Revision 2.18 by rschregle, Thu Jun 7 19:26:04 2018 UTC

# Line 25 | Line 25 | static const char RCSid[] = "$Id$";
25   #include "otypes.h"
26   #if NIX
27     #include <sys/mman.h>
28 <   #include <sys/wait.h>
28 >   #include <sys/wait.h>  
29   #endif
30  
31  
# Line 60 | Line 60 | static PhotonPrimaryIdx newPhotonPrimary (PhotonMap *p
60      
61     if (primRay) {
62        FVECT dvec;
63 <      
63 >
64 > #ifdef PMAP_PRIMARYDIR            
65        /* Reverse incident direction to point to light source */
66        dvec [0] = -primRay -> rdir [0];
67        dvec [1] = -primRay -> rdir [1];
68        dvec [2] = -primRay -> rdir [2];
69        pmap -> lastPrimary.dir = encodedir(dvec);
70 + #endif      
71   #ifdef PMAP_PRIMARYPOS      
72        VCOPY(pmap -> lastPrimary.pos, primRay -> rop);
73   #endif      
# Line 170 | Line 172 | typedef  unsigned long  PhotonContribCnt;
172  
173  
174  
175 +
176 +
177 +
178   void distribPhotonContrib (PhotonMap* pm, unsigned numProc)
179   {
180     EmissionMap       emap;
# Line 225 | Line 230 | void distribPhotonContrib (PhotonMap* pm, unsigned num
230     if (!pm -> distribTarget)
231        error(INTERNAL, "no photons to distribute in distribPhotonContrib");
232    
233 <   /* Get photon ports if specified */
234 <   if (ambincl == 1)
230 <      getPhotonPorts();
233 >   /* Get photon ports from modifier list */
234 >   getPhotonPorts(photonPortList);
235        
236     /* Get photon sensor modifiers */
237     getPhotonSensors(photonSensorList);      
# Line 356 | Line 360 | void distribPhotonContrib (PhotonMap* pm, unsigned num
360  
361           /* Seed RNGs from PID for decorellated photon distribution */
362           pmapSeed(randSeed + proc, partState);
363 <         pmapSeed(randSeed + proc, emitState);
364 <         pmapSeed(randSeed + proc, cntState);
365 <         pmapSeed(randSeed + proc, mediumState);
366 <         pmapSeed(randSeed + proc, scatterState);
367 <         pmapSeed(randSeed + proc, rouletteState);
363 >         pmapSeed(randSeed + (proc + 1) % numProc, emitState);
364 >         pmapSeed(randSeed + (proc + 2) % numProc, cntState);
365 >         pmapSeed(randSeed + (proc + 3) % numProc, mediumState);
366 >         pmapSeed(randSeed + (proc + 4) % numProc, scatterState);
367 >         pmapSeed(randSeed + (proc + 5) % numProc, rouletteState);
368 >
369 > #ifdef PMAP_SIGUSR                      
370 >   double partNumEmit;
371 >   unsigned long partEmitCnt;
372 >   double srcPhotonFlux, avgPhotonFlux;
373 >   unsigned       portCnt, passCnt, prePassCnt;
374 >   float          srcPreDistrib;
375 >   double         srcNumEmit;     /* # to emit from source */
376 >   unsigned long  srcNumDistrib;  /* # stored */
377 >
378 >   void sigUsrDiags()
379 >   /* Loop diags via SIGUSR1 */
380 >   {
381 >      sprintf(errmsg,
382 >              "********************* Proc %d Diags *********************\n"
383 >              "srcIdx = %d (%s)\nportCnt = %d (%s)\npassCnt = %d\n"
384 >              "srcFlux = %f\nsrcPhotonFlux = %f\navgPhotonFlux = %f\n"
385 >              "partNumEmit = %f\npartEmitCnt = %lu\n\n",
386 >              proc, srcIdx, findmaterial(source [srcIdx].so) -> oname,
387 >              portCnt, photonPorts [portCnt].so -> oname,
388 >              passCnt, srcFlux [srcIdx], srcPhotonFlux, avgPhotonFlux,
389 >              partNumEmit, partEmitCnt);
390 >      eputs(errmsg);
391 >      fflush(stderr);
392 >   }
393 > #endif
394          
395 + #ifdef PMAP_SIGUSR
396 +         signal(SIGUSR1, sigUsrDiags);
397 + #endif        
398 +
399 + #ifdef DEBUG_PMAP          
400 +         /* Output child process PID after random delay to prevent corrupted
401 +          * console output due to race condition */
402 +         usleep(1e6 * pmapRandom(rouletteState));
403 +         fprintf(stderr, "Proc %d: PID = %d "
404 +                 "(waiting 10 sec to attach debugger...)\n",
405 +                 proc, getpid());
406 +         /* Allow time for debugger to attach to child process */
407 +         sleep(10);
408 + #endif
409 +
410           /* =============================================================
411            * 2-PASS PHOTON DISTRIBUTION
412            * Pass 1 (pre):  emit fraction of target photon count
413            * Pass 2 (main): based on outcome of pass 1, estimate remaining
414            *                number of photons to emit to approximate target
415            *                count
416 <          * ============================================================= */        
416 >          * ============================================================= */
417           for (srcIdx = 0; srcIdx < nsources; srcIdx++) {
418 + #ifndef PMAP_SIGUSR        
419              unsigned       portCnt, passCnt = 0, prePassCnt = 0;
420              float          srcPreDistrib = preDistrib;
421              double         srcNumEmit = 0;       /* # to emit from source */
422              unsigned long  srcNumDistrib = pm -> numPhotons;  /* # stored */
423 + #else
424 +            passCnt = prePassCnt = 0;
425 +            srcPreDistrib = preDistrib;
426 +            srcNumEmit = 0;       /* # to emit from source */
427 +            srcNumDistrib = pm -> numPhotons;  /* # stored */
428 + #endif            
429  
430              if (srcFlux [srcIdx] < FTINY)
431                 continue;
# Line 381 | Line 433 | void distribPhotonContrib (PhotonMap* pm, unsigned num
433              while (passCnt < 2) {
434                 if (!passCnt) {  
435                    /* INIT PASS 1 */
436 <                  if (++prePassCnt > maxPreDistrib && !proc) {
436 >                  if (++prePassCnt > maxPreDistrib) {
437                       /* Warn if no photons contributed after sufficient
438                        * iterations; only output from subprocess 0 to reduce
439                        * console clutter */
440 <                     sprintf(errmsg,
441 <                             "source %s: too many prepasses, skipped",
442 <                             source [srcIdx].so -> oname);
443 <                     error(WARNING, errmsg);
440 >                     if (!proc) {
441 >                        sprintf(errmsg,
442 >                                "source %s: too many prepasses, skipped",
443 >                                source [srcIdx].so -> oname);
444 >                        error(WARNING, errmsg);
445 >                     }
446 >
447                       break;
448                    }
449                    
# Line 397 | Line 452 | void distribPhotonContrib (PhotonMap* pm, unsigned num
452                 }
453                 else {
454                    /* INIT PASS 2 */
455 + #ifndef PMAP_SIGUSR
456                    double srcPhotonFlux, avgPhotonFlux;
457 + #endif
458                    
459                    /* Based on the outcome of the predistribution we can now
460                     * figure out how many more photons we have to emit from
# Line 419 | Line 476 | void distribPhotonContrib (PhotonMap* pm, unsigned num
476                    srcPhotonFlux = srcFlux [srcIdx] / srcNumEmit;
477                    avgPhotonFlux = photonFluxSum / (srcIdx + 1);
478                    
479 <                  if (avgPhotonFlux > 0 &&
479 >                  if (avgPhotonFlux > FTINY &&
480                        srcPhotonFlux / avgPhotonFlux < FTINY) {
481                       /* Skip source if its photon flux is grossly below the
482                        * running average, indicating negligible contributions
483                        * at the expense of excessive distribution time; only
484                        * output from subproc 0 to reduce console clutter */
485 <                     sprintf(errmsg,
486 <                             "source %s: itsy bitsy photon flux, skipped",
487 <                             source [srcIdx].so -> oname);
488 <                     error(WARNING, errmsg);
489 <                     srcNumEmit = 0;
485 >                     if (!proc) {
486 >                        sprintf(errmsg,
487 >                                "source %s: itsy bitsy photon flux, skipped",
488 >                                source [srcIdx].so -> oname);                    
489 >                        error(WARNING, errmsg);
490 >                     }
491 >
492 >                     srcNumEmit = 0;   /* Or just break??? */
493                    }
494                          
495                    /* Update sum of photon flux per light source */
# Line 470 | Line 530 | void distribPhotonContrib (PhotonMap* pm, unsigned num
530                    
531                    for (emap.partitionCnt = 0; emap.partitionCnt < emap.numPartitions;
532                         emap.partitionCnt++) {
533 + #ifndef PMAP_SIGUSR                      
534                       double partNumEmit;
535                       unsigned long partEmitCnt;
536 + #endif
537                      
538                       /* Get photon origin within current source partishunn
539                        * and build emission map */
# Line 568 | Line 630 | void distribPhotonContrib (PhotonMap* pm, unsigned num
630                   pm -> numPhotons);
631           eputs(errmsg);
632           fflush(stderr);
633 + #endif
634 +
635 + #ifdef PMAP_SIGUSR
636 +         signal(SIGUSR1, SIG_DFL);
637   #endif
638  
639   #if NIX

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines