bugGNU Octave - Bugs: bug #61208, [MXE Octave] Launchers should set...


bug #61208: [MXE Octave] Launchers should set OPENBLAS_NUM_THREADS

Submitter:  Markus Mützel <mmuetzel>
Submitted:  Thu 23 Sep 2021 12:17:07 PM UTC
Category:  Configuration and Build System Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Performance
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Jump to the original submission

Wed 16 Mar 2022 10:50:09 AM UTC, comment #31: 

Forgot about this.

The first release candidate including this launcher is out, and it seems to be working afaict.

Closing as fixed.

Markus Mützel <mmuetzel>
Group administrator
Sat 27 Nov 2021 05:19:02 AM UTC, comment #30: 

works fine.

getenv("OPENBLAS_NUM_THREADS") returns 8 as it should.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 09:58:30 PM UTC, comment #29: 

I think I found the error:

I wonder why it was working so reliably for me.

Hopefully, the next nightly will show better results.

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 09:06:05 PM UTC, comment #28: 

It looks like it sets it to 2.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 08:54:51 PM UTC, comment #27: 

When it starts with the bash (without setting OPENBLAS_NUM_THREADS manually), is that environment variable set correctly in Octave?

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 08:52:48 PM UTC, comment #26: 

Neither cmd nor power shell work.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 08:43:43 PM UTC, comment #25: 

Hmm. Does it work from a different shell?
E.g. press the "Windows key"+R, then run `cmd`. Then:

cd "\Program Files\GNU Octave\Octave-7.0.0"

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 08:30:01 PM UTC, comment #24: 

No, it hangs the same way.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 08:25:56 PM UTC, comment #23: 

That is strange indeed.

Does it work if you run it by double-clicking `octave-launch.exe` directly? I.e. without using the link?

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 08:21:55 PM UTC, comment #22: 

I can try.

The funny thing i can start manually ./octave-launch.exe
from the bash shell just fine w/o setting OPENBLAS_NUM_THREADS.

But clicking on the desktop icons hangs.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 08:19:08 PM UTC, comment #21: 

Thanks. That pretty much proves that it hangs when it tries to run the newly added code.
I'll try to think of a way how we can debug this. Unfortunately, I can't reproduce the error on my system.

Would you be willing to compile some test executables on Windows?

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 08:13:57 PM UTC, comment #20: 

Thanks. Yes it works; it starts and test eigs passes.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 08:09:47 PM UTC, comment #19: 

You could use the bash that you can start with `cmdshell.bat` in Octave's installation directory and run it from there:

cd /C/Program\ Files/GNU\ Octave/Octave-7.0.1/
OPENBLAS_NUM_THREADS=4 ./octave-launch.exe

(Or `cd` to the corresponding path if you installed Octave to a non-default location.)

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 08:03:24 PM UTC, comment #18: 

I am not sure how to manually set OPENBLAS_NUM_THREADS manuall on Windows.

Launcher hangs with modified octave.vbs.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 07:55:48 PM UTC, comment #17: 

Just to clarify: The launcher still hangs even if you set OPENBLAS_NUM_THREADS manually before starting Octave?

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 07:52:44 PM UTC, comment #16: 

Yes, 10-26 starts up from vbs. test eigs fail the same way.
Using the experimental octave.vbs that you posted some time ago
it starts fine and test eigs passes.

launcher still hangs.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 07:35:58 PM UTC, comment #15: 

Thanks for testing.

Does it still start if you set OPENBLAS_NUM_THREADS manually before using the launcher?
In that case, it should just take the environment value and skip checking the number of physical cores.

Also, does Octave still start if you use the .vbs script in the installation directory?

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 07:32:26 PM UTC, comment #14: 

I think ideally we should let user to setup desired number of threads. On 16-core (32-threads) linux I set it to 8. I noticed that performance does not increase much after that. I think running too many threads increases CPU T too much so it reduces its frequency. So may be it is easier if the setting is done in some kind of  a startup script rather than in an exe .

BTW, 10-25 fails test eigs (error in dneupd) -- not sure if
this is related to too many openblas threads.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 07:23:40 PM UTC, comment #13: 

11-25 version started up OK.


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 07:09:06 PM UTC, comment #12: 

Does yesterday's build still start correctly for you? I.e., did the code that tries to determine the number of threads break it? Or is it a more general issue with the launcher?

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 07:05:57 PM UTC, comment #11: 

on Win10 pro 21H1 on i9-9880H


Dmitri A. Sergatskov <dasergatskov>
Fri 26 Nov 2021 06:59:02 PM UTC, comment #10: 

@Dmitri: Did you use the build from octave.space from today Fri, Nov 26, 2021?

Which OS version?

I installed that version here (Windows 10 21H1, Intel(R) Core(TM) i5-4690 CPU @ 3.50GHz) and it worked for me.

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Nov 2021 02:41:27 PM UTC, comment #9: 

I cannot start this octave. Task manager shows Octave Launcher
running at high CPU load, but nothing seems to be happening.
Neither cli not gui.


Dmitri A. Sergatskov <dasergatskov>
Thu 25 Nov 2021 05:45:13 PM UTC, comment #8: 

I pushed a patch for the launcher that should be setting OPENBLAS_NUM_THREADS to the number of physical processor cores:

It would be nice if someone that has a hyperthreaded system could check if OPENBLAS_NUM_THREADS is set correctly for them with that change.
The next build on octave.space (octave-mxe-default-w64) should contain this change.

Marking as ready for test.

Markus Mützel <mmuetzel>
Group administrator
Tue 23 Nov 2021 08:35:07 AM UTC, comment #7: 

Now that we are probably switching from the launcher scripts to a launcher executable for Octave 7, this needs to be re-implemented in C.
Maybe using "GetLogicalProcessorInformationEx" with "RelationProcessorCore"?

Markus Mützel <mmuetzel>
Group administrator
Tue 05 Oct 2021 06:26:47 PM UTC, comment #6: 

Oh, that must be my ignorance :-)

Why not change the comment into s/th like:

'If running with wscript.exe, calling "Exec" (needed to get nr. of CPUs) will flash a window for a split second.

([OT]  Remarkable how simple things like calling one stupid little command in the end yields relatively big patches like this, isn't it)

Philip Nienhuis <philipnienhuis>
Group Member
Mon 04 Oct 2021 07:24:33 AM UTC, comment #5: 

You are probably referring to this hunk of the patch:

diff -r 18ed05625431 -r ff1b3f3aaf6e installer-files/octave-firsttime.vbs
--- a/installer-files/octave-firsttime.vbs        Sun Sep 19 18:29:32 2021 +0200
+++ b/installer-files/octave-firsttime.vbs        Thu Sep 23 14:20:41 2021 +0200
@@ -2,11 +2,23 @@

 Set wshShell = CreateObject( "WScript.Shell" )

+' If running with wscript.exe, "Exec" will flash a window for a split second.
+' Relaunch with cscript.exe which doesn't show that window.
+If InStr(1, WScript.FullName, "wscript.exe", vbTextCompare) > 0 Then
+  AllArgs = ""
+  Set wshArgs = WScript.Arguments
+  For I = 0 to wshArgs.Count - 1
+    AllArgs = AllArgs & " " & chr(34) & wshArgs(I) & chr(34)
+  Next
+  WScript.Quit wshShell.Run("cscript.exe """ & WScript.ScriptFullName & """ " & AllArgs, 0, True)
+End If
 ' get the directory that script resides in
 Set fso = CreateObject("Scripting.FileSystemObject")
 OctavePath = fso.GetParentFolderName(WScript.ScriptFullName)

-' ctavePath is now the root of the install folder, but for msys2,
+' OctavePath is now the root of the install folder. But for msys2,
 ' OctavePath should be OctavePath/mingw64 or OctavePath/ming32
 MSysType = "MSYS"
 MSysPath = OctavePath

I was trying to be as clear as possible with the comment: It is "Exec" that causes the flashing window for me. We did not call "Exec" before that patch. So no flashing windows before that patch for me.
This patch adds a command that calls "wmic" using "Exec". That would cause the flashing window (for me) unless the hunk above is also added.

Do who have suggestions how to make that comment more easily understandable?

Markus Mützel <mmuetzel>
Group administrator
Sun 03 Oct 2021 08:40:40 PM UTC, comment #4: 

No the last years I didn't note a cmd windows flashing by when starting Octave. IIRC the .vbs start script eliminated it, and/or JWE did something a few years back so that it got silenced.
TBH I wondered why you added that part of the patch in the first place, I figured because you did see it, or someone else reported seeing it.
So, is it really needed then?

With Matlab the temporary cmd window is quite prominent, but AFAIR only with the prereleases and older releases (we still use r2014a very often as that's the last before the object-based graphics, and it's simply a bit faster); it lasts about 2-3 seconds on all Windows boxes I've been using the last years. The Matlab splash screen only shows up after that cmd window disappeared.

Indeed an Octave splash screen (IMO only for the GUI) would be a "nice to have".

Philip Nienhuis <philipnienhuis>
Group Member
Sun 03 Oct 2021 12:25:29 PM UTC, comment #3: 

Do you see a flashing cmd window when starting Octave before that patch?
That doesn't appear for me here.
I also don't see a cmd window when starting Matlab on the same machine.

If that is a change in behavior on some systems, I agree that that part should probably go in a separate (prior) patch.

I was wondering whether we could add a splash screen that shows while Octave is loading (similar to what happens when starting Excel, Matlab or other programs that take some seconds to load). Preferably that would work cross-platform. (Maybe Qt has something ready-baked?)
But that should probably go in a dedicated report.

Markus Mützel <mmuetzel>
Group administrator
Sat 02 Oct 2021 07:46:24 PM UTC, comment #2: 

I applied the patch manually in an existing Octave-7.0.0 installation on my desktop (core i5-4570 with 4 cores w/o hyperthreading) and on my laptop with an older core i5-3320 with 2 cores and hyperthreading.
The environment var gets set correctly to the actual number of cores.

The patch also removes the flashing cmd window (shouldn't that be  a separate patch, together with the typo fixes?).  Matlab r2021b still flashes a cmd window for quite a while, so in a way your patch removes that "Matlab compatibility" ;-)
Personally I'd like some start-up feedback but OK, the Octave GUI usually takes just a few seconds to start, in contrast to Matlab which takes 25 secs or so.

Philip Nienhuis <philipnienhuis>
Group Member
Thu 23 Sep 2021 12:21:57 PM UTC, comment #1: 

Please, see the attached patch.

(file #51953)

Markus Mützel <mmuetzel>
Group administrator
Thu 23 Sep 2021 12:17:07 PM UTC, original submission:  

OpenBLAS seems to make errors and run less performant if the number of threads it uses exceeds the number of physical processor cores.
That seems to happen with default settings on machines with processor that use hyperthreading.
See also some posts interleaved in that discourse thread. E.g.:

I'll post a possible patch for the start scripts included in the Windows bundle created with MXE Octave as soon as I have a bug number.

Markus Mützel <mmuetzel>
Group administrator


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

Attach Files:

Attached Files
file #51953:  bug61208-mxe-openblas-threads.patch added by mmuetzel (10KiB - 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 dasergatskov (Posted a comment)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by mmuetzel (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 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-03-16 mmuetzel StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2021-11-25 mmuetzel StatusConfirmed Ready For Test
        Summary[MXE Octave] Start scripts should set OPENBLAS_NUM_THREADS [MXE Octave] Launchers should set OPENBLAS_NUM_THREADS
    2021-11-23 mmuetzel StatusPatch Submitted Confirmed
    2021-11-22 jwe CategoryNone Configuration and Build System
    2021-09-23 mmuetzel Attached File- Added bug61208-mxe-openblas-threads.patch, #51953
        StatusNone Patch Submitted

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code