random number generator - mersenne twister

Hello forum,

I have a small physically based renderer where one of the most important task is to generate canonical random numbers. I used have my self-customized random number generator class and it used to give me some bizarre artifacts.

Once i get to know that C++ also started to support the fast radom number generator engine i wanted to give it a try. Unfortunately i am getting the core dumped segmentation fault.

I need to generate random integer numbers and generate the canonical random numbers. I am doing it as follows:

GENERATE INTEGER RANDOM NUMBER
1
2
 std::mt19937 generator(seed);
 unsigned int jump = (generator() % mNumSets) * mNumSamples;



GENERATE CANONICAL RANDOM NUMBER

1
2
 std::mt19937 generator(seed);
float whichRayToTrace = generate_canonical<float,std::numeric_limits<float>::digits>(generator);


If i run the example code given in the reference they run fine.

Then i tried gdb and back trace stopped somewhere which does not make any sense
because that part of the code is already validated.


Any thoughts on this?

Please ask me if you need any more details.


Regards
Sajjad
The code you posted has no errors (assuming non-zero mNumSets), although it would be more typically written using distributions:

1
2
3
4
5
    std::uniform_int_distribution<> d1(0, mNumSets-1);
    unsigned int jump = mNumSamples * d1(generator);

    std::uniform_real_distribution<> d2(0, 1);
    float whichRayToTrace = d2(generator);


The error was caused by something else. What does gdb backtrace show?
Last edited on
I wish i could paste the backtrace ouput. But the output is too long. And now, the program is running , but gives a wrong output.

Is there anything with the seed value. I am defining static constant seed value as follows:

 
static const unsigned seed =  std::chrono::system_clock::now().time_since_epoch().count();


Is it right to do so?

I wish i could reproduce the backtrace output to help me track it. But i am not getting the segmentation fault anymore.

What else could you suggest me?


Regards
Sajjad
I prefer calling std::random_device to seed generators, but this isn't an error either.
Hi

I managed to recreate the segmentation fault. The coding style i followed is mentioned in your previous post. The GDB output is:


[code]
creating image (1024x1024)
creating camera
preparing scene...
BVH construction done in 0.03 seconds
creating ray tracer
Path tracing...
[New Thread 0x7ffff2ae1700 (LWP 5586)]
[New Thread 0x7ffff22e0700 (LWP 5587)]
[New Thread 0x7ffff1adf700 (LWP 5588)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff2ae1700 (LWP 5586)]
0x00007ffff78112f5 in __sincosf (x=0.851227164, sinx=0x7ffff22e20fc, cosx=0x7ffff22e20f8) at ../sysdeps/ieee754/flt-32/s_sincosf.c:52
52 ../sysdeps/ieee754/flt-32/s_sincosf.c: No such file or directory.

[/code


Looking forward to more on this issue.


Regards
Sajjad
Off-hand it seems that the thread 5586 is writing to objects that belong to thread 5587 when they happen to be inaccessible. I'd start by examining your synchronization logic.
I am using openmp to make it run parallel. The code snippet for it is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
void PathTracer::computeImage()
{
   std::cout << "Path tracing..." << std::endl;
   
   //map the samples to hemisphere with 
   //cosine weighted density function
   //mSampler->mapSamplesToHemisphere(1);
   
   Timer timer;
   
   Color c;

   //get the width and height of the image
   int width = mImage->getWidth();
   int height = mImage->getHeight();
   
   // Loop over all pixels in the image
   #pragma omp parallel for schedule(dynamic,1), private(c)
   for (int y = 0; y < height; y++)
     {
       for (int x = 0; x < width; x++)
         {
           // Raytrace the pixel at (x,y).
           c = tracePixel(x,y);
           
           // Store the result in the image.
           mImage->setPixel(x,y,c);
         }

       #pragma omp critical
       // Print progress approximately every 5%.
       if ((y+1) % (height/20) == 0 || (y+1) == height)
         std::cout << (100*(y+1)/height) << "% done" << std::endl;
     }
   
   std::cout << "Done in " << timer.stop() << " seconds" << std::endl;

}



Anything more i can provide you with?
Topic archived. No new replies allowed.