Matlab users can package code projects as toolboxes and/or packages.
The packages format works for ancient versions of Matlab, before even R2006a as well as GNU Octave.
The toolbox format works for Matlab ≥ R2016a and not GNU Octave.
The packages format brings benefits to toolboxes as well.
A key issue with Matlab vs. Python arise from that Matlab users often add many paths for their project.
If any function names clash, there can be unexpected behavior as it’s not immediately clear which function is being used without further investigation of path ordering.
As in Python and other languages, there is considerable benefit for using a package format where the function names are specified in their namespace.
To enable Matlab package format, we explain by example. Suppose a project directory structure is like:
To use these functions, the end users do:
This is where the namespace can have clashes, and with large projects it’s not clear where a function is without further introspection.
To make this project a Matlab / Octave package, change the subdirectories containing .m files to start with a “+” plus symbol:
Then multiple subdirectories can have the same function name without clashing in the Matlab namespace.
Support the function “mem1” is used frequently in another function.
To avoid typing the fully resolved function name each time, use the
Matlab .mltbx toolboxes became available in R2016a.
The Matlab-proprietary toolbox format also allows end users to create their own packages containing code, examples and even graphical Apps.
In effect .mltbx provides metadata and adds the package to the bottom of Matlab path upon installation.
The installation directory is under (system specific)/MathWorks/MATLAB Add-Ons/Toolboxes/packageName.
Whether or not the project uses .mltbx, the namespace of the project is kept cleaner by using a Matlab package layout.
On Windows, the Intel C, C++ and Fortran compilers present Visual Studio-like command line options.
correct version of Visual Studio
must be installed on Windows for Intel compilers to work.
C and C++ use the icl compiler on Windows.
Most users use the Intel oneAPI command prompt.
Alternatively, run “compilervars.bat” script to enable the Intel compilers for each session.
“psxevars.bat” is not appropriate for this setup.
For convenience, make a batch script like %userprofile%\intel.bat containing:
"C:\Program Files (x86)\inteloneapi\compiler\latest\windows\bin\compilervars.bat" intel64
Intel MPI on Windows is only for Intel compiler
Linux Intel MPI,
Windows Intel MPI is only for the Intel C, C++ and Fortran compilers and Visual Studio.
Although not often needed, a separate username can be used for Windows Intel MPI jobs by from Command Prompt:
runas /user:username cmd
Environment variables are not passed to the new window, so it may be necessary to run Intel compilervars.bat again.
It’s possible to
the user credential in the Windows registry.
select rank – making assumed rank arguments actually useful.
added random_init() to initialize the random generator seed…randomly
Optimization: automatic nested loop exchange with do concurrent
Checks: Actual argument array with too few elements for dummy argument now errors
Polymorphism: initial support for parameterized derived types (simply define kind at initialization)
Coarray: Initial support for teams
(Gfortran 8.2 and 8.3 did not introduce new Fortran features)
std=f2008ts deprecated, do not use as it errors on compiling error stop for Gfortran < 8.
Polymorphism: derived type IO select type etc. fully supported from Fortran 2003.
Fortran 2018: Non-constant stop and error stop codes
Compatibility: -fdec- options help compiling very old non-standard code that was previously only compatible with Intel oneAPI (of DEC heritage).
Fortran 2008: submodule support, useful for large projects to save compilation time and allow powerful use scenarios
Fortran 2003: improved support for deferred-length character.
These are very useful for avoiding bothersome trim() everywhere.
character(256) :: argv
character(:), allocatable:: filename
call get_command_argument(1, argv)
filename = trim(argv)
In this example, filename is now exactly the length required to fit the text.
If the filename (in argv) was “hello.txt” then len(filename) is 9.
That is, len_trim == len with auto-allocated characters (unless subsequently rewritten with a shorter string).
Practical examples are in gitrev.f90 and split_string.f90.
For split_string.f90, note that this is the proper way to avoid assumed-length character functions, which are obsolete as of Fortran 95.
! don't do this!
character(*) function myfun(a)
pure function myfun(a)
character(:), allocatable:: myfun
OpenMP 4.0 fully supported
Fortran 2003: ieee_ intrinsics supported, allowing convenient standard-compliant use of nan, ieee_is_nan, etc.
CMake allows switching parameters based on compiler version.
This is very useful for modern Fortran programs.
Example CMakeLists.txt for Fortran compiler version dependent options.
if(CMAKE_Fortran_COMPILER_IDSTREQUALGNU)# option applying to any language for this compiler
add_compile_options(-mtune=native)# language-specific, note LEADING space
string(APPENDCMAKE_Fortran_FLAGS" -fimplicit-none") if(CMAKE_Fortran_COMPILER_VERSIONVERSION_GREATER_EQUAL8) string(APPENDCMAKE_Fortran_FLAGS" -std=f2018") endif()endif()add_executable(myprogmain.f90)
Non-Fortran 2018 workaround
Here we assume that assert.f90 contains error stop in a procedure that’s called from a pure procedure.
Existing toolchains such as CMake and Meson can immediately use HPC SDK by setting environment variables:
first ensuring the HPC SDK bin/ directory is on PATH.
Nvidia HPC binaries can offer speed improvements over GNU GCC / GFortran, but Intel oneAPI binaries can be significantly faster than Nvidia-compiled binaries for CPU-only workloads.
Unless one specifically needs the GPU features of Nvidia HPC SDK consider GNU or Intel oneAPI that have more modern Fortran features.
Nvidia HPC compilers are currently available for Linux, with language standard support:
Fortran 2003, with some Fortran 2008 including submodule and error stop
Since Windows 10 1809, OpenSSH client and server are built into Windows.
The setup procedure is easier than using Cygwin.
RDP (Remote Desktop) over SSH can be significantly more secure than RDP alone, assuming SSH is well configured.
Enable OpenSSH Server: Go to Windows Settings → Apps → Apps & features → Optional features → Add a feature → OpenSSH Server. This also sets Windows Firewall to allow inbound SSH TCP connections.
2 . Edit c:/ProgramData/ssh/sshd_config on the OpenSSH server PC. At least set PasswordAuthentication no to require SSH public key for better security.
A minimal SSH keypair can be created for the SSH client by:
ssh-keygen -t ed25519 -f ~/.ssh/my_server
Copy the contents of client laptop file ~/.ssh/my_server.pub to the Windows SSH server computer, creating or adding a line to file ~/.ssh/authorized_keys. The location of this file is defined in sshd_config as AuthorizedKeysFile. Use a unique key for each connecting client–do not reuse SSH keypairs between servers or clients.
if the user is a Windows Administrator on the OpenSSH server computer, add the SSH public key to c:/ProgramData/ssh/administrators_authorized_keys
Start the SSH server (for this session only) from PowerShell:
If this gives an error and/or you wish to always start OpenSSH, type services.msc and in Properties of OpenSSH server → General set “Startup Type: Automatic”
As on Linux, the “authorized_keys” file must have the correct file permissions ACL. Run this PowerShell script from Concurrency.com:
now the SSH client should be able to connect to the SSH server. If this doesn’t work, try using SSH locally on the OpenSSH server computer to troubleshoot.
Compilers define macros that can be used to identify a compiler and platform from within C, C++ and Fortran code.
This can be useful for many purposes where short bits of platform-specific or compiler-specific code is needed.
If a significant amount of code is needed, it may be better to swap in different code files using the build system instead of lengthly #if defined(foo) logic.
There are numerous examples for C and C++ so here we will focus on macros of Fortran compilers.
Gfortran compiler macro definitions are obtained in an OS-agnostic way by:
echo "" | gfortran -dM -E - > macros.txt
that creates a file “macros.txt” containing all the compiler macros.
commonly used macros to detect operating system / compiler configuration include:
include the Gfortran macros noted above and additionally:
Nvidia HPC Fortran
Nvidia HPC Fortran compiler macros are printed by:
the Nvidia macros include the Gfortran macros above as well as:
MPI 3 constants like mpi_comm_world and mpi_real are no longer integer data type, but rather derived types.
Some libraries have not yet updated to be polymorphic for this enhanced MPI 3 variable type.
For such libraries, access the integer value via the %mpi_val property.
integer:: comm = mpi_comm_world%mpi_val
!! %mpi_var emits the legacy integer
This example uses the aurora, which is produced around most planetary bodies due to energetic particle kinetics as the particles penetrate the ionosphere.
Optical instruments such as cameras give a line integrated measurement for each pixel (angle) of the imagers.
This data can be useful for tomographic techniques, when the location and orientation of the camera is well known, and multiple cameras with overlapping field of view exist.
However, this rich data can be greatly supplemented and even superseded by other instruments, especially incoherent scatter radar, where 3-D + time data are available due to volume integrated target returns.
Many analyses rely on those thin (~ 0.5 degree FWHM) radar beams to complete an analysis.
We rarely know the needed orientation of the radar beams beforehand, and many ISR cannot change the location of their pre-programmed beams.
Although as AESA they can steer almost instantaneously within the radar backend processor limits.
This is just a geospace example of like Twitter having too much data, but not enough to gauge individual analyses without additional processing techniques.