bugGNU Octave - Bugs: bug #63415, Error in fwrite() or rand() or...

 
 

bug #63415: Error in fwrite() or rand() or randn(), I'm not sure

Submitter:  José Luis García Pallero <jgpallero>
Submitted:  Fri 25 Nov 2022 09:18:24 AM UTC
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Works For Me Assigned to:  None
Originator Name:  José Luis García Pallero Open/Closed:  * Open
Release:  * stable Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

( Jump to the original submission )

Sat 10 Dec 2022 09:00:54 PM UTC, comment #19: 

Thanks for the test, Sébastien. I've compiled again the stable branch and I have the error again only in GUI mode (CLI mode works OK). I can't understand where the problem is in my installation, and why Octave 7.3.0 works, but not stable nor 9.0.0. Attached I send my ./configure output

(file #54080)

José Luis García Pallero <jgpallero>
Sat 10 Dec 2022 03:00:19 PM UTC, comment #18: 

commentaire #9 :

> I'm also copying Sébastien Villemot, the Octave maintainer on Debian. @svillemot: could you run the test from comment #2 on Debian Sid and see if the assertions pass please?


I compiled Octave 8.0.1 (hg id: ccbf38427774) by hand on Debian unstable/sid, on an amd64 machine, and ran the test from comment #2. All the assertions pass.

Also note that I plan to upload Octave 8 to Debian experimental as soon as there is a release candidate available.

Sébastien Villemot <svillemot>
Sun 27 Nov 2022 02:00:13 PM UTC, comment #17: 

Yes, if this bug is to be reproduced, doing so on Debian Sid would be the most promising route. Once the release candidate is made for Octave 8.1, it will be tested in various distros including Debian and that should hopefully trap the error, whether it's in Octave or an external library.

The "official" Octave on the Debian Sid is still 7.3 as of now. https://packages.debian.org/sid/octave

Arun Giridhar <arungiridhar>
Project Member
Sun 27 Nov 2022 12:37:31 PM UTC, comment #16: 

I have tried on 2 computers (Ryzen 3950 and i-9880h) with Fedora 37
(gcc version 12.2.1 20221121 (Red Hat 12.2.1-4)) and on 2
computers (CoreDuo T9900 and RaspberryPI4 (aarm64))
with Ubuntu 22.10 (gcc 12.2.0-3). I cannot reproduce neither
fwrite() nor gui-not-starting problem. Tried both 8.0.1 and 9.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sun 27 Nov 2022 10:43:15 AM UTC, comment #15: 

New compilation test:

All configured as ./configure --prefix=/opt/octave/ CFLAGS=-O3 FFLAGS=-O3 CXXFLAGS=-O3. The only difference between the configure results are:

  • In Octave 7.3.0 the PCRE libraries value is -lpcre, while in stable and default PCRE libraries value is -lpcre2-8. Inspecting my Debian installation I can see that libpcre.so is part of libpcre3-dev package, but libpcre2-8.so is part of libpcre2-dev. libpcre3 is a dependency for LibreOffice, Okular and other related libraries. libpcre2 is a dependency for lots of packeges
  • In Octave 7.3.0 there is the configuration TERM libraries: -lncurses, but this not appears in stable nor default

Attached I send the three configuration results

The results related with the use of fwrite are the same as I posted in past messages:

  • Using Octave in CLI mode all works fine with 7.3.0, stable and default
  • Using Octave in GUI mode only 7.3.0 version works

I've reconfigured the stable branch with --without-pcre2 in order to force the use of -lpcre, and then recompiled the 8.0.1, but the error with fwrite is still present.

My GCC version in Debian Sid is 4:12.2.0-1 (Debian repository nomenclature)

(file #54026, file #54027, file #54028)

José Luis García Pallero <jgpallero>
Sat 26 Nov 2022 06:44:16 PM UTC, comment #14: 

I confirm that the error is also present compiling the 8.0.1 sources with -O2. Also the call with the argument --gui produces sometimes, not always, a stand by and no launching

José Luis García Pallero <jgpallero>
Sat 26 Nov 2022 04:45:58 PM UTC, comment #13: 

comentario nº11:

> Recompile with "-O2". "-O3" will not give you anything but trouble.
>


But up to now -O3 always worked fine. Compilation of Octave 7.3.0 does not show the problem. Anyway, I'll compile 8.0.1 with -O2

José Luis García Pallero <jgpallero>
Sat 26 Nov 2022 04:42:34 PM UTC, comment #12: 

@jgpallero: Never mind then. Since I am not on Debian myself, I'm trying to see if anyone on Debian Unstable (Sid) can replicate it. If so, then the Debian CI and packaging process will be able to give more clarity.

Arun Giridhar <arungiridhar>
Project Member
Sat 26 Nov 2022 04:38:02 PM UTC, comment #11: 

Recompile with "-O2". "-O3" will not give you anything but trouble.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sat 26 Nov 2022 03:20:22 PM UTC, comment #10: 

comentario nº9:

> @jgpallero: Is it feasible for you to test on a different Debian machine, one running Testing or Stable but not Sid?
>


No, it's impossible for me. Other alternative could be I upload my compilation to some place as google Drive or Dropbox and then you can run it on your machine. The folder has a size of 275 MB compressed in tar.gz. But I'm not sure if you could run it due to dynamic linking and possible differente libarry names in Debian and other Linux distros. Is it possible to compile Octave as static linking? In this case I could upload the final binary in order you can check it

José Luis García Pallero <jgpallero>
Sat 26 Nov 2022 02:14:39 PM UTC, comment #9: 

@jgpallero: Is it feasible for you to test on a different Debian machine, one running Testing or Stable but not Sid?

I'm also copying Sébastien Villemot, the Octave maintainer on Debian. @svillemot: could you run the test from comment #2 on Debian Sid and see if the assertions pass please?

Arun Giridhar <arungiridhar>
Project Member
Fri 25 Nov 2022 06:27:00 PM UTC, comment #8: 

comentario nº7:

> Your hg id has a + at the end indicating that you made local changes to it after downloading. Yes, I agree with testing with a fresh install.


Yes, it corresponds to my changes in the es_ES ts file for localization.

I've compiled the changeset

>> ver
GNU Octave Version: 8.0.1 (hg id: fd8c0df759bb)

but the problem is still present. I can't understand it. Attached I send the final output of my ./configure. I'm running Debian Sid with GCC 12.2.0-9 from the official repositories

(file #54018)

José Luis García Pallero <jgpallero>
Fri 25 Nov 2022 04:02:03 PM UTC, comment #7: 

Your hg id has a + at the end indicating that you made local changes to it after downloading. Yes, I agree with testing with a fresh install.

Arun Giridhar <arungiridhar>
Project Member
Fri 25 Nov 2022 03:51:22 PM UTC, comment #6: 

In my case, ver command output is

GNU Octave Version: 8.0.1 (hg id: 76140113e6cc+)

About your suggestion on writing first the random numbers and then the eye matrix, but the result is the same:

error: assert (stat ("m_rand.bin").size == numel (matB) * 8) failed
error: called from
    assert at line 107 column 11
    prueba_fwrite at line 8 column 1

Using fflush() before fclose() does not solve the problem.

I've cloned again, hg clone https://hg.octave.org/octave -r stable, run ./bootstrap, and ./configure --prefix=/opt/octave/ CFLAGS=-O3 FFLAGS=-O3 CXXFLAGS=-O3. I'll write the new results

José Luis García Pallero <jgpallero>
Fri 25 Nov 2022 02:15:01 PM UTC, comment #5: 

@jgpallero: If you write the random numbers first and the eye() matrix later, do you see the same problem with rand, or does it go to the second file now? Also, does calling fflush() before closing the file make any difference?

Arun Giridhar <arungiridhar>
Project Member
Fri 25 Nov 2022 01:54:23 PM UTC, comment #4: 

Sorry, I am still unable to replicate the file mismatch.

If you type "ver" in Octave it should give you the hg id next to the Octave version:

>> ver
----------------------------------------------------------------------
GNU Octave Version: 8.0.1 (hg id: fa254b08f949)

I am now using your compilation settings, except for the installation prefix. My gcc version is 12.2.0.

Octave is now configured for x86_64-pc-linux-gnu

  Source directory:              ..
  Installation prefix:           /usr/local
  C compiler:                    gcc  -pthread -fopenmp  -Wall -W -Wshadow -Wformat -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wcast-align -Wcast-qual -O3
  C++ compiler:                  g++  -pthread -fopenmp  -Wall -W -Wshadow -Woverloaded-virtual -Wold-style-cast -Wformat -Wpointer-arith -Wwrite-strings -Wcast-align -Wcast-qual -O3
  Fortran compiler:              gfortran -O3 -std=legacy
  CPPFLAGS:
  Fortran libraries:             -L/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0 -L/usr/lib -L/lib -lgfortran -lm -lquadmath
  Lex libraries:
  LIBS:                          -lpthread -lm
  LDFLAGS:
  Extra LDFLAGS:

Running "./run-octave --gui" does not cause the problem for me. Installing it and running plain "octave" does not do it either.

Does anyone have an idea what might cause binary mode file writing to stop part-way through?

Regarding the not-starting part: it's only affected some users on Windows before, but does it make a difference if you delete your GUI ini file so that Octave can recreate it? On my system it is located at

$HOME/.config/octave/octave-gui.ini

Arun Giridhar <arungiridhar>
Project Member
Fri 25 Nov 2022 01:17:41 PM UTC, comment #3: 

I'm running Debian Sid and I always configure Octave in the compilation as ./configure --prefix=/opt/octave/ CFLAGS=-O3 FFLAGS=-O3 CXXFLAGS=-O3

I ran your test and it works with version 8.0.1, BUT only in CLI mode:

Variables visible from the current scope:

variables in scope: top scope

  Attr   Name        Size                     Bytes  Class
  ====   ====        ====                     =====  =====
         matA      100x150                      800  double
         matB      100x150                   120000  double
         matC    15000x1                     120000  double
         matD    15000x1                     120000  double
         n           1x1                          8  double

Total is 60001 elements using 360808 bytes

If I execute the script from the GUI I obtain

error: assert (stat ("m_rand.bin").size == numel (matB) * 8) failed
error: called from
    assert at line 107 column 11
    prueba_fwrite at line 15 column 1

Also, I'm having problems starting octave --gui with 8.0.1. Sometimes the program does not launch, but no error is emitted in the command line, it only maintains waiting. If I execute ps -U user I obtain, related with Octave,

107657 pts/10   00:00:00 octave
107658 ?        00:00:04 octave-gui

I don't know which hg id I cloned exactly (I deleted the folder after compilation), but I did it after the call for translators message were posted.

With Octave 7.3.0 all works fine in both CLI and GUI modes

José Luis García Pallero <jgpallero>
Fri 25 Nov 2022 12:24:07 PM UTC, comment #2: 

Works for me with both default and stable:

GNU Octave Version: 8.0.1 (hg id: fa254b08f949)
GNU Octave Version: 9.0.0 (hg id: ce5b4a00b022)

I expanded your test like this.

clear all

fid = fopen ("m_eye.bin", "wb", "ieee-le");
matA = eye (100,150);
n = fwrite (fid, matA, "double");
fclose(fid);

assert (stat ("m_eye.bin").size == numel(matA) * 8)

fid = fopen ("m_rand.bin", "wb", "ieee-le");
matB = rand (100,150);
n = fwrite (fid, matB, "double");
fclose(fid);

assert (stat ("m_rand.bin").size == numel(matB) * 8)

fid = fopen ("m_eye.bin", "rb");
matC = fread (fid, inf, "double");
fclose(fid);

fid = fopen ("m_rand.bin", "rb");
matD = fread (fid, inf, "double");
fclose(fid);

assert (all (matC == matA(:)))
assert (all (matD == matB(:)))

clear ans fid
whos

It passes all assertions for me and the file sizes are 120000 bytes each.

What OS are you running on? Is it on a local disk or a network drive? (Not sure if it would make a difference, but it's good to rule out disk caching interference.)

Arun Giridhar <arungiridhar>
Project Member
Fri 25 Nov 2022 09:21:50 AM UTC, comment #1: 

The error is also present using 'float' as data type

José Luis García Pallero <jgpallero>
Fri 25 Nov 2022 09:18:24 AM UTC, original submission:  

Hello:

Yesterday (November, 24th) I cloned the stable branch of Octave (hg clone https://hg.octave.org/octave -r stable) and I compiled it (version command output is 8.1.0)

When I try to print a matrix generated by rand function to a binary file I obtain an incorrect size. See this code:

idf = fopen('m_eye.bin','wb','ieee-le');
mat = eye(100,150);
n = fwrite(idf,mat,'double')
fclose(idf);

idf = fopen('m_rand.bin','wb','ieee-le');
mat = rand(100,150);
n = fwrite(idf,mat,'double')
fclose(idf);

The first file contains a matrix generated by eye and written as 'double' format. As its dimensions are 100x150 the final file size if 100*150*8=120000 bytes. But in the second case the matrix is generated by rand function and the size of the file created is  114971 bytes (the size varies between different executions), so I think there is an error in fwrite() function or maybe in rand() or even in randn(), which produces also wrong size in the file.

But all works well with Octave 7.3.0, the file sizes are correct

José Luis García Pallero <jgpallero>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #54080:  configure-octave-stable added by jgpallero (7KiB - application/octet-stream)
file #54026:  configure-7.3.0 added by jgpallero (7KiB - application/octet-stream)
file #54027:  configure-default added by jgpallero (7KiB - application/octet-stream)
file #54028:  configure-stable added by jgpallero (7KiB - application/octet-stream)
file #54018:  configure added by jgpallero (7KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by svillemot (Posted a comment)
  • -email is unavailable- added by arungiridhar (Octave file creation problem reported for Debian Sid)
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by arungiridhar (Octave file creation problem reported for Debian Sid)
  • -email is unavailable- added by arungiridhar (Posted a comment)
  • -email is unavailable- added by jgpallero (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 project members can vote.

     

     

     

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-12-10 jgpallero Attached File- Added configure-octave-stable, #54080
    2022-11-27 arungiridhar Carbon-Copy- Added rlaboiss
    2022-11-27 jgpallero Attached File- Added configure-7.3.0, #54026
        Attached File- Added configure-default, #54027
        Attached File- Added configure-stable, #54028
    2022-11-26 arungiridhar Carbon-Copy- Added svillemot
    2022-11-25 jgpallero Attached File- Added configure, #54018
    2022-11-25 arungiridhar Release8.0.90 stable
    2022-11-25 arungiridhar StatusNone Works For Me

    Back to the top

    Powered by Savane 3.10