"time" of ParallelContext class in Linux

The basics of how to develop, test, and use models.
Post Reply
hkur

"time" of ParallelContext class in Linux

Post by hkur »

I have a problem about 'time' of ParallelContext class.

I tried to use 'time' to get a random seed such as the following.

Code: Select all

objref pc
pc = new ParallelContext()
objref r
r = new Random( pc.time )
r.uniform(0,1)
In the case of MSwindows, this code worked well.
But, In the case of Linux (Ubuntu), r.uniform generated same random sequence anytime.
So, I typed just pc.time and ran this in Linux.
Then the output value was 0 anytime.

I have two questions:
1. Doesn't 'time' of ParallelContext class work in Linux?
2. If so, are there any efficient way to get a random seed?
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: "time" of ParallelContext class in Linux

Post by ted »

hkur wrote:I tried to use 'time' to get a random seed
That's not a good idea, even if it worked. If your purpose is research, you don't want simulation results to depend on stuff that is not under your explicit control. The system clock is a prime example of something that is outside of your control. To paraphrase myself, it may be OK for demonstration purposes but it is not a good strategy for introducing randomness into a model when you are involved in serious work such as development, debugging, or "production" ("generation of publishable results"). It destroys the ability to reproduce the results of any particular run. Worse, it destroys the ability to detect whether any change you make to your program broke anything, because you will not be able to compare results against the known output of a "good implementation." It is much better to create a set of random seeds in advance, store them in a file for future use, and read them from that file when needed.

You'll find an intelligent discussion of truly random numbers here
http://en.wikipedia.org/wiki/Hardware_r ... _generator
and some useful links here
http://en.wikipedia.org/wiki/A_Million_ ... l_Deviates
hines
Site Admin
Posts: 1607
Joined: Wed May 18, 2005 3:32 pm

Re: "time" of ParallelContext class in Linux

Post by hines »

On Linux you must not have configured to use MPI. ParallelContext.time() is a wrapper for MPI_Wtime which is for high resolution
elapsed wall time. For your purpose (which has the defects mentioned by Ted) you should use startsw().
hkur

Re: "time" of ParallelContext class in Linux

Post by hkur »

Thank you, Ted and Hines.

If I use startsw() to get the random seed and write the value of the seed into output file to enable my simulation to be replicated exactly such as following code,
is it OK or problematic?

Code: Select all

objref r, output
seed = startsw()
r = new Random(seed)
output = new File()
output.wopen("outputfile")
output.printf("%g", seed)
output.close()
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: "time" of ParallelContext class in Linux

Post by ted »

If I use startsw() to get the random seed and write the value of the seed into output file to enable my simulation to be replicated exactly such as following code,
is it OK or problematic?
The question is: what real problem does it solve? It doesn't ensure that a sequence of simulations will use seeds that are statistically independent of each other. Quite the contrary--the seeds will be an ascending sequence of integers, and if run times are nearly constant they will be nearly evenly spaced. Far better to get seeds from one of the tables of random numbers that are freely available, e.g. the contents of the Rand book.

Nor does it address these two problems, which are very real:
(1) How do I reuse a saved seed? This has to be solved sooner rather than later--preferably before anyone makes any substantive revisions to your program.
(2) How do I pair a seed with simulation results? This has to be solved before your program can be used to generate reportable results.
Post Reply