bugGNU Octave - Bugs: bug #58052, [octave forge] (parallel) problem...

 
 

bug #58052: [octave forge] (parallel) problem with random number initialization

Submitter:  Mark van Rossum <cosine>
Submitted:  Thu 26 Mar 2020 07:24:27 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 5.2.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 11 Apr 2020 01:34:15 PM UTC, comment #7: 

thank you for looking into it.
I will test once the new version comes out.

Mark van Rossum <cosine>
Sat 11 Apr 2020 09:45:26 AM UTC, comment #6: 

The parallel package now uses newly started (not just forked) Octave sessions, even for parcellfun/pararrayfun. A release is pending. This probably makes this report not applicable anymore.

If the problem persists (I can't imagine how), please re-open.

Olaf Till <i7tiol>
Group Member
Wed 08 Apr 2020 02:50:18 PM UTC, comment #5: 

There is a bug in the parcellfun package.
It tries to randomly initialize the random generators, but it does not.

I found two possible solutions.
replace in parcellfun.m line 246
 seed = iproc (flintmax () - 1); # backwards compatibility
with
 seed = iproc;

Or replace
cellfun (@ (fun) fun ("state", seed), random_func_list);
with
cellfun (@ (fun) fun ("state", "reset"), random_func_list);


The underlying reason is that
 s=1*(flintmax ()-1); rand("state",s); rand
produces the same random number as
 s=2*(flintmax ()-1); rand("state",s); rand

It would be good it the maintainers could look at this.

Mark van Rossum <cosine>
Mon 30 Mar 2020 04:07:02 PM UTC, comment #4: 

My trick of calling
   rand("state","reset")
only works for rand() calls, but not for randn() calls.

I attach a script that shows this.

(file #48716)

Mark van Rossum <cosine>
Fri 27 Mar 2020 05:44:40 PM UTC, comment #3: 

Ok, I haven't looked at the documentation, but if that's how it's specified, then I guess that is supposed to be a feature of the package.

Mike Miller <mtmiller>
Group Member
Fri 27 Mar 2020 05:42:12 PM UTC, comment #2: 

Hi,

The documentation of parcellfun says:

"The pseudo random number generators of each process are initialised with a unique state. This currently works only for new style generators."

And given that pararrayfun is just a wrapper for parcellfun, I think it is not the desired behavior.

If pararrayfun is supposed to act differently, it would be good to document that.

Mark van Rossum <cosine>
Fri 27 Mar 2020 04:31:39 PM UTC, comment #1: 

This is probably indeed a feature of how the parallel package works. I believe it forks the Octave process, so each fork probably does inherit an identical random number generator state at the point of creation.

Mike Miller <mtmiller>
Group Member
Thu 26 Mar 2020 07:24:27 PM UTC, original submission:  

Hi

I'm running Octave 5.2.0 with parallel 3.1.3, and the patch of #56477. i7-8650, ubuntu 20.04

I attach a test script. It calculates independent sums of randn numbers.
However, when run using parrayfun the values returned are quite often the same. This is very unlikely to happen statistically.

It might be due to the random number not being seeded on every call.
When I seed the generator within every call with rand("state","reset"), results are as expected.


Mark van Rossum <cosine>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #48716:  octave_rand_parraryfun.m added by cosine (859B - application/vnd.wolfram.mathematica.package)
file #48680:  bug2.m added by cosine (655B - application/vnd.wolfram.mathematica.package)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by i7tiol (Posted a comment)
  • -email is unavailable- added by cosine
  • -email is unavailable- added by cosine
  • -email is unavailable- added by cosine (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-04-11 i7tiol StatusNone Fixed
        Open/ClosedOpen Closed
    2020-04-08 cosine Carbon-Copy- Added -email is unavailable-
        Carbon-Copy- Added -email is unavailable-
    2020-03-30 cosine Attached File- Added octave_rand_parraryfun.m, #48716
    2020-03-27 mtmiller SummaryOctave forge parallel, problem with random number initialization [octave forge] (parallel) problem with random number initialization
    2020-03-26 cosine Attached File- Added bug2.m, #48680

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code