Scientific Computing

Matlab .empty array initialization

Many coding languages have objects that are useful as sentinels to indicate missing data or unused parameters. For example, if a boolean parameter’s state has not been checked, it’s a bit disingenuous to say available = false. Sentinel values give a state that can communicate that something is unknown or unset.

Some example sentinels:

In Matlab an empty array can be used as a sentinel.

Create empty arrays for Matlab data types by appending .empty to the data type name. Examples:

datetime.empty
string.empty
struct.empty

The commonly used isempty() works for any Matlab type:

function out = myfun(cfg)
arguments
  cfg struct = struct.empty
end

if isempty(cfg)
  cfg.lims = [0,100];
end

Detect Linux distro version

Windows and macOS have few maintained versions due to their commercial nature. In contrast, FOSS operating systems like BSD and Linux have hundreds of maintained distros. Only a few Linux distros dominate such as Debian, Ubuntu and Red Hat. Less common Linux distros are commonly based on popular distros.

For certain system management tasks and install scripts it’s useful to programatically identify which major Linux distro family the current OS belongs to. A standard method to detect Linux operating system version is via plaintext /etc/os-release. Prior to this de facto standard, older Linux distros used other files.

The algorithm we use to identify older and newer Linux distros is to first check the file “/etc/os-release” versus known distros. If “/etc/os-release” is not present, the algorithm looks for OS-specific files:

Distro ID file
Red Hat /etc/redhat-release
Debian /etc/debian_version
Ubuntu /etc/debian_version
Arch Linux /etc/arch-version

Free multispeaker large group web presentations

These programs allow hosting or attending a live Web group conference. We considered factors including: large attendee count, live feedback, several speakers/presenters who can share their screen, and allowing others to draw on that screen or edit the document. There are many more options such as Talky, etc. These web conferencing methods work for Linux / macOS / Windows / Android / iOS.

High quality livestreaming HD broadcasts via an API requires just a bit of reasonable technical knowledge to accomplish. Google Meet only requires a web browser and plugin (or mobile app)–it’s simpler to get started and is a good business-grade choice.

According to Omnicore, 95% of global Web users visit YouTube. YouTube Live is free for live events with live user feedback and multiple speakers. YouTube Live is easy to stream using FFmpeg or OBS Studio. YouTube Live streaming is also possible directly from the web browser.

The Facebook Live Graph API makes it possible to live stream broadcast from a laptop. FFmpeg can stream to Facebook Live from a laptop.


Zoom currently allows limited free use. Paid plans have unlimited time with a large participant count. The Zoom client is available for many platforms, or can be used directly from the web browser app. The Zoom Linux client also works well.

GoToMeeting allows small free meetings, with a large participant count on paid plans. Web browsser GoToMeeting works well in the Google Chrome browser across operating systems.

WebEx web browser platform-independent conferencing works better than the installed WebEx app. WebEx limits participant count by pricing tier.

Google Meet has browser-based screen sharing / video group calls. Phone dialout / dialin is also available.

Discord can be used from an web browser, and allows thousands of simultaneous many-to-many voice and text chat users. Several speakers can share video/screen and audio as well. Discord is free to use with very low latency HD voice. Discord uses discontinous voice via voice activation or push-to-talk. Many-to-many conversations allows interrupting without pause/break.

Skype has plugin-free access via the web browser with a limited number of conference participants. Skype for Business has higher user count limits, but is not free.

Fix Numpy import errors

Numpy ABIs change between releases, which can lead to errors upon

import numpy

like:

ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

try fixing by upgrading Numpy.

conda install numpy

# or

pip install --upgrade numpy

What value does modern Fortran add?

For scientists, engineers and other performance-sensitive coders modern Fortran offers immediate advantages in developer time savings. The clarity, conciseness and power of modern Fortran are widely available in contemporary compilers. This brief post was motivated by viewpoints encountered including:

  • those whose boss insisted on Fortran 77–they didn’t know anything newer than Fortran 90 existed.
  • those who thought essentially no compilers supported newer than Fortran 95 standard (in calendar year 2018).

To be effective with programmer time, one generally shouldn’t needlessly upgrade all Fortran 77 code to modern Fortran, since Fortran has always maintained good backward compatibility. However, new and upgraded Fortran code should almost never be written in Fortran 77 unless specific job conditions dictate. Of course, Fortran 66 / Fortran IV is little supported and will need to be upgraded to Fortran 77 syntax, which is very similar except for file I/O.

New Fortran code should at least use Fortran 2003, which is universally supported by current compilers. In HPC environments, Gfortran and Intel oneAPI are widely supported, so we use modern Fortran features in virtually every program.

Modern Fortran support

The compilers easily available supporting modern Fortran include:

  • Gfortran
  • Intel oneAPI
  • NAG
  • LLVM Flang
  • Nvidia HPC

Polyhedral benchmarks compilers supporting modern Fortran features.

What did the major Fortran versions add

  • Fortran 95 brought strong N-dimensional array operations. It is a key step toward modern Fortran, enabling arbitrary size (elemental) intrinsic and non-intrinsic procedures. With Fortran 95, one no longer had to to explicitly loop over almost every array operation.
  • Fortran 2003 brought polymorphism and true object-oriented procedures, critical parts of modern generic programming.
  • Fortran 2008 strengthened polymorphism, and baked coarray (distributed parallelism) directly into Fortran, transparently using underlying libraries such as OpenMPI. Improved Fortran software architecture comes through submodule enabled by Fortran 2008.
  • Fortran 2018 strengthened coarray support, and did further important language cleanup such as enabling error stop within pure procedures

Related: Gfortran feature set vs. OS and version

Fortran stderr stop return codes

Summary:

  • stop (1956 Fortran I): return integer on stderr (recommendation)
  • stop (Fortran 77): return integer or constant character – no integer return with character
  • error stop (Fortran 2008): constant character with error code
  • error stop (Fortran 2018): variable character with error code, also allowed inside pure procedure.

Fortran 2018 finally brought the needed behavior for convenient error messages and continuous integration.

CMake and Meson handle automatic detection of compiler supported features like error stop.

Fortran 2008 error stop with constant code:

  • Gfortran ≥ 5
  • NAG ≥ 6.0
  • Intel oneAPI
  • Nvidia HPC SDK

Fortran 2018 error stop with variable code

  • Gfortran ≥ 7
  • NAG ≥ 6.2
  • Intel oneAPI
  • Nvidia HPC SDK

Fortran 2018 error stop,QUIET=.true./.false.

  • NAG ≥ 6.2

This feature was promoted by Steve Lionel, but has not yet been widely adopted. From the Fortran 2018 standard, the quiet= parameter not only suppresses any console output but also may suppress the error code? I would prefer to have the error return code, without the console text.

Since Fortran I in 1956, the stop statement has generally displayed a return code to indicate an error if an integer value was provided. Over time, stop statement behavior has changed to allow more refined signaling on program stop.

Since Fortran I in 1956, stop without return code to stop execution normally has been supported, along with stop with integer return code to indicate abnormal termination.

stop 1

The Fortran 2008 and 2018 standards recommend that the error code be returned on iso_fortran_env: error_unit, which was first defined in Fortran 2003 standard. Earlier standards don’t say where the error code should go. Through Fortran 2018, stop with integer code is still normal program termination.

Since Fortran 77, stop may instead return a constant scalar character like “goodbye”. This generally sets stderr return code to 0, that is, no error is indicated.

For continuous integration, having a reliable way to indicate error behavior is crucial. For HPC, indicating abnormal conditions to the shell is also vital to avoid taking resources on runs that suffered a computational error.

Fortran 2008 brought the long overdue error stop statement. stop still indicates normal program termination, and can for example stop individual images in a parallel executing program. Say an individual cell in a 3-D simulation did not find a stable solution. Depending on the simulation, that can be OK, perhaps set that value to NaN and stop with an error code on stderr, while letting the other images continue running.

However, in other types of simulations, an early failure to converge to a solution in a cell may invalidate the entire simulation taking a month of CPU time. Instead of writing cumbersome external checking code, the programmer can instead use error stop to reliably terminate all images when a critical failure is detected. Fortran 2008 error stop with constant string or integer code: both return non-zero exit status on stderr.

use, intrinsic:: iso_fortran_env, only: stderr=>error_unit

write(stderr,*) 'the failure was in ' // failedmod

error stop

Fortran 2018 added error stop with variable scalar string or variable integer code. A vital addition of Fortran 2018 is that error stop can be used within pure procedures, a very commonly needed use case. Fortran 2018 error stop variable character string allows for cleaner syntax, for example:

error stop 'the failure was in ' // failedmod

Python install additional files

Python package installs can use MANIFEST.in to install arbitrary files to the package install directory. MANIFEST.in might look like:

include src/mypkg/intf.f90

This places the files for pip install . under:

<python-install>/site-packages/mypkg.egg/mypkg/intf.f90