Get MPI on Windows with C and Fortran by any one of:
MS-MPI,
Intel oneAPI
or Windows Subsystem for Linux libopenmpi-dev.
We often use MPI via
MSYS2
with GCC / Gfortran compilers on Windows.
Upon installing or updating Intel oneAPI compilers and libraries on Windows, you may experience CMake failing to find MPI for MinGW.
This happens because Intel compilers put Intel MPI on the system PATH.
Fix this by removing Intel MPI from the system PATH and use the Intel Compiler shell instead, which provides all the needed directories.
These techniques allow a Windows development machine to use Notepad++ more effectively.
Notepad++ is a free source code editor and Notepad.
It was first released in 2003 and is an
open source project.
winget install Notepad++.Notepad++
Notepad++ from command line:
add to user environment variable Path the binary path of Notepad++ – typically at %PROGRAMFILES%\Notepad++.
This allows using notepad++ from the Windows Terminal.
Notepad++ shortcut icon open a new window:
When using multiple virtual desktops, by default Notepad++ snaps to the other desktop when clicking the Notepad++ start menu icon.
Make the Notepad++ icon open a new Notepad++ window by editing the Notepad++ start menu shortcut, appending
-multiInst
to the right and outside of the quoted full Target path to notepad++.exe.
This allows opening multiple Notepad++ windows, each with its own set of tabs.
Notepad++ open directory as project:
To open a directory as a project, use the command line option -openFoldersAsWorkspace followed by the path to the directory.
We have found this is often a server-side configuration issue, particularly when it only occurs with a specific server.
The server may be using an older version of OpenSSH that still supports arcfour-hmac, or it may have been configured to allow this encryption type.
To check settings in the SSH client configuration file, look for lines that specify Ciphers or MACs.
If arcfour-hmac is listed, it should be removed.
The Matlab external language interface to Python in Matlab releases before R2022a has a bug with the JIT compilation via
Matlab execution engine
such that any mention of the py.* namespace will make a function unusable if Python is not
available.
Especially problematic is functions that can work without Python (say in an if-else or switch block) where the mere presence of a py.* call will cause the entire function to fail if Python is not available.
To workaround this issue in Matlab older than R2022a, use a private function to encapsulate the Python call.
This way, the main function will not be affected by the Python call.
functionresult =my_fun2(input)if has_python()
result = encaps_fun2(input);
else% fallback code when Python is not availableendend
Make a private function in file “private/encaps_fun2.m”:
functionresult =encaps_fun2(input)result = py.some_module.some_function(input);
end
Matlab external language
interfaces
includes .NET on Windows, Linux, and macOS.
This allows efficiently calling .NET assemblies and using .NET libraries directly from Matlab.
The Matlab function
dotnetenv
is used to set up and check the active .NET environment in Matlab.
Environment variable DOTNET_ROOT is vital for Matlab to detect the .NET installation, particularly on Linux and macOS.
If Matlab is having issues detecting the .NET installation NET.isNETSupported is false, determine the value for DOTNET_ROOT from system Terminal:
dotnet --info
If “dotnet” command is not found, install .NET SDK:
macOS: brew install dotnet
Windows: winget install Microsoft.DotNet.SDK.9 # whatever the desired version is
Matlab Online (Linux): if .NET isn’t detected, use .NET install script to install .NET SDK.
Find the “dotnet” executable and run dotnet --info to get the DOTNET_ROOT path.
If this path is not defined, look for the Base Path, and pick the directory that contains the “dotnet” executable.
Set the DOTNET_ROOT environment variable in Matlab by adding to Matlab startup.m so that future Matlab sessions have the correct DOTNET_ROOT set.
edit(fullfile(userpath,'startup.m'))
Then add the following line to startup.m:
setenv("DOTNET_ROOT", <DOTNET_ROOT path from dotnet --info>)
Restart Matlab.
Do the following one-time command to finish setting up .NET in Matlab:
dotnetenv("core", Version=8)
The Version number must match the major version of .NET in DOTNET_ROOT.
On future Matlab sessions, dotnetenv() will be empty until the first .NET command is run, for example
NET.isNETSupported
then (optionally) running dotnetenv() shows the current .NET environment.
On Unix-like systems such as Linux and macOS, Python can detect if a script is being run as sudo / root from the
UID,
which is by definition zero for root.
On Windows, the ctypes module can be used to check if the current user is an administrator.
Its convenient to flip an image vertically or horizontally from Terminal.
In general, modifying an image in any way including cropping, flipping, rotating, etc. is a lossy process if the image compression algorithm used is lossy such as JPEG.
Lossless compression formats such as PNG will remain lossless with this operation.
Here are examples using
ImageMagick
or
IrfanView.
Assume the input image is named “in.png” and the modified image is written to “out.png”.
IrfanView has been popular for decades on Windows and
WINE
as a no-cost (not open source) image viewing and simple modification program that handles many formats.
IrfanView can also be used from the command line.
Install IrfanView directly, not via the Microsoft App Store:
winget install IrfanSkiljan.IrfanView
The order of the commands is important.
These commands do not open the IrfanView GUI–they are “headless” operations.
If there are spaces in the file paths, they must be enclosed in quotes like
"c:/data pics/in.png"
The POSIX functions
nanosleep()
and
clock_gettime()
useful in games and other programs needing repeatable time delay and time measurement is not available in the standard C library on Windows with Visual Studio and certain MinGW CPU architectures.
The clock tick for Windows is 100 ns.
The practical achievable timer resolution on Windows is in the
millisecond range.
This presents a floor on the accuracy achievable for sleep timers.
Virtual Machine running of Windows makes the sleep accuracy significantly worse.
In general across general-purpose operating systems, high accuracy sleep timer performance is not guaranteed.
For high accuracy sleep timers (i.e., beyond what is needed for gaming and abstract high-level control of hardware interfaces), consider using a real-time operating system (RTOS) or a dedicated microcontroller.
CMake can use MUSL slim libc natively (e.g. Alpine Linux), in a Docker container, or by cross-compiling.
Cross-compiling in CMake generally uses a toolchain file to set critical variables that can’t be detected automatically.
For example, using the x86_64 MUSL binaries from musl.cc, extract the tar file say to ~/musl and then create file ~/musl/musl-toolchain.cmake like:
set(CMAKE_SYSTEM_NAMELinux)# target system
set(CMAKE_SYSTEM_PROCESSORx86_64)# target architecture
set(CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_LIST_DIR}/x86_64-linux-musl-native)# These cross-compilers come from the toolchain downloaded from musl.cc
set(_bin ${CMAKE_FIND_ROOT_PATH}/bin)set(CMAKE_C_COMPILER"${_bin}/x86_64-linux-musl-gcc")set(CMAKE_CXX_COMPILER"${_bin}/x86_64-linux-musl-g++")set(CMAKE_Fortran_COMPILER"${_bin}/x86_64-linux-musl-gfortran")set(_lib ${CMAKE_FIND_ROOT_PATH}/lib)set(CMAKE_SYSTEM_LIBRARY_PATH ${_lib})set(CMAKE_SYSTEM_INCLUDE_PATH ${CMAKE_FIND_ROOT_PATH}/include)set(CMAKE_EXE_LINKER_FLAGS_INIT-Wl,-rpath-link=${_lib},-rpath=${_lib})set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAMNEVER)set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARYONLY)set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDEONLY)set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGEONLY)
Use this to cross-compile a CMake project with MUSL like:
When turning on an old Windows PC that hasn’t been used for a while, the Windows OS may be several versions out of date.
Windows may be so old that using Windows Update doesn’t automatically give an option to upgrade Windows, or may offer a non-latest Windows release.
Instead of discarding the PC, consider manually upgrading Windows to the latest release via the
Windows Upgrade Assistant.
Typically the Assistant will have a PC Health Check that it will ask to have run first.
The Health Check will tell among other things the current maximum capacity of the laptop battery.
The PC can still be used during the upgrade, which doesn’t take too long.
It’s important to use a currently supported version of Windows to be better protected from cybersecurity concerns and to avoid unsupported or non-working software configurations.