Verificarlo CI

1. Verificarlo probes

This file contains utility functions to enable the Verificarlo Continuous Integration system (VFC_CI), a tool for verifying the numerical accuracy and stability of scientific computations.

Verificarlo is a tool that uses Monte Carlo Arithmetic to detect numerical instabilities by randomly rounding floating-point operations. The VFC_CI system automates the process of testing numerical stability in a continuous integration environment.

This module is a wrapper around Verificarlo's vfc_probes system. The goal of these QMCkl probe functions is to simplify the use of vfc_probes, and to provide functions that can be called either with or without VFC_CI support by using preprocessor directives:

  • when VFC_CI is disabled, the functions will either return false (indicating no error) or perform a check based on a reference value
  • when VFC_CI is enabled, the functions will encapsulate calls to vfc_probe, enabling automatic numerical stability testing

Moreover, users don't need to worry about the life cycle of the probes data structure, as it is automatically created, dumped (written to output), and freed by this wrapper. This automation simplifies integration into existing codebases.

VFC_CI support can be enabled by using the following configure command, which uses the Verificarlo compiler wrappers:

This wrapper also provides a Fortran interface (in its dedicated file), enabling numerical stability testing for Fortran code as well.

To learn more about Verificarlo CI and how to interpret its results: https://github.com/verificarlo/verificarlo/blob/master/doc/06-Postprocessing.md#verificarlo-ci

1.2. Standard probe, without check

  • if VFC_CI is defined, place a standard probe
  • if VFC_CI is undefined, return false (no error)

1.3. Probe with absolute check

  • if VFC_CI is defined, place a probe with an absolute check
  • if VFC_CI is undefined, perform an absolute check based on target value and accuracy

1.4. Probe with relative check

  • if VFC_CI is defined, place a probe with a relative check
  • if VFC_CI is undefined, perform a relative check based on target value and accuracy

2. Fortran wrappers

The Fortran wrappers take ordinary Fortran character strings and terminate them with a NUL before calling the C layer: vfc_probes measures the test and variable names with strlen, and Fortran character literals are not NUL-terminated.

Fortran
module qmckl_verificarlo_f
  use, intrinsic :: iso_c_binding
  implicit none

  interface
     logical(c_bool) function qmckl_probe_c &
          (testName, varName, val) &
          bind(C, name="qmckl_probe_f")

       use, intrinsic :: iso_c_binding
       import
       implicit none

       character(C_CHAR), dimension(*) :: testName
       character(C_CHAR), dimension(*) :: varName

       real(C_DOUBLE) :: val
     end function qmckl_probe_c

     logical(c_bool) function qmckl_probe_check_c &
          (testName, varName, val, expectedValue, accuracyTarget) &
          bind(C, name="qmckl_probe_check_f")

       use, intrinsic :: iso_c_binding
       import
       implicit none

       character(C_CHAR), dimension(*) :: testName
       character(C_CHAR), dimension(*) :: varName

       real(C_DOUBLE) :: val
       real(C_DOUBLE) :: expectedValue
       real(C_DOUBLE) :: accuracyTarget
     end function qmckl_probe_check_c

     logical(c_bool) function qmckl_probe_check_relative_c &
          (testName, varName, val, expectedValue, accuracyTarget) &
          bind(C, name="qmckl_probe_check_relative_f")

       use, intrinsic :: iso_c_binding
       import
       implicit none

       character(C_CHAR), dimension(*) :: testName
       character(C_CHAR), dimension(*) :: varName

       real(C_DOUBLE) :: val
       real(C_DOUBLE) :: expectedValue
       real(C_DOUBLE) :: accuracyTarget
     end function qmckl_probe_check_relative_c
  end interface

contains

  logical(c_bool) function qmckl_probe(testName, varName, val)
    character(len=*), intent(in) :: testName
    character(len=*), intent(in) :: varName
    real(C_DOUBLE), intent(in)   :: val

    qmckl_probe = qmckl_probe_c(trim(testName)//c_null_char, &
                                trim(varName)//c_null_char, val)
  end function qmckl_probe

  logical(c_bool) function qmckl_probe_check(testName, varName, val, &
                                             expectedValue, accuracyTarget)
    character(len=*), intent(in) :: testName
    character(len=*), intent(in) :: varName
    real(C_DOUBLE), intent(in)   :: val
    real(C_DOUBLE), intent(in)   :: expectedValue
    real(C_DOUBLE), intent(in)   :: accuracyTarget

    qmckl_probe_check = qmckl_probe_check_c(trim(testName)//c_null_char, &
                                            trim(varName)//c_null_char, val, &
                                            expectedValue, accuracyTarget)
  end function qmckl_probe_check

  logical(c_bool) function qmckl_probe_check_relative(testName, varName, &
                                                      val, expectedValue, &
                                                      accuracyTarget)
    character(len=*), intent(in) :: testName
    character(len=*), intent(in) :: varName
    real(C_DOUBLE), intent(in)   :: val
    real(C_DOUBLE), intent(in)   :: expectedValue
    real(C_DOUBLE), intent(in)   :: accuracyTarget

    qmckl_probe_check_relative = &
        qmckl_probe_check_relative_c(trim(testName)//c_null_char, &
                                     trim(varName)//c_null_char, val, &
                                     expectedValue, accuracyTarget)
  end function qmckl_probe_check_relative
end module qmckl_verificarlo_f