changeset 6184:d02b5d26ac28 release

Set OPENBLAS_NUM_THREADS also in launcher scripts. * installer-files/octave-firsttime.vbs, installer-files/octave.vbs, installer-files/octave.bat: Set OPENBLAS_NUM_THREADS to number of physical cores if it is not set in the environment yet.
author Markus Mützel <markus.muetzel@gmx.de>
date Fri, 22 Apr 2022 19:19:31 +0200
parents 4ba9eb3f70c9
children 8df7db467c66
files installer-files/octave-firsttime.vbs installer-files/octave.bat installer-files/octave.vbs
diffstat 3 files changed, 62 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/installer-files/octave-firsttime.vbs	Tue Apr 19 09:26:38 2022 -0400
+++ b/installer-files/octave-firsttime.vbs	Fri Apr 22 19:19:31 2022 +0200
@@ -2,11 +2,18 @@
 
 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
+  WScript.Quit wshShell.Run("cscript.exe """ & WScript.ScriptFullName & """", 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
@@ -55,9 +62,21 @@
   wshSystemEnv("QT_PLUGIN_PATH") = OctavePath & "\plugins"
 End If
 
-' pkg config pc path
+' pkgconfig .pc files path
 wshSystemEnv("PKG_CONFIG_PATH") = OctavePath & "\lib\pkgconfig"
 
+If wshShell.ExpandEnvironmentStrings("%OPENBLAS_NUM_THREADS%") = "%OPENBLAS_NUM_THREADS%" Then
+  ' set OPENBLAS_NUM_THREADS to number of physical processor cores.
+  Set wshExec = wshShell.Exec("wmic CPU Get NumberOfCores")
+  If Not wshExec.Stdout.atEndOfStream then
+    ' Check that first line contains "NumberOfCores".
+    If (InStr(1, wshExec.StdOut.ReadLine(), "NumberOfCores") = 1) And (Not wshExec.Stdout.atEndOfStream) then
+      ' The next line should contain the number of cores.
+      wshSystemEnv("OPENBLAS_NUM_THREADS") = wshExec.StdOut.ReadLine()
+    End If
+  End If
+End If
+
 ' set directory to users
 startpath = wshShell.ExpandEnvironmentStrings("%UserProfile%")
 wshShell.CurrentDirectory = startpath
--- a/installer-files/octave.bat	Tue Apr 19 09:26:38 2022 -0400
+++ b/installer-files/octave.bat	Fri Apr 22 19:19:31 2022 +0200
@@ -41,9 +41,27 @@
   set QT_PLUGIN_PATH=%OCT_HOME%\plugins
 )
 
-Rem pkgconfig .pc path
+Rem pkgconfig .pc files path
 set PKG_CONFIG_PATH=%OCT_HOME%\lib\pkgconfig
 
+IF NOT x%OPENBLAS_NUM_THREADS%==x GOTO openblas_num_threads_set
+
+Rem Set OPENBLAS_NUM_THREADS to number of physical processor cores.
+SETLOCAL ENABLEDELAYEDEXPANSION
+SET count=1
+FOR /F "tokens=* USEBACKQ" %%F IN (`wmic CPU Get NumberOfCores`) DO (
+  SET line!count!=%%F
+  SET /a count=!count!+1
+)
+Rem Check that first line contains "NumberOfCores".
+IF x%line1%==xNumberOfCores (
+  Rem The next line should contain the number of cores.
+  SET OPENBLAS_NUM_THREADS=%line2%
+)
+ENDLOCAL & SET OPENBLAS_NUM_THREADS=%OPENBLAS_NUM_THREADS%
+
+:openblas_num_threads_set
+
 Rem set home if not already set
 if "%HOME%"=="" set HOME=%USERPROFILE%
 if "%HOME%"=="" set HOME=%HOMEDRIVE%%HOMEPATH%
--- a/installer-files/octave.vbs	Tue Apr 19 09:26:38 2022 -0400
+++ b/installer-files/octave.vbs	Fri Apr 22 19:19:31 2022 +0200
@@ -2,12 +2,18 @@
 
 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
+  WScript.Quit wshShell.Run("cscript.exe """ & WScript.ScriptFullName & """", 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 should be OctavePath/mingw64 or OctavePath/ming32
+' OctavePath is now the root of the install folder, but for msys2,
+' OctavePath should be OctavePath/mingw64 or OctavePath/mingw32
 MSysType = "MSYS"
 MSysPath = OctavePath
 Set objFSO = CreateObject("Scripting.FileSystemObject")
@@ -15,7 +21,7 @@
   MSysPath = OctavePath & "\usr"
   MSysType = "MINGW64"
   OctavePath = OctavePath & "\mingw64" 
- ElseIf objFSO.FileExists(OctavePath & "\mingw32\bin\octave-cli.exe") Then
+ElseIf objFSO.FileExists(OctavePath & "\mingw32\bin\octave-cli.exe") Then
   MSysPath = OctavePath & "\usr"
   MSysType = "MINGW32"
   OctavePath = OctavePath & "\mingw32" 
@@ -56,9 +62,21 @@
   wshSystemEnv("QT_PLUGIN_PATH") = OctavePath & "\plugins"
 End If
 
-' pkg config pc path
+' pkgconfig .pc files path
 wshSystemEnv("PKG_CONFIG_PATH") = OctavePath & "\lib\pkgconfig"
 
+If wshShell.ExpandEnvironmentStrings("%OPENBLAS_NUM_THREADS%") = "%OPENBLAS_NUM_THREADS%" Then
+  ' Set OPENBLAS_NUM_THREADS to number of physical processor cores.
+  Set wshExec = wshShell.Exec("wmic CPU Get NumberOfCores")
+  If Not wshExec.Stdout.atEndOfStream then
+    ' Check that first line contains "NumberOfCores".
+    If (InStr(1, wshExec.StdOut.ReadLine(), "NumberOfCores") = 1) And (Not wshExec.Stdout.atEndOfStream) then
+      ' The next line should contain the number of cores.
+      wshSystemEnv("OPENBLAS_NUM_THREADS") = wshExec.StdOut.ReadLine()
+    End If
+  End If
+End If
+
 ' check args to see if told to run gui or command line
 ' and build other args to use
 GUI_MODE=1