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.