Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^16: PDL and srand puzzle - PDL non-thread testing

by marioroy (Prior)
on Jun 09, 2024 at 16:25 UTC ( [id://11159851]=note: print w/replies, xml ) Need Help??


in reply to Re^15: PDL and srand puzzle - PDL non-thread testing
in thread PDL and srand puzzle

Uh, no:

I'm referring to the parallel non-thread demonstration. It does not produce predictable results unless calling CORE::rand.

Edit 1: MCE checks for PDL::Primitive->can('srand'), but missed checking PDL::Primitive->can('srandom'). I will release MCE 1.894 and MCE::Shared 1.889.

From here: Calling srand cannot be a workaround for this, because there is no interaction between Perl's RNG and PDL's. They are separate systems.

I was hoping for PDL::srandom to work before spinning non-threads and output predictable results.

Edit 2: MCE may not know or assume the srand or setter function used by the application. Therefore, I reverted back to CORE::random() for MCE's internal seed. Releasing MCE 1.895 and MCE::Shared 1.890. Update: The parallel demonstration processes a sequence of numbers, consuming lesser memory consumption. See also, Predictability Summary.

From here: I have just realised that Perl's "threads" functionality might clash with this, if it uses POSIX threads: PDL's RNG has a global vector of n seeds, in a global C variable. PDL's code will, if it is being used in what it thinks is single-threaded mode, use the 0th offset in that. If multiple POSIX threads are accessing that single seed (which gets updated on each RNG generation), there will be a race condition, hence less uniqueness.

Thank you for clarity with regards to spinning threads.

Replies are listed 'Best First'.
Re^17: PDL and srand puzzle - PDL non-thread testing
by etj (Priest) on Jun 10, 2024 at 10:49 UTC
    I'm referring to the parallel non-thread demonstration. It does not produce predictable results unless calling CORE::rand.
    So you described the situation wrong? You can have predictable results with PDL if you call random() to generate data before creating threads.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11159851]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2026-04-22 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.