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.15 by rschregle, Thu Feb 8 19:55:02 2018 UTC vs.
Revision 2.17 by rschregle, Tue Mar 20 19:55:33 2018 UTC

# Line 172 | Line 172 | typedef  unsigned long  PhotonContribCnt;
172  
173  
174  
175 +
176 +
177 +
178   void distribPhotonContrib (PhotonMap* pm, unsigned numProc)
179   {
180     EmissionMap       emap;
# Line 227 | 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)
232 <      getPhotonPorts();
233 >   /* Get photon ports from modifier list */
234 >   getPhotonPorts(photonPortList);
235        
236     /* Get photon sensor modifiers */
237     getPhotonSensors(photonSensorList);      
# Line 358 | 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 + #if PMAP_SIGUSR
396 +         signal(SIGUSR1, sigUsrDiags);
397 + #endif        
398 +        
399 +         /* Output child process PID after random delay to prevent corrupted
400 +          * console output due to race condition */
401 +         usleep(1e6 * pmapRandom(rouletteState));
402 +         fprintf(stderr, "Proc %d: PID = %d\n", proc, getpid());
403 +         /* Allow time for debugger to attach to child process */
404 +         sleep(10);
405 +
406           /* =============================================================
407            * 2-PASS PHOTON DISTRIBUTION
408            * Pass 1 (pre):  emit fraction of target photon count
# Line 372 | Line 411 | void distribPhotonContrib (PhotonMap* pm, unsigned num
411            *                count
412            * ============================================================= */        
413           for (srcIdx = 0; srcIdx < nsources; srcIdx++) {
414 + #ifndef PMAP_SIGUSR        
415              unsigned       portCnt, passCnt = 0, prePassCnt = 0;
416              float          srcPreDistrib = preDistrib;
417              double         srcNumEmit = 0;       /* # to emit from source */
418              unsigned long  srcNumDistrib = pm -> numPhotons;  /* # stored */
419 + #else
420 +            passCnt = prePassCnt = 0;
421 +            srcPreDistrib = preDistrib;
422 +            srcNumEmit = 0;       /* # to emit from source */
423 +            srcNumDistrib = pm -> numPhotons;  /* # stored */
424 + #endif            
425  
426              if (srcFlux [srcIdx] < FTINY)
427                 continue;
# Line 383 | Line 429 | void distribPhotonContrib (PhotonMap* pm, unsigned num
429              while (passCnt < 2) {
430                 if (!passCnt) {  
431                    /* INIT PASS 1 */
432 <                  if (++prePassCnt > maxPreDistrib && !proc) {
432 >                  if (++prePassCnt > maxPreDistrib) {
433                       /* Warn if no photons contributed after sufficient
434                        * iterations; only output from subprocess 0 to reduce
435                        * console clutter */
436 <                     sprintf(errmsg,
437 <                             "source %s: too many prepasses, skipped",
438 <                             source [srcIdx].so -> oname);
439 <                     error(WARNING, errmsg);
436 >                     if (!proc) {
437 >                        sprintf(errmsg,
438 >                                "source %s: too many prepasses, skipped",
439 >                                source [srcIdx].so -> oname);
440 >                        error(WARNING, errmsg);
441 >                     }
442 >
443                       break;
444                    }
445                    
# Line 399 | Line 448 | void distribPhotonContrib (PhotonMap* pm, unsigned num
448                 }
449                 else {
450                    /* INIT PASS 2 */
451 + #ifndef PMAP_SIGUSR
452                    double srcPhotonFlux, avgPhotonFlux;
453 + #endif
454                    
455                    /* Based on the outcome of the predistribution we can now
456                     * figure out how many more photons we have to emit from
# Line 421 | Line 472 | void distribPhotonContrib (PhotonMap* pm, unsigned num
472                    srcPhotonFlux = srcFlux [srcIdx] / srcNumEmit;
473                    avgPhotonFlux = photonFluxSum / (srcIdx + 1);
474                    
475 <                  if (avgPhotonFlux > 0 &&
475 >                  if (avgPhotonFlux > FTINY &&
476                        srcPhotonFlux / avgPhotonFlux < FTINY) {
477                       /* Skip source if its photon flux is grossly below the
478                        * running average, indicating negligible contributions
479                        * at the expense of excessive distribution time; only
480                        * output from subproc 0 to reduce console clutter */
481 <                     sprintf(errmsg,
482 <                             "source %s: itsy bitsy photon flux, skipped",
483 <                             source [srcIdx].so -> oname);
484 <                     error(WARNING, errmsg);
485 <                     srcNumEmit = 0;
481 >                     if (!proc) {
482 >                        sprintf(errmsg,
483 >                                "source %s: itsy bitsy photon flux, skipped",
484 >                                source [srcIdx].so -> oname);                    
485 >                        error(WARNING, errmsg);
486 >                     }
487 >
488 >                     srcNumEmit = 0;   /* Or just break??? */
489                    }
490                          
491                    /* Update sum of photon flux per light source */
# Line 472 | Line 526 | void distribPhotonContrib (PhotonMap* pm, unsigned num
526                    
527                    for (emap.partitionCnt = 0; emap.partitionCnt < emap.numPartitions;
528                         emap.partitionCnt++) {
529 + #ifndef PMAP_SIGUSR                      
530                       double partNumEmit;
531                       unsigned long partEmitCnt;
532 + #endif
533                      
534                       /* Get photon origin within current source partishunn
535                        * and build emission map */
# Line 570 | Line 626 | void distribPhotonContrib (PhotonMap* pm, unsigned num
626                   pm -> numPhotons);
627           eputs(errmsg);
628           fflush(stderr);
629 + #endif
630 +
631 + #ifdef PMAP_SIGUSR
632 +         signal(SIGUSR1, SIG_DFL);
633   #endif
634  
635   #if NIX

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines