Windows Subsystem for Linux version 0.67.6 and newer can use systemd, which makes using Cron on WSL straightforward.
Check the WSL version from Windows Terminal (not WSL):
Many types of programs can be run via Cron, including CTest scripts that upload to CDash.
While CDash gives information once the CMake / CTest processes have started, if the CTest scripts aren’t running, the Cron job may need to be debugged.
Debugging Cron jobs involves examining Cron logs.
Cron logging is optional.
For debugging, it may be easier to simply append to the end of the cron job line a file dump like:
On macOS, Cron logging is disabled by default, but the results of cron jobs are available via system mail, which is stored in /var/log/$(whoami).
Apple
launchd
can be used instead of Cron via Property List files, but many simply prefer Cron.
On Linux systems, Cron may log to locations like “/var/log/cron”.
For systems that use “rsyslog”, check “/etc/rsyslog.conf” for this line to be uncommented:
“conda activate” is
intended for interactive shells
and therefore doesn’t work properly with Cron jobs and other non-interactive shell environments.
Rather than “bash -l”, consider using
conda run.
By default the stdin/stdout/stderr are captured by conda run–no text input or output is seen until after the executable finishes running.
For testing scripts, it’s possible to get live stdin/stdout/stderr with the option:
conda run --no-capture-output <exe>
For example, if a Cron job runs a CTest or CDash script that needs to use a Conda Python environment “myenv”, make a Cron job like:
conda run --name myenv ctest -S memcheck.cmake
Cron jobs are single lines only in “crontab -e”.
In general more complex Cron jobs are invoked by calling a script from crontab.
For example suppose a CMake project using Conda Python needs to be configured, built and tested.
Make a cron job script like:
# So CMake finds Conda Python environment "myenv"conda run --name myenv \
cmake -Bbuild
cmake --build build --parallel
# preface with "conda run --name myenv" if Python invoked during the buildconda run --name myenv \
ctest --test-dir build
NOTE: environment variables are defined for all cron jobs at the top of the crontab.
The “conda” executable must be on PATH environment variable, or specify the full path to “conda” in each cron job line.
For example, on macOS the crontab PATH might be like:
Gfortran 10 added the default behavior to make type mismatches an error instead of a warning.
Legacy Fortran programs too often did not explicitly specify the procedure interfaces to allow implicit polymorphism.
The Fortran 2008 standard cleaned up this situation in part with type(*).
Workaround: Gfortran flag -fallow-argument-mismatch can be used to degrade the errors to warnings.
It is however
strongly recommended
to fix the problem in the legacy code, if it’s part of your code ownership.
For external libraries like MPI-2, the interfaces are intended to be polymorphic but use Fortran 90-style interfaces.
The user code can declare an explicit interface.
However, this is not recommended – we have seen intermittent runtime errors with MPI-2 using the technique below, that were entirely fixed by using the “mpi_f08” MPI-3+ interface.
usempi,only:MPI_STATUS_SIZEimplicitnoneinterface!! This avoids GCC >= 10 type mismatch warnings for MPI-2
subroutinempi_send(BUF,COUNT,DATATYPE,DEST,TAG,COMM,IERROR)type(*),dimension(..),intent(in)::BUFinteger,intent(in)::COUNT,DATATYPE,DEST,TAG,COMMinteger,intent(out)::IERRORendsubroutinesubroutinempi_recv(BUF,COUNT,DATATYPE,SOURCE,TAG,COMM,STATUS,IERROR)importMPI_STATUS_SIZEtype(*),dimension(..),intent(in)::BUFinteger,intent(in)::COUNT,DATATYPE,SOURCE,TAG,COMMinteger,intent(out)::STATUS(MPI_STATUS_SIZE),IERRORendsubroutineendinterface
Many code languages don’t have garbage collection and also suffer from issues like uninitialized variables etc.
CMake can use several common tools to check memory usage of a program.
These tools are limited by the code coverage of the tests run.
The basic procedure is to build the project in “Debug” mode, run CTest memcheck task, then browse the results.
Then fix the problems and rerun the tests to verify.
The popular “valgrind” memory tester is available on Linux, including Windows Subsystem for Linux (WSL).
CMake will usually automatically detect valgrind if the valgrind executable is on the environment variable PATH.
That is, if typing “valgrind” at the Terminal runs, then CMake should find and use it.
To use memory checking tools from CMake, the CMakeLists.txt must include the line:
include(CTest)
Here are example CMake commands to check memory of a project.
The tests may run more slowly than usual due to the testing overhead.
The CTest terminal output will look like:
MemCheck log files can be found here: (<#> corresponds to test number)
build/Testing/Temporary/MemoryChecker.<#>.log
Memory checking results:
Memory Leak - 8
Potential Memory Leak - 8
Uninitialized Memory Conditional - 3
Each MemCheck CTest number has a log file.
The traceback stack to the suspected area (line) of code detected to lead to memory problems is given.
Edit the code to fix the problem, then rebuild and rerun memcheck as above.
To change from default CTest memcheck settings, create a script
memcheck.cmake
in the top level of the project (where the top CMakeLists.txt is).
Run this script like:
It’s often useful to set per-test environment variables in CMake’s CTest testing frontend.
The environment variables appear and disappear with the start and end of each test, in isolation from any other tests that may be running in parallel.
This is accomplished via CMake test properties
ENVIRONMENT
and
ENVIRONMENT_MODIFICATION.
Example: set environment variable FOO=1 for a test “bar” like:
set_property(TESTbarPROPERTYENVIRONMENT"FOO=1")
multiple variables are set with a CMake list (semicolon delimited) like:
Here comes an issue.
In general, Windows needs DLLs to be on the current working directory or in environment variable PATH.
We handle this by a
script
that appends to PATH for CTest on Windows:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Package managers can detect which packages were manually installed (at user or script explicit request) and which were implicitly installed as a prerequisite.
When uninstalling the manually installed package, the prerequisite packages are often not auto-uninstalled.
To recover a significant amount of disk space (gigabytes perhaps) from unused packages, an autoremove command is useful.
CMAKE_LINK_LIBRARY_USING_FEATURE
doesn’t have a
feature
to delay loading import for MSVC-like compilers flag like
/delayload.
Nonetheless, /delayload can be accomplished in a compact way as in the following example: