Many IDEs create per-project cache directories with metadata relevant to the IDE configuration for that project.
Similar to
user global .gitattributes,
instead of editing the .gitignore file for each repository,
ignore directories in Git for all repos a particular user has as follows, for any operating system.
On Windows with Python subprocess, an executable may be missing DLL from PATH.
This environment error can be detected and a message given to the user.
The return code of the subprocess can be checked for the error code 3221225781, which corresponds to hex error code C0000135.
importsubprocessimportosimportloggingret = subprocess.run('myprog.exe')
if ret.returncode == 3221225781and os.name == 'nt':
# Windows 0xc0000135, missing DLL logging.error('missing DLL detected. Ensure DLL directory is in environment variable PATH')
path = os.environ['PATH']
print("PATH:", path)
raiseSystemExit(ret.returncode)
If putting DLLs on PATH is problematic, another possible approach is
statically compiling the executable,
but this may not be feasible for all programs.
PROJ.4 / GEOS-based
CartoPy
downloads and caches shape files as needed, avoiding a large install up front.
CartoPy is an
alternative
to Matplotlib
basemap.
CartoPy uses easily available / automatically & seamlessly installed
prereqs.
conda install cartopy
Note the zorder option of Matplotlib elements such as contourf.
Higher number zorder is higher priority (on top).
See
PlotPrecip.py
for an example of zorder.
An example using CartoPy follows:
CMake environment variable
CMAKE_BUILD_PARALLEL_LEVEL
can be manually set to control default number of build parallel threads.
Parallel builds are virtually always desired to save build and rebuild time.
As a starting point, perhaps set CMAKE_BUILD_PARALLEL_LEVEL environment variable to be equal to the number of physical or logical CPU cores by setting it in the user profile:
#!/bin/bash
if [[ x"${CMAKE_BUILD_PARALLEL_LEVEL}" == x ]]; thenn=8;
case"$OSTYPE" in
linux*)
n=$(nproc);;
darwin*)
n=$(sysctl -n hw.physicalcpu);;
bsd*)
n=$(sysctl -n hw.ncpu);;
esacexportCMAKE_BUILD_PARALLEL_LEVEL=${n}fi
Or for Windows, in environment variable settings:
CMAKE_BUILD_PARALLEL_LEVEL=%NUMBER_OF_PROCESSORS%
If the computer runs out of RAM, reduce the specific command parallelism with the cmake --build --parallel N command line option.
For Ninja build systems, specific targets can control the number of workers with
job pools.
The purpose of compiler flag checks is to test if a flag is supported.
Metabuild system (such as CMake and Meson) compiler flag checks must not test the “-Wno-” form of a warning flag.
This is because several compilers including Clang, GCC, Intel oneAPI emit a “success” return code 0 for the “-Wno-” form of an unsupported flag.
From time to time, the topic of why meta-build systems like CMake and Meson are single-threaded sequentially executing processes is brought up.
With desktop workstations (not to mention build farms) having 32, 64, and even 128+ CPU cores increasingly widespread, and the configure / generation step of meta-build systems taking tens of seconds to a few minutes on large projects, developers are understandably frustrated by the lack of parallelism.
A fundamental issue with CMake, Meson and equivalently for other meta-build systems is that the user’s CMake scripts would then have to be dataflow / declarative versus imperative.
This would require reworking of script syntax and meta-build internal code radically.
In Meson, Python threading (single thread executes at one time) is used in subprojects, giving a speed boost in download time of subproject source code.
There is no Python multiprocessing or ProcessPoolExecutor in Meson configure step.
Meson parallel execution is for build (Ninja) and test.
Both build and test are also done in parallel in CMake.
For CMake, the ExternalProject steps can already be run in parallel (including download) via the underlying build system.
A way to speed up meta-build configure time–here specific to CMake–is to stuff the CMakeCache.txt file with precomputed values and/or use CMake Toolchain to do likewise, skipping configure tests when the host build system is static.
CMakeCache.txt stuffing is a technique Meson uses to speed up configure time of CMake-based subprojects from Meson projects.
Flake8
is a Python code style checker that can detect unexecuted syntax errors.
Python 3.12 with flake8 detects PEP8 formatting errors
inside f-strings
that are
not yet handled by Black.
Currently these formatting errors must be corrected by hand.
CI jobs should test with Python < 3.12 and Python >= 3.12 to ensure the f-string syntax is valid in older and newer Python versions.
Debugging C, C++, and Fortran code with GNU Debugger “gdb” is akin to debugging Python with
pdb.
The popular
VSCode IDE can use GDB
for debugging C, C++, and Fortran code.
This can be especially handy when using
VSCode over SSH
to a remote computer like an HPC.
Start GDB Fortran debugger: assuming executable myprog with arguments hello and 3:
gdb --args ./myprog hello 3
Run program in gdb (perhaps after setting breakpoints) with
r
A typical debugging task uses breakpoints.
Breakpoints are where the debugger stops running until you type
c
Set breakpoints by functionName:lineNumber.
Example: Set a breakpoint in function myfun on line 32
b myfun:32
For breakpoints in Fortran modules in this example line 32 of a module named mymod in function myfun:
b mymod::myfun:32
List all scope variables as two separate steps.
local variables
arguments to the function.
Variable type, size (bytes/element), and shape (elements/dim) are available for each variable “var” by
whatis var
Example: a Fortran iso_fortran_envreal64 3-D array of size 220 x 23 x 83:
var = REAL(8) (220,23,83)
If “var” is a Fortran
derived type,
get the same information about each record (akin to “property”) of the derived type by:
whatis var%prop
Local variables are variables used only within the scope of the function–excluding arguments to the function.
info locals
List the names and values of all arguments to the current function:
info args
Example: in integer function myfun(a,b) or subroutine mysub(a,b), upon info args you’d see perhaps
a = 1.5
b = 0.2
If a or b are arrays or structs, array values are printed as well.
However, it is often more convenient (if using care) to use terse variables that are not as specific:
if(CMAKE_VERSIONVERSION_LESS3.25ANDCMAKE_SYSTEM_NAMESTREQUAL"Linux")set(LINUXtrue)endif()if(APPLE)# macOS
elseif(BSD)# FreeBSD, NetBSD, OpenBSD, etc.
elseif(LINUX)# Linux
elseif(UNIX)# Linux, BSD, etc. (including macOS if not trapped above)
elseif(WIN32)# Windows
else()message(FATAL_ERROR"Unsupported system: ${CMAKE_SYSTEM_NAME}")endif()