Walker test code coverage report
Current view: top level - RNGTest - TestU01Wrappers.hpp (source / functions) Hit Total Coverage
Commit: test_coverage.info Lines: 15 17 88.2 %
Date: 2022-09-21 18:57:21 Functions: 30 72 41.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 24 25.0 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/RNGTest/TestU01Wrappers.hpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.
       7                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     TestU01 global-scope wrappers
       9                 :            :   \details   TestU01 global-scope wrappers. For more info on why these functions
      10                 :            :     are in global-scope, see Main/RNGTest.C, for more info on why they are
      11                 :            :     static inline, see http://stackoverflow.com/a/9399539.
      12                 :            : */
      13                 :            : // *****************************************************************************
      14                 :            : #ifndef TestU01Wrappers_h
      15                 :            : #define TestU01Wrappers_h
      16                 :            : 
      17                 :            : #include <map>
      18                 :            : 
      19                 :            : #include "RNG.hpp"
      20                 :            : 
      21                 :            : namespace rngtest {
      22                 :            : 
      23                 :            : extern std::map< tk::ctr::RawRNGType, tk::RNG > g_rng;
      24                 :            : 
      25                 :            : template< tk::ctr::RawRNGType id >
      26                 : 2216511233 : static inline double uniform( void*, void* )
      27                 :            : // *****************************************************************************
      28                 :            : //  Global-scope TestU01 uniform RNG wrapper
      29                 :            : //! \details This functions is used as an external uniform random number
      30                 :            : //!   generator (i.e., external to TestU01) that is called by the TestU01
      31                 :            : //!   library, hence the required signature and hence the global scope. It is
      32                 :            : //!   templated on a unique integer corresponding to the RNG type enum defined
      33                 :            : //!   by tk::ctr::RNGType. Templating on the id enables the compiler to generate
      34                 :            : //!   a different wrapper for a different RNG facilitating simultaneous calls to
      35                 :            : //!   any or all wrappers as they are unique functions.
      36                 :            : //! \return Random number generated as a double-precision floating point value
      37                 :            : // *****************************************************************************
      38                 :            : {
      39                 : 2216511233 :   double r = 0.0;
      40         [ +  - ]: 2216511233 :   const auto rng = g_rng.find( id );
      41         [ +  - ]: 2216511233 :   if (rng != end(g_rng))
      42         [ +  - ]: 2216511233 :     rng->second.uniform( CkMyPe(), 1, &r );
      43                 :            :   else
      44 [ -  - ][ -  - ]:          0 :     Throw( "RNG not found" );
                 [ -  - ]
      45                 : 2216511233 :   return r;
      46                 :            : }
      47                 :            : 
      48                 :            : template< tk::ctr::RawRNGType id >
      49                 :  506400000 : static inline unsigned long uniform_bits( void*, void* )
      50                 :            : // *****************************************************************************
      51                 :            : //  Global-scope TestU01 uniform RNG bits wrapper
      52                 :            : //! \details This functions is used as an external uniform random number
      53                 :            : //!   generator (i.e., external to TestU01) that is called by the TestU01
      54                 :            : //!   library, hence the required signature and hence the global scope. It is
      55                 :            : //!   templated on a unique integer corresponding to the RNG type enum defined
      56                 :            : //!   by tk::ctr::RNGType. Templating on the id enables the compiler to generate
      57                 :            : //!   a different wrapper for a different RNG facilitating simultaneous calls to
      58                 :            : //!   any or all wrappers as they are unique functions.
      59                 :            : //! \return Random number generated as a unsigned long integer value
      60                 :            : // *****************************************************************************
      61                 :            : {
      62                 :  506400000 :   double r = 0.0;
      63         [ +  - ]:  506400000 :   const auto rng = g_rng.find( id );
      64         [ +  - ]:  506400000 :   if (rng != end(g_rng))
      65         [ +  - ]:  506400000 :     rng->second.uniform( CkMyPe(), 1, &r );
      66                 :            :   else
      67 [ -  - ][ -  - ]:          0 :     Throw( "RNG not found" );
                 [ -  - ]
      68                 :  506400000 :   return static_cast<unsigned long>(r * unif01_NORM32);
      69                 :            : }
      70                 :            : 
      71                 :            : template< tk::ctr::RawRNGType id >
      72                 :         48 : static inline unif01_Gen* createTestU01Gen( const std::string& name )
      73                 :            : // *****************************************************************************
      74                 :            : //  Global-scope create TestU01 external generator
      75                 :            : //! \details This is the function that contains the TestU01 library call to
      76                 :            : //!   register a TestU01-external random number generator that later can be
      77                 :            : //!   subjected to the TestU01 batteries. It ties the unique global-scope
      78                 :            : //!   wrappers templated on the unique RNG id, thus TestU01 will see them as
      79                 :            : //!   different external generators.
      80                 :            : //! \param[in] name Random number generator name
      81                 :            : // *****************************************************************************
      82                 :            : {
      83                 :         48 :   return unif01_CreateExternGen01( const_cast<char*>(name.c_str()),
      84                 :         48 :                                    uniform< id >, uniform_bits< id > );
      85                 :            : }
      86                 :            : 
      87                 :            : } // rngtest::
      88                 :            : 
      89                 :            : #endif // TestU01Wrappers_h

Generated by: LCOV version 1.14