| 1 |
|
/* RCSid $Id$ */ |
| 2 |
– |
#ifndef PMAPRAND_H |
| 3 |
– |
#define PMAPRAND_H |
| 2 |
|
|
| 3 |
|
/* |
| 4 |
< |
================================================================== |
| 4 |
> |
====================================================================== |
| 5 |
|
Random number generators for photon distribution |
| 6 |
|
|
| 7 |
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
| 8 |
|
(c) Fraunhofer Institute for Solar Energy Systems, |
| 9 |
|
(c) Lucerne University of Applied Sciences and Arts, |
| 10 |
< |
supported by the Swiss National Science Foundation (SNSF, #147053) |
| 11 |
< |
================================================================== |
| 10 |
> |
supported by the Swiss National Science Foundation (SNSF, #147053) |
| 11 |
> |
====================================================================== |
| 12 |
|
|
| 13 |
+ |
$Id$ |
| 14 |
|
*/ |
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
< |
/* According to the analytical validation, skipping numbers in the sequence |
| 19 |
< |
introduces bias in scenes with high reflectance. We therefore use |
| 21 |
< |
erand48() with separate states for photon emission, scattering, and |
| 22 |
< |
russian roulette. The pmapSeed() and pmapRandom() macros can be adapted |
| 23 |
< |
to other (better?) RNGs. */ |
| 18 |
> |
#ifndef PMAPRAND_H |
| 19 |
> |
#define PMAPRAND_H |
| 20 |
|
|
| 21 |
< |
#if defined(_WIN32) || defined(BSD) |
| 22 |
< |
/* Assume no erand48(), so use standard RNG without explicit multistate |
| 23 |
< |
control; the resulting sequences will be suboptimal */ |
| 24 |
< |
#include "random.h" |
| 25 |
< |
|
| 26 |
< |
#define pmapSeed(seed, state) (srandom(seed)) |
| 27 |
< |
#define pmapRandom(state) (frandom()) |
| 21 |
> |
/* According to the analytical validation, skipping sequential samples |
| 22 |
> |
* when sharing a single RNG among multiple sampling domains introduces |
| 23 |
> |
* overlapping photon rays (reported as 'duplicate keys' when building |
| 24 |
> |
* the underlying data structure) and therefore bias. This is aggravated |
| 25 |
> |
* when running parallel photon distribution subprocesses, where photon |
| 26 |
> |
* rays from different subprocesses may correlate. |
| 27 |
> |
* We therefore maintain a separate RNG state for each sampling domain |
| 28 |
> |
* (e.g. photon emission, scattering, and russian roulette). With |
| 29 |
> |
* multiprocessing, each subprocess has its own instance of the RNG |
| 30 |
> |
* state, which is independently seeded for decorellation -- see |
| 31 |
> |
* distribPhotons() and distribPhotonContrib(). |
| 32 |
> |
* The pmapSeed() and pmapRandom() macros below can be adapted to |
| 33 |
> |
* platform-specific RNGs if necessary. */ |
| 34 |
> |
#if defined(_WIN32) || defined(_WIN64) |
| 35 |
> |
/* Use standard RNG without state management; the generated sequences |
| 36 |
> |
* will be suboptimal */ |
| 37 |
> |
#include "random.h" |
| 38 |
> |
#define pmapSeed(seed, state) srandom(seed) |
| 39 |
> |
#define pmapRandom(state) frandom() |
| 40 |
|
#else |
| 41 |
+ |
/* Assume NIX and manage RNG state via erand48() */ |
| 42 |
|
#define pmapSeed(seed, state) (state [0] += seed, state [1] += seed, \ |
| 43 |
|
state [2] += seed) |
| 44 |
< |
#define pmapRandom(state) erand48(state) |
| 44 |
> |
#define pmapRandom(state) erand48(state) |
| 45 |
|
#endif |
| 46 |
|
|
| 47 |
< |
|
| 48 |
< |
extern unsigned short partState [3], emitState [3], cntState [3], |
| 49 |
< |
mediumState [3], scatterState [3], rouletteState [3], |
| 50 |
< |
randSeed; |
| 42 |
< |
|
| 47 |
> |
|
| 48 |
> |
extern unsigned short partState [3], emitState [3], cntState [3], |
| 49 |
> |
mediumState [3], scatterState [3], rouletteState [3], |
| 50 |
> |
randSeed; |
| 51 |
|
#endif |
| 52 |
|
|