Matlab
Git operations
are a first-class part of the Matlab environment, without need for
system()
calls.
The Matlab Desktop GUI or Matlab factory functions allow most common Git operations to be directly performed.
For example,
Git clone
is a plain Matlab function that can be called from the command line or script.
For research reproducibility, a Docker image gives a known software state that should be usable for many years.
It isn’t strictly necessary to make a custom image as described below, but it can be useful for a known software state.
FROM alpine:latest# example for CMake project using Fortran with OpenMPI.RUN apk add --no-cache ninja-build cmake gfortran openmpi-devENV CMAKE_GENERATOR=Ninja
Create the file above named Dockerfile in the Git repo.
Once the configured Docker container is ready, share this container.
This can be done with
Docker Hub.
Once ready to upload the image, note the “container ID”, which is the hexadecimal number at the terminal prompt of the Docker container, under docker ps.
The container hex ID must appear under docker ps, just being in docker images is not enough.
The changes to the image the container made are gathered into a new image.
It may take a minute or two for a large image.
Ideally with a small image it will take only a couple seconds.
The new image has not yet left the computer, it will show up under
docker images
Once uploaded, the Docker image is visible to the world by default.
Login to Docker Hub
docker login -u dockerhub_username
Push (upload) this image to Docker Hub.
This image is world-visible by default!
docker push dockerhub_username/openmpi-fortran
If the image is very large > 1 GB, be aware it will take a while to upload, and for the host to download.
This is a telltale that it’s important to keep Docker images small.
Docker images are useful for reproducibility and ease of setup and for software binary distribution on platforms not natively available.
For example, it may be desired to distribute a statically-linked binary that will run on any Linux system with compatible CPU architecture and kernel system calls.
To setup and maintain Docker images, it’s useful to have
Docker Desktop
available on the developer laptop to debug and test Dockerfiles.
Read the install instructions particular to the laptop OS to understand OS-specific caveats and features.
For example, on Linux laptops, to avoid the need for “sudo” in every command, follow the
post-install.
Docker commands can be run from the system terminal if desired–all commands in this article assume this.
Docker images by default will be downloaded to run locally.
Try the Hello World images, which should auto-download and print a welcome message
docker run hello-world
Search for a desired image using Docker Desktop or docker search.
Consider the “Official” images first.
Let’s use
Alpine Linux.
docker search alpine
Get the desired image
docker pull alpine
Verify the images:
docker images
Start the Docker container:
docker run -it alpine
-it
interactive session
Verify the Alpine version running in the container.
It will have a # superuser prompt.
cat /etc/os-release
Search for desired APK packages from within the container:
Docker images are useful for reproducibility and ease of setup and for software binary distribution on platforms not natively available on GitHub Actions runner images.
While one can setup a
custom Docker image,
it’s often possible to simply use an existing official image from
Docker Hub.
This example GitHub Actions workflow uses the Alpine Linux image with the MUSL C library to build a statically-linked binary.
Some folder locations in macOS are not accessible by traversing one level at a time from outside or above that location.
In general, it can be convenient to open a terminal window at a specific folder location.
The folder may be opened directly by right-clicking on the folder in Finder and selecting “New Terminal at Folder”.
By default, listing the contents of a directory with
PowerShell
shows file metadata along with the path names within the directory.
Other shells typically show only the path names by default, which is convenient for copy-pasting lists of files or directories into other commands or scripts.
To list only the path names when listing a directory in PowerShell, use the -Name option:
The POSIX function nanosleep() is not available on Windows with MSVC and certain MinGW architectures.
This
implementation of nanosleep() for Windows
uses Waitable Timer Objects.
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.
OpenMP
and
OpenACC
are open standards for parallel programming on CPU and GPU shared memory platforms.
While OpenMP has wider compiler support,
OpenACC
also aims to be portable across compilers and computing architectures.
OpenMP standard syntax for C, C++, Fortran, and
CUDA
can work seamlessly with non-OpenMP systems if code is properly written.
While OpenMP is typically built in from the factory in contemporary compilers, the compilers may need flag(s) to enable OpenMP.
Build systems like
CMake
and
Meson
can manage the OpenMP compiler flags.
OpenMP is well-supported in commercial computation performance-oriented Fortran compilers like:
OpenMP support in open-source Fortran compilers includes
LLVM
and
GCC.
Open-source compilers such as LLVM Flang need to have the proper OpenMP-enabling flags set when building the compiler by the distribution maintainers.
For example,
Homebrew LLVM Flang
was missing Fortran libomp.mod support due to misconfiguration in the Homebrew
flang formula.
“git clone” clones the default branch of the remote repository as determined by the Git server.
The default Git branch is typically “main”, but the repository owner can change it to any other branch.
To Git clone a specific branch, use the –branch option:
git clone --branch <branch-name> <repository-url>
This can help workaround problems like a default branch that is very large or is broken in some way.