Scientific Computing

Gfortran 12 bind(C) spurious warning fixed

This code triggered a spurious warning in GFortran 12:

program demo
use, intrinsic :: iso_c_binding, only : c_int
implicit none

interface
subroutine fun(f_p) bind(c)
import c_int
integer(c_int), pointer, intent(out) :: f_p(:)
end subroutine
end interface

integer(c_int), pointer :: f(:)

nullify(f)
call fun(f)

end program

This bug was fixed in GCC 13.1.

Flatpak open shell

Flatpak is a popular means to distribute software on Linux that installs and runs in a sandbox for each application. This is particularly useful when an application needs a newer GLIBC / GLIBCXX than the system has, which is often the case on RHEL and HPC systems.

It can be convenient to open a sandboxed shell in a Flatpak app’s sandbox. For example, to open a shell in the GNU Octave Flatpak sandbox:

flatpak run --command=sh org.octave.Octave

This can be useful to build further applications with CMake using a Flatpak program.

Git apply patch line ending

Git patch files can be generated like:

git diff > my.patch

If the Git patch file is generated on a Windows computer and is copied to a non-Windows computer, the patch may fail to “git apply my.patch” on the non-Windows computer. If the mismatches seen with “git apply my.patch -v” show question marks “?” at the end of each line, the issue may simply be line endings mismatch.

Try fixing line endings in the patch file using dos2unix on the computer where the patch is to be applied:

dos2unix my.patch
git apply my.patch

dos2unix is installed like “brew install dos2unix” or “apt install dos2unix” or similar.

Git mv glob PowerShell

The git mv command tracks moves or renames of Git tracked files similar to the shell “mv” command. Typically it’s useful to “glob” match patterns of files to move to avoid extra typing. PowerShell command substitution is used with Get-ChildItem and “git mv”:

git mv $(gci -Path ./source_dir/ -Include *.cpp) ./dest_dir/

Find files with PowerShell

PowerShell can recursively find files like GNU Findutils using PowerShell function Get-ChildItem. The abbreviated form of Get-ChildItem is “gci”. Typically the “-Recurse” option is used as the default is to only search the specified directory level.

Examples:

Recursively find all “*.lib” files under directory ./build:

gci -Path build -Recurse -Filter *.lib

Find all files named “example.txt” under directory ~/projects:

gci -Path ~/projects -Recurse -Filter example.txt

Open all files found above in “code” Visual Studio code:

code (gci -Path ~/projects -Recurse -Filter example.txt)

Matlab loadlibrary C interface

Matlab loadlibrary is a straightforward way to use existing C libraries from Matlab. In contrast, Matlab C++ interface takes several steps to setup and distribute, and the C++ interfaces may not be necessary, considering one may be able to use an existing unmodified C library directly from Matlab. Other options include MEX C++ interface code, where the developer writes a wrapper function accessible from Matlab, this is relatively high performance and straightforward as well. However, loadlibrary can be the least amount of effort and the end user doesn’t need to compile C/C++ code.

Consider the modest example interfacing to the C++ <filesystem> library from Matlab. Compare that with a similar MEX <filesystem> interface. One doesn’t need to build a Matlab class like Ffilesystem.m for loadlibrary. The loadlibrary approach is more general and can be used with many C libraries having C types amenable to Matlab types.

Observe in Ffilesystem.m that the user provides the path to the shared library (.dll, .so, or .dylib) that could be distributed by GitHub Release or built by the user. Pointer in / out arguments are handled by libpointer. The “delete” destructor unloads the library to avoid resource leaks.

Free ReactOS Windows clone in VirtualBox

ReactOS gives a free, open-source Windows XP API level replacement that can use USB devices. Sometimes Linux users need to use a Windows VM when USB devices are required in Windows programs. ReactOS can work in a VM for older Windows programs with a much smaller install than Microsoft Windows. As time goes on, less and less Windows software is compatible with Windows XP and hence less software is compatible with ReactOS.

Install ReactOS in a virtual machine with the VirtualBox version recommended in ReactOS install procedure. Create a new VM with name “ReactOS”, which should auto-populate needed settings.

When installing, use FAT file system instead of buggy, experimental BTRFS at this time. Disable JavaScript in ReactOS Firefox browser as ReactOS might hang at 100% CPU for JavaScript intensive websites. Type about:config in Firefox address bar and Toggle javascript.enabled to false.

ReactOS advantages vs. Windows:

  • ReactOS installation takes 90% less space than Windows
  • no OS license maintenance with free, open-source ReactOS
  • no licensing worries about making many copies of a working ReactOS install. Get a VM working and copy it to many workstations.
  • ReactOS theme feels like Windows XP, so there are few concerns about transitioning users reluctant to change

ReactOS Limitations:

ReactOS 0.4.x API level is Windows NT 5.2 (Windows 2003 / XP). Programs requiring Windows NT 6.0 (Vista) or newer will likely not run. Current versions of Python do not work with ReactOS 0.4.x due to the Windows NT 5.2 API level. Consider trying an older version of the program you want to install that is still noted to work with Windows XP when using ReactOS.

NT 6.x API Windows Vista support is important as many programs, including open source programs, have left Windows NT 5.x unsupported and non-functional for their programs.

Windows shared library caveats

In general on any project, “shared” libraries on Windows using .DLL files have numerous caveats that aren’t an issue on macOS and Windows due to decades-old stark differences in how Windows links and runs shared libraries. One key distinction is that Windows has no concept of Rpath as Unix-like OS have, which means the .DLL have to be on PATH environment variable for all shared libraries used in an executable. This can be a key drawback for Windows shared libraries in non-trivial projects using 3rd party libraries. In general we strongly recommend using “static” libraries on Windows, as the downsides of shared libraries on Windows are significant.

In the past year or so, GitHub Actions runners for Windows broke most “shared” library runs across projects. The projects would run in “shared” on physical Windows machines reliably, but not on CI. We have disabled Windows shared builds on GitHub Actions CI across all projects.

Windows Git symlinks

Windows Git requires one-time settings to enable Git symbolic links. If a computer doesn’t have these settings, it can create problems with inability to reset a Git repo, where the repo may have to be erased and re-cloned to fix. If an existing local Git repo on a Windows PC has problems with symbolic links, it may be necessary to re-clone the repo after first making these one-time settings.

Set Windows user permission to create symbolic links. Configure Git globally on the Windows PC to handle symlinks:

git config --global core.symlinks true

Git symlinks should only refers to paths within the Git repo. Where possible it is preferable to avoid symlinks, but this method above often works on Windows PCs for Git symlinks.