OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
nancheck.hpp File Reference

NaN detection and debugging utilities. More...

#include <cmath>
#include <iostream>
#include <mpi.h>
#include <vector>
Include dependency graph for nancheck.hpp:

Go to the source code of this file.

Macros

#define CHECK_AND_ABORT_IF_NAN(value)
 
#define CHECK_AND_ABORT_IF_NANS(vec)
 

Functions

template<typename T >
bool pfc::utils::hasNaNs (const std::vector< T > &vec)
 
template<typename T >
void pfc::utils::abortIfNaN (T value, const char *filename, int line)
 
template<typename T >
void pfc::utils::abortIfNaNs (const std::vector< T > &vec, const char *filename, int line)
 

Detailed Description

NaN detection and debugging utilities.

This header provides macros and functions for detecting NaN (Not-a-Number) values in floating-point computations, useful for debugging numerical issues.

Key features:

  • CHECK_AND_ABORT_IF_NAN(value): Macro to check single values
  • CHECK_AND_ABORT_IF_VECTOR_HAS_NAN(vector): Macro to check entire vectors
  • Enabled with NAN_CHECK_ENABLED preprocessor flag
  • MPI-aware: Reports rank where NaN was detected

NaN checks are disabled by default for performance. Enable with: cmake -DNAN_CHECK_ENABLED=ON

double result = compute_something();
CHECK_AND_ABORT_IF_NAN(result); // Aborts if NaN detected
NaN detection and debugging utilities.
See also
utils.hpp for other utility functions
Author
OpenPFC Development Team
Date
2025

Function Documentation

◆ abortIfNaNs()

template<typename T >
void pfc::utils::abortIfNaNs ( const std::vector< T > &  vec,
const char filename,
int  line 
)

Checks if there are any NaNs in a vector of floats and aborts the MPI application if NaNs are detected. Prints an error message indicating the process rank where NaNs were found before aborting.

Parameters
vecThe vector of floats to check.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasNaNs()

template<typename T >
bool pfc::utils::hasNaNs ( const std::vector< T > &  vec)

Checks if there are any NaNs in a vector of floats.

Parameters
vecThe vector of floats to check.
Returns
True if NaNs are found, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function: