Scientific Computing

Cray compiler CMake toolchain

Cray PE can select from multiple compilers as backends for better language standard support while maintaining performance of Cray frontend optimizations. Compilers such as Intel oneAPI themselves use GCC as a backend on Linux. Manual configuration may be required as the default system GCC may be too old for the desired language standard features. Or, the libstdc++ can be too old in the system default GCC. These issues are remediated by purposeful specification of the Cray-Intel-GCC toolchain in a CMake toolchain file.

This toolchain file can be copied to a common location like ~ and used among many projects, such as cray.cmake.

For CMake project that have ExternalProject inside them, there must be a CMAKE_TOOLCHAIN_FILE parameter to ExternalProject_Add like:

set(cmake_args ...)

if(CMAKE_TOOLCHAIN_FILE)
  list(APPEND cmake_args -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE})
endif()


ExternalProject_Add(...
CMAKE_ARGS ${cmake_args}
)

The CMake project is configured like:

cmake --toolchain ~/cray.cmake -B build

Intel oneMKL LAPACK95 with Gfortran

On Linux, the Intel oneMKL LAPACK95 library can also be used with Gfortran. Build and install LAPACK95 with Intel MKL Lapack95 project.

An example CMakeLists.txt, using the FindLAPACK.cmake under cmake/ of Netlib LAPACK95

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

find_package(LAPACK COMPONENTS LAPACK95 REQUIRED)

add_executable(myexe myprogram.f90)
target_link_libraries(myexe PRIVATE LAPACK::LAPACK95)

Intel oneMKL Scalapack examples

Intel oneAPI / oneMKL includes Scalapack. MKL Scalapack library & include files are under the MKLROOT environment variable for Linux and Windows. Scalapack MKL is used in CMake like:

set(ENABLE_BLACS true)
set(ENABLE_SCALAPACK true)

find_package(MKL CONFIG REQUIRED)

add_executable(mytest main.f90)
target_link_libraries(mytest PRIVATE MKL::MKL)

The exact link flags and compile flags for a particular system are obtained from Intel Link Line Advisor.

Intel MKL Scalapack example project

Netlib Scalapack examples can also be used with non-MKL Scalapack.

GDL datalanguage build

GDL (GNU Data Language) is a free/libre open-source program that runs most IDL code. GDL is actively developed and easily installed by:

  • Linux: apt install gnudatalanguage
  • macOS Homebrew: brew install gnudatalanguage
  • Windows: get the latest release

Building GDL source uses the GDL build script “scripts/build_gdl.sh” to get the prerequisites. If Anaconda Python is present, conda deactivate first to avoid library problems when building GDL.

cmake -B build --install-prefix=$HOME/gdl

cmake --build build --parallel

(optional) Check the install. You will see several plots appearing and disappearing automatically during this test, which takes a few minutes.

cmake --test-dir build -V

Install (do not use sudo):

cmake --install build

Do not build on an ExFAT / FAT32 drive, as the build will fail since symbolic links are not allowed on ExFAT / FAT32. If cmake reports libeigen being too old, install LibEigen3 or:

cmake -Bbuild -DEIGEN3=OFF

To use the Linux distro’s older version of GDL, just use /usr/local/bin/gdl or similar, or rename ~/.local/bin/gdl to ~/.local/bin/gdl0.98 or similar.

Troubleshooting build:

  • Runtime search path conflicts: temporarily comment out those paths in ~/.profile (typically from Anaconda Python, libreadline, libhistory, libz, libjpeg.so)
  • Problems with LZMA, try disabling HDF5: cmake -DHDF5=OFF

CMake get CPU count

For moderately advanced tasks in CMake it can be useful to get the CPU count to allow building or testing in parallel with non-CMake-based ExternalProject. Building a non-CMake ExternalProject from CMake with GNU Make by default builds serially, which can be very slow. This is because CMake doesn’t know if the non-CMake ExternalProject is capable of being built in parallel. When it’s known that the non-CMake-based ExternalProject can be built in parallel, it’s necessary to get the CPU count in CMake as simply putting make -j can overwhelm the computer.

Get CPU count in CMake via cmake_host_system_information. cmake_host_system_information should be used instead of ProcessorCount. The CMake module script ProcessorCount is known to be not as accurate as the C++-based cmake_host_system_information.

Example: specify the parameters relevant to CPU count:

cmake_host_system_information(RESULT Ncpu QUERY NUMBER_OF_PHYSICAL_CORES)
message(STATUS "CMake ${CMAKE_VERSION} using ${Ncpu} threads")

include(ExternalProject)

ExternalProject_Add(demo
BUILD_COMMAND make -j${Ncpu}
)

CB Radio CTCSS tone code squelch

Continuously transmitted subaudible squelch systems such as CTCSS (Continuous Tone-Coded Squelch) and DCS (Digital Coded Squelch) are available on FM radios including CB radios so equipped. CTCSS on CB radio allows maximum range while virtually eliminating unwanted static and skip from other users. FCC WT Docket 10-119 permits CTCSS and DCS on CB radio, along with FM mode and other long-awaited and useful features to the American public. We will call CTCSS and DCS “coded squelch” for short. Subaudible coded squelch is reliable for communications systems that have adequately high SNR and are frequency stable. For example, satellite downlinks, broadcast radio remote control, utility control, broadcast radio identification, which are all applications that have a long time to decode repetitive signals. Mobile two-way radio has typically weak and fading signals with interference from co-channel users and general noise. The squelch should open quickly (say with half a second) and close quickly at the end of the transmission to avoid annoying bursts of noise. The coded squelch must tolerate Doppler shift and frequency drift between transmitters and receivers.

Subaudible continuous coded squelch is not available on AM modes in general. Some communications receivers have coded squelch that also seems to work in AM, whether by accident or design. I have tested such receivers with a signal generator and on AM mode, coded squelch can seem to “work” on the bench. Why then isn’t AM mode CTCSS or DCS generally available?

The following sections explain why CTCSS and DCS are only useful on FM radios. Selective calling on AM and SSB is available by on-channel signaling such as Selcall CCIR 493-4. Selcall CCIR 493-4 is a selective calling system that works on AM and SSB by using in-band signaling that takes several seconds at the beginning of a conversation to open the squelch of one, many, or all receivers in a group. Selcall is used in HF marine radio, HF land mobile radio, and HF amateur radio and is also legal for CB radio in the USA.

Threshold effect and capture effect

FM receivers have a threshold effect that makes them less susceptible to noise than AM receivers. Once the input signal exceeds the noise floor sufficiently, the output SNR increases dramatically. This is the threshold effect. The threshold effect is why FM is less susceptible to noise than AM. The FM capture effect is a similar phenomenon where the FM receiver tends to hear only the strongest signal once it’s a little bit stronger than all the other signals.

These two effects make CTCSS, DCS, and other subaudible modulation like LTR work extremely well on FM, but are completely impractical on AM for mobile two-way communications systems.

SNR compromises

Continuous subaudible coded squelch modulation must not consume too much of the available modulation bandwidth, or the output SNR (audio quality at the receiver’s speaker) will suffer. In FM systems, the deviation of the subaudible information has generally been accepted by industry and de facto standards in the range of 15% .. 35% of the deviation of the main audio signal. For example, on obsolete 5kHz deviation FM systems, the CTCSS, DCS, or trunked subaudible deviation would be 750-1000Hz. In 2.5kHz deviation FM systems, the subaudible deviation would be 375-500Hz for CTCSS or DCS, and 800 Hz for LTR trunked subaudible modulation. Practical experience with 450 MHz and 900 MHz SMR trunked systems led some operators to set the LTR subaudible deviation to 1000 Hz instead of 800 Hz despite the 2.5 kHz maximum total FM deviation, compromising the audio quality and output SNR of the main signal.

If we apply the same principles to AM, we would have to reduce the modulation depth of the main audio signal to accommodate the subaudible tone. This would reduce the output SNR of the main signal, which is already compromised by the nature of AM. The output SNR of AM is generally lower than FM, and the modulation depth of AM is already limited by the need to avoid overmodulation. Adding a subaudible tone to AM would further reduce the modulation depth of the main signal, reducing the output SNR of the main signal. This would reduce or eliminate the slight advantage AM has over FM in weak input SNR conditions.

By way of reference, in broadcast AM (530-1710 kHz) the subaudible modulation depth by 47 CFR § 73.1570 (b)1(ii) is limited to 6% of the total modulation depth. Utilities that used broadcast AM subaudible tones for remote control of transmitters with such little modulation assumed a powerful signal and consistent input SNR with fixed location receivers. Canadian patent CA1149023A discusses using angle modulation of the carrier frequency within 20 Hz of nominal channel center frequency to avoid the typical 5% modulation depth limit of AM. The broadcast AM subaudible signaling standard was field tested in about 1969 as discussed in FCC Docket 17873 that permitted AM broadcast subaudible signaling. The C-QUAM AM stereo system uses a 25 Hz phase-modulated tone at 5% deviation to indicate stereo availability. Once again, strong signals and consistent input SNR are necessary for successful detection of the pilot tone, and detection is not near-instantaneous as required for coded squelch.

Suppose a 5% subaudible modulation depth is used on CB Radio for coded squelch. The power in each sideband of the subaudible tone would be 50 milliwatts (0.05 Watts) for a 4 watt carrier. The input SNR would have to be sufficient to decode the subaudible tone. The output SNR of the main signal would be reduced by the subaudible tone.

Thus the useful communications range between stations would be so dramatically reduced to open the coded squelch that the feature would be impractical with AM mode.

Beat frequencies false squelch

When more than one carrier is above the noise level in an AM communications receiver, the carriers produce a beat frequency defined by the difference in carriers’ frequencies. The beat frequencies may typically fall within the subaudible tone range given modern transmitter frequency stability. This can cause false squelch opening on the receiver. Conversely, the beat frequencies may interfere with the subaudible tone, causing the receiver to not open squelch when it should.

CTest CDash run only once

This CMake function works across Windows, macOS, and Linux checks that the current CTest script is the only instance of CTest running at the time. We use this in CTest CDash scripts to avoid unexpectedly long-running scripts overlapping with the next day’s runs. That could exhaust memory and crash the computer.

Git PGP signed commit using Keybase.io

Git signed commits help verify the Git author’s identity using PGP. Optionally, a user or organization can set rules requiring Git PGP signed commits on Git providers such as GitHub and GitLab

Public PGP IDs can help verify author identity of Git commits, social media, website, etc. A popular free service to share PGP IDs is Keybase.io. Below we demonstrate using Keybase.io PGP ID with Git with the keybase.io client.

Setup GPG on the laptop:

  • Linux: apt install gnupg
  • macOS: brew install gnupg
  • Windows: Kleopatra GPG binary install.

Export Keybase.io public & private key and import into GPG:

keybase pgp export | gpg --import

keybase pgp export --secret | gpg --pinentry-mode=loopback --allow-secret-key --import

If old GnuPG, may need to omit option --pinentry-mode=loopback

The GPG signature is password protected, distinct from the Keybase.io account password.

Verify PGP key:

gpg --list-secret-keys --keyid-format LONG

The first lines will be like:

sec   rsa4096/05F2BD2A525007DF

The hexadecimal part after the / is a public reference to keybase.io keypair. It’s shown on the keybase.io public profile, next to the key icon.


Add Git provider such as GitHub or GitLab verified email address to the PGP key. To make commits “Verified” with the Git provider, at least one of the Git provider verified email addresses must match:

git config --get user.email

Use the GPG public ID below:

gpg --edit-key 05F2BD2A525007DF

In the interactive GPG session that launches, type

adduid

and enter Name and the Email address–which must exactly match the GitHub verified email address. I also add the @users.noreply.github.com fake email that I always use to avoid spam. Do adduid twice–once for the real GitHub verified email address and again for the github_username@users.noreply.github.com fake email.

Add “trust” from the GPG> prompt:

trust

Since it’s you, perhaps a trust level of 5 is appropriate. type

save

to save changes, which may not show up until exiting and reentering the GPG> prompt.

Configure Git to use Keybase public hex ID as seen next to the key logo on the public Keybase.io profile, as in the example below.

git config --global user.signingkey 05F2BD2A525007DF

git config --global commit.gpgsign true

Add the GPG public key to the Git provider. Copy and paste the output from this command into GPG Key of GitHub or GitLab. This is done only once per human, not once per device.

gpg --armor --export 05F2BD2A525007DF

Windows

On Windows, additionally do

git config --global gpg.program "$Env:ProgramFiles (x86)\GnuPG\bin\gpg.exe"

macOS

On macOS, additionally do

brew install pinentry-mac

and add to ~/.zshrc:

export GPG_TTY=$TTY

Usage

GPG can be used to sign Git commits and tags, and can also be disabled per commit.

Verify Git PGP commit sign

Make a git commit after the procedure above, and see the signature notes:

git log --show-signature

it will start with

gpg: Signature made

Temporary disable Git commit sign

If you temporarily lose access to the GPG password, you won’t be able to git commit. A temporary workaround is to set

git config commit.gpgsign false

or simply add the --no-gpg-sign option like:

git commit -am "msg" --no-gpg-sign

If not signing as default, sign only certain commits by

git commit -S

Note that’s a capital “S”.

CB radio base / mobile antenna

An affordable base station antenna for GMRS, MURS, or CB radio can be made from a mobile antenna at roof or balcony level. Be sure the antenna is well away from power lines for safety and noise. It’s important to get the tip of the antenna higher above ground level vs. antenna length. That is, a shorter antenna up high is often better than a longer antenna at ground level.

A mobile antenna near the roof peak using half a mirror mount can screw into the metal eaves for groundplane. A satellite TV dish mount can also be used, assuming a lightweight CB antenna that doesn’t significantly exceed the weight or wind load of the dish mount.

Groundplane

If the antenna is not mounted to metal, a counterpoise / groundplane can be employed at least by drooping a wire or wires 1/4 wavelength long (27 MHz CB ~ 9 feet) from the ground of the antenna base, connected to the coax cable shield.

For higher frequency MURS and GMRS or as a compromise at CB 27 MHz, a magnet mount antenna could be attached to a large dog kennel or magnetic baking sheet. A mobile antenna on the roof will perform poorly without a large magnetic surface to attach to. For safety, put weight on the groundplane or screw it into the balcony or roof to prevent it from blowing off in the wind.

Maximum communications range

Important factors for maximizing communications range include:

  • antenna tip height above average terrain
  • freedom from interference (noise, undesired signals)
  • antenna efficiency – 1/4 wavelength radiating element is desired – balancing length, weight and aesthetics. The mobile antenna should be of a type at least 3 feet long to be worthwhile as a base antenna for effective communication range.
  • antenna blockage by the roof or adjacent structures
  • ensure the power supply is linear to avoid noise–especially important at 27 MHz CB.

Depending on favorable terrain, base-to-base communication range on CB using omnidirectional antennas with at least 1/4 wavelength antenna with base (bottom) height of the antenna about 20 feet above ground, in clear terrain, and with clear channels can legally reach using various emissions modes:

  • AM: 20+ miles
  • FM: 15+ miles
  • SSB: 30+ miles

In contrast, a base station antenna in an urban area on a first-floor deck (say 5 feet above ground) may have only 1/2 mile to 3/4 mile range on CB, MURS, or GMRS to mobile or portable units–similar to simply having a portable unit at the base location.

Estimate communications range using a voice activated recorded at the base station and drive around, giving location on each transmission. Compare CB range to MURS or GMRS range with multiple radios near the recorder.

FM and CTCSS

FM mode is strongly preferred for family and neighborhood communications. For CB radios capable of FM and CTCSS, the squelch can be set to only open for the group’s chosen CTCSS tone. The choice of FM mode and CTCSS is not about maximum communication range, but about reducing interference from other users on the same channel. If the family members or group turns off the radio because of static and interference, that’s no radio at all. Better to have shorter range village communication than no communication at all. CTCSS on CB radio finally largely levels the playing field with other license-free radio bands like MURS and GMRS that could always use FM and CTCSS.

A CB radio gives a heads up when members of a family or group are coming back home. This gives some peace of mind in case of a breakdown, in that the home base or another base station can be reached on the local channel.