Advanced Multi-Physics (AMP)
On-Line Documentation
Classes | Enumerations | Functions
AMP::Utilities Namespace Reference

Classes

class  Algorithms
 
struct  copyCast_
 
class  stackVector
 Stack based vector. More...
 

Enumerations

enum class  Backend : int8_t {
  Serial = 0 , Hip_Cuda = 1 , Kokkos = 2 , OpenMP = 3 ,
  OpenACC = 4 , OpenCL = 5 , RAJA = 6
}
 Enum to store the backend used for gpu acceleration. More...
 
enum class  ExecutionSpace : int8_t { unspecified , cpu , device }
 
enum class  MemoryType : int8_t {
  none = -1 , unregistered = 0 , host = 1 , managed = 2 ,
  device = 3
}
 Enum to store pointer type. More...
 

Functions

template<class T >
bool approx_equal (const T &v1, const T &v2, const T tol=type_default_tol< T >())
 
template<class T >
bool approx_equal_abs (const T &v1, const T &v2, const T tol=type_default_tol< T >())
 
Backend backendFromString (const std::string_view name)
 
double bilinear (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &f, double xi, double yi)
 
std::string blockToString (int num)
 
void busy_ms (int N)
 
void busy_s (int N)
 
template<class T1 , class T2 >
void copy (size_t N, const T1 *src, T2 *dst)
 Perform copy with conversion if necessary.
 
template<typename T1 , typename T2 , Backend , class Allocator >
void copyCast (const size_t len, const T1 *vec_in, T2 *vec_out)
 
template<typename T1 , typename T2 , Backend >
void copyCast (const size_t len, const T1 *vec_in, T2 *vec_out)
 
std::string demangle (const std::string &name)
 
ExecutionSpace executionSpaceFromString (const std::string_view name)
 
std::vector< int > factor (uint64_t)
 Get the prime factors for a number.
 
void fillRandom (std::vector< double > &)
 Fill with random values in [0,1].
 
template<size_t N>
void fillRandom (std::vector< std::array< double, N > > &)
 Fill with random values in [0,1].
 
void finalizeKokkos ()
 
template<class T >
size_t findfirst (const std::vector< T > &x, const T &value)
 
template<class T >
size_t findfirst (size_t N, const T *x, const T &value)
 
template<typename ALLOC >
constexpr AMP::Utilities::MemoryType getAllocatorMemoryType ()
 
Backend getDefaultBackend (const MemoryType memory_location)
 
ExecutionSpace getDefaultExecutionSpace (const MemoryType memory_location)
 
std::string getenv (const char *name)
 
std::string getLastErrnoString ()
 Return the string description for the last value in errno (thread-safe)
 
MemoryType getMemoryType (const void *ptr)
 Return the pointer type.
 
std::string_view getString (const Backend backend)
 
std::string_view getString (const ExecutionSpace exec_space)
 
std::string_view getString (MemoryType)
 Return a string for the memory type.
 
constexpr unsigned int hash_char (const std::string_view &str)
 Create a hash key from a char array.
 
void initializeKokkos (int &argc, char *argv[], const AMPManagerProperties &)
 
std::string intToString (int num, int min_width=1)
 
template<class TYPE >
bool isInf (TYPE x)
 Check if a number infinity.
 
bool isKokkosInitialized ()
 
template<class TYPE >
bool isNaN (TYPE x)
 Check if a number NaN.
 
bool isPrime (uint64_t)
 Check if a number is prime.
 
bool KokkosEnabled ()
 
bool KokkosInitializedOpenMP ()
 
std::string levelToString (int num)
 
double linear (const std::vector< double > &x, const std::vector< double > &f, double xi)
 
void memcpy (void *dest, const void *src, std::size_t count)
 Perform memory-memory copy (pointer may be in any memory space)
 
MemoryType memoryLocationFromString (std::string_view name)
 Return the memory type from a string.
 
void memset (void *dest, int ch, std::size_t count)
 Perform memory set (pointer may be in any memory space)
 
std::string nodeToString (int num)
 
void nullUse (const void *)
 Null use function.
 
std::string patchToString (int num)
 
std::vector< uint64_t > primes (uint64_t)
 Return all prime numbers <= x.
 
void printBanner ()
 Print AMP Banner.
 
void printDatabase (const Database &, std::ostream &, const std::string &indent="")
 Print a database.
 
std::string processorToString (int num)
 
template<class T >
void quicksort (size_t N, T *x)
 
template<class T1 , class T2 >
void quicksort (size_t N, T1 *x, T2 *y)
 
template<class T1 , class T2 , class T3 >
void quicksort (size_t N, T1 *x, T2 *y, T3 *z)
 
template<class T >
void quicksort (std::vector< T > &x)
 
template<class T1 , class T2 >
void quicksort (std::vector< T1 > &x, std::vector< T2 > &y)
 
std::string randomString (const AMP::AMP_MPI &comm=AMP_COMM_NULL)
 Function to return a unique alpha-numeric string across a given communicator.
 
bool running_valgrind ()
 Check if valgrind is running.
 
void setenv (const char *name, const char *value)
 
void setNestedOperatorMemoryLocations (std::shared_ptr< AMP::Database > input_db, std::string outerOperatorName, std::vector< std::string > nestedOperatorNames)
 
void sleep_ms (int N)
 
void sleep_s (int N)
 
std::string stringf (const char *format,...)
 std::string version of sprintf
 
std::string strrep (const std::string &str, const std::string &s, const std::string &r)
 
template<class TYPE >
std::string to_string (const std::vector< TYPE > &x)
 Print a vector.
 
double trilinear (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &f, double xi, double yi, double zi)
 
template<class T >
void unique (std::vector< T > &x)
 
template<class T >
void unique (std::vector< T > &X, std::vector< size_t > &I)
 
void zero (void *dest, std::size_t count)
 Perform memory zero (pointer may be in any memory space)
 

Detailed Description

Utilities is a namespace containing basic routines for error reporting, file manipulations, etc. Included are a set of macros that are commonly used.

Enumeration Type Documentation

◆ Backend

enum class AMP::Utilities::Backend : int8_t
strong

Enum to store the backend used for gpu acceleration.

Enumerator
Serial 
Hip_Cuda 
Kokkos 
OpenMP 
OpenACC 
OpenCL 
RAJA 

Definition at line 21 of file Backend.h.

◆ ExecutionSpace

enum class AMP::Utilities::ExecutionSpace : int8_t
strong
Enumerator
unspecified 
cpu 
device 

Definition at line 14 of file Backend.h.

◆ MemoryType

enum class AMP::Utilities::MemoryType : int8_t
strong

Enum to store pointer type.

Enumerator
none 
unregistered 
host 
managed 
device 

Definition at line 21 of file Memory.h.

Function Documentation

◆ approx_equal()

template<class T >
bool AMP::Utilities::approx_equal ( const T &  v1,
const T &  v2,
const T  tol = type_default_tol<T>() 
)
inline

Soft equal checks if two numbers are within the given precision True iff abs(v1-v2)/v1 < tol

Parameters
v1scalar floating point value
v2scalar floating point value
tolrelative tolerance

Definition at line 146 of file Utilities.h.

◆ approx_equal_abs()

template<class T >
bool AMP::Utilities::approx_equal_abs ( const T &  v1,
const T &  v2,
const T  tol = type_default_tol<T>() 
)
inline

Soft equal checks if two numbers are equivalent within the given precision True iff abs(v1-v2) < tol

Parameters
v1scalar floating point value
v2scalar floating point value
tolrelative tolerance

Definition at line 162 of file Utilities.h.

◆ backendFromString()

Backend AMP::Utilities::backendFromString ( const std::string_view  name)

◆ bilinear()

double AMP::Utilities::bilinear ( const std::vector< double > &  x,
const std::vector< double > &  y,
const std::vector< double > &  f,
double  xi,
double  yi 
)

Function to perform tri-linear interpolation

Parameters
xx-coordinates
yy-coordinates
ffunction values at the coordinates ( Nx x Ny )
xix-coordinate of desired point
yiy-coordinate of desired point

◆ blockToString()

std::string AMP::Utilities::blockToString ( int  num)

◆ busy_ms()

void AMP::Utilities::busy_ms ( int  N)

Busy wait for X ms

Parameters
NTime to wait (ms)

Referenced by busy_s().

◆ busy_s()

void AMP::Utilities::busy_s ( int  N)
inline

Busy wait for X s

Parameters
NTime to wait (s)

Definition at line 366 of file Utilities.h.

References busy_ms().

◆ copy()

template<class T1 , class T2 >
void AMP::Utilities::copy ( size_t  N,
const T1 *  src,
T2 *  dst 
)

Perform copy with conversion if necessary.

◆ copyCast() [1/2]

template<typename T1 , typename T2 , Backend , class Allocator >
void AMP::Utilities::copyCast ( const size_t  len,
const T1 *  vec_in,
T2 *  vec_out 
)

Helper function to copy and cast (single<->double precision) values between two arrays

Parameters
[in]lenLength of above vectors
[in]vec_inThe incoming vector to get the values from
[in,out]vec_outThe outgoing vector to with the up/down-casted values from vec_in It is assumed that vec_out is properly allocated

◆ copyCast() [2/2]

template<typename T1 , typename T2 , Backend >
void AMP::Utilities::copyCast ( const size_t  len,
const T1 *  vec_in,
T2 *  vec_out 
)

◆ demangle()

std::string AMP::Utilities::demangle ( const std::string &  name)

◆ executionSpaceFromString()

ExecutionSpace AMP::Utilities::executionSpaceFromString ( const std::string_view  name)

◆ factor()

std::vector< int > AMP::Utilities::factor ( uint64_t  )

Get the prime factors for a number.

◆ fillRandom() [1/2]

void AMP::Utilities::fillRandom ( std::vector< double > &  )

Fill with random values in [0,1].

◆ fillRandom() [2/2]

template<size_t N>
void AMP::Utilities::fillRandom ( std::vector< std::array< double, N > > &  )

Fill with random values in [0,1].

◆ finalizeKokkos()

void AMP::Utilities::finalizeKokkos ( )

◆ findfirst() [1/2]

template<class T >
size_t AMP::Utilities::findfirst ( const std::vector< T > &  x,
const T &  value 
)
inline

Search a std::vector for the first entry >= the given value This routine only works on sorted arrays and does not check if the array is sorted This routine returns the size of the vector if no entries in the vector are >= the desired entry.

Parameters
xvector to sort
valueValue to search for

Definition at line 269 of file Utilities.h.

References findfirst().

◆ findfirst() [2/2]

template<class T >
size_t AMP::Utilities::findfirst ( size_t  N,
const T *  x,
const T &  value 
)

Search a std::vector for the first entry >= the given value This routine only works on sorted arrays and does not check if the array is sorted This routine returns the size of the vector if no entries in the vector are >= the desired entry.

Parameters
NNumber of entires to search
xvector to sort
valueValue to search for

Referenced by findfirst().

◆ getAllocatorMemoryType()

template<typename ALLOC >
constexpr AMP::Utilities::MemoryType AMP::Utilities::getAllocatorMemoryType ( )
constexpr

Definition at line 76 of file Memory.h.

References AMP_ERROR, device, host, and managed.

◆ getDefaultBackend()

Backend AMP::Utilities::getDefaultBackend ( const MemoryType  memory_location)

◆ getDefaultExecutionSpace()

ExecutionSpace AMP::Utilities::getDefaultExecutionSpace ( const MemoryType  memory_location)

◆ getenv()

std::string AMP::Utilities::getenv ( const char *  name)

Get an environmental variable

Parameters
nameThe name of the environmental variable
Returns
The value of the enviornmental variable

◆ getLastErrnoString()

std::string AMP::Utilities::getLastErrnoString ( )

Return the string description for the last value in errno (thread-safe)

◆ getMemoryType()

MemoryType AMP::Utilities::getMemoryType ( const void *  ptr)

Return the pointer type.

◆ getString() [1/3]

std::string_view AMP::Utilities::getString ( const Backend  backend)

◆ getString() [2/3]

std::string_view AMP::Utilities::getString ( const ExecutionSpace  exec_space)

◆ getString() [3/3]

std::string_view AMP::Utilities::getString ( MemoryType  )

Return a string for the memory type.

◆ hash_char()

constexpr unsigned int AMP::Utilities::hash_char ( const std::string_view &  str)
constexpr

Create a hash key from a char array.

Definition at line 317 of file Utilities.h.

◆ initializeKokkos()

void AMP::Utilities::initializeKokkos ( int &  argc,
char *  argv[],
const AMPManagerProperties  
)

◆ intToString()

std::string AMP::Utilities::intToString ( int  num,
int  min_width = 1 
)

Convert an integer to a string.

The returned string is padded with zeros as needed so that it contains at least the number of characters indicated by the minimum width argument. When the number is positive, the string is padded on the left. When the number is negative, the '-' sign appears first, followed by the integer value padded on the left with zeros. For example, the statement intToString(12, 5) returns "00012" and the statement intToString(-12, 5) returns "-0012".

◆ isInf()

template<class TYPE >
bool AMP::Utilities::isInf ( TYPE  x)

Check if a number infinity.

◆ isKokkosInitialized()

bool AMP::Utilities::isKokkosInitialized ( )

◆ isNaN()

template<class TYPE >
bool AMP::Utilities::isNaN ( TYPE  x)

Check if a number NaN.

◆ isPrime()

bool AMP::Utilities::isPrime ( uint64_t  )

Check if a number is prime.

◆ KokkosEnabled()

bool AMP::Utilities::KokkosEnabled ( )

◆ KokkosInitializedOpenMP()

bool AMP::Utilities::KokkosInitializedOpenMP ( )

◆ levelToString()

std::string AMP::Utilities::levelToString ( int  num)

◆ linear()

double AMP::Utilities::linear ( const std::vector< double > &  x,
const std::vector< double > &  f,
double  xi 
)

Function to perform linear interpolation

Parameters
xx-coordinates
ffunction values at the coordinates ( Nx )
xix-coordinate of desired point

◆ memcpy()

void AMP::Utilities::memcpy ( void *  dest,
const void *  src,
std::size_t  count 
)

Perform memory-memory copy (pointer may be in any memory space)

◆ memoryLocationFromString()

MemoryType AMP::Utilities::memoryLocationFromString ( std::string_view  name)

Return the memory type from a string.

◆ memset()

void AMP::Utilities::memset ( void *  dest,
int  ch,
std::size_t  count 
)

Perform memory set (pointer may be in any memory space)

◆ nodeToString()

std::string AMP::Utilities::nodeToString ( int  num)

Convert common integer values to strings.

These are simply wrappers around intToString that ensure the same width is uniformly used when converting to string representations.

◆ nullUse()

void AMP::Utilities::nullUse ( const void *  )

Null use function.

◆ patchToString()

std::string AMP::Utilities::patchToString ( int  num)

◆ primes()

std::vector< uint64_t > AMP::Utilities::primes ( uint64_t  )

Return all prime numbers <= x.

◆ printBanner()

void AMP::Utilities::printBanner ( )

Print AMP Banner.

◆ printDatabase()

void AMP::Utilities::printDatabase ( const Database ,
std::ostream &  ,
const std::string &  indent = "" 
)

Print a database.

◆ processorToString()

std::string AMP::Utilities::processorToString ( int  num)

◆ quicksort() [1/5]

template<class T >
void AMP::Utilities::quicksort ( size_t  N,
T *  x 
)

Quicksort a std::vector

Parameters
NNumber of entries to sort
xvector to sort

Referenced by quicksort(), and quicksort().

◆ quicksort() [2/5]

template<class T1 , class T2 >
void AMP::Utilities::quicksort ( size_t  N,
T1 *  x,
T2 *  y 
)

Quicksort a vector

Parameters
NNumber of entries to sort
xVector to sort
yExtra values to be sorted with X

◆ quicksort() [3/5]

template<class T1 , class T2 , class T3 >
void AMP::Utilities::quicksort ( size_t  N,
T1 *  x,
T2 *  y,
T3 *  z 
)

Quicksort a vector

Parameters
NNumber of entries to sort
xVector to sort
yExtra values to be sorted with x
zExtra values to be sorted with x

◆ quicksort() [4/5]

template<class T >
void AMP::Utilities::quicksort ( std::vector< T > &  x)
inline

Quicksort a std::vector

Parameters
xvector to sort

Definition at line 195 of file Utilities.h.

References quicksort().

◆ quicksort() [5/5]

template<class T1 , class T2 >
void AMP::Utilities::quicksort ( std::vector< T1 > &  x,
std::vector< T2 > &  y 
)
inline

Quicksort a std::vector

Parameters
xVector to sort
yExtra values to be sorted with x

Definition at line 215 of file Utilities.h.

References AMP_INSIST, and quicksort().

◆ randomString()

std::string AMP::Utilities::randomString ( const AMP::AMP_MPI comm = AMP_COMM_NULL)

Function to return a unique alpha-numeric string across a given communicator.

This will return a unique alpha-numeric string on the given communicator. The string will be the same on all processors, but unique for all subsequent calls to this routine regardless of the communicator used. Note: this is a blocking call on the given communicator.

◆ running_valgrind()

bool AMP::Utilities::running_valgrind ( )

Check if valgrind is running.

◆ setenv()

void AMP::Utilities::setenv ( const char *  name,
const char *  value 
)

Set an environmental variable

Parameters
nameThe name of the environmental variable
valueThe value to set

◆ setNestedOperatorMemoryLocations()

void AMP::Utilities::setNestedOperatorMemoryLocations ( std::shared_ptr< AMP::Database input_db,
std::string  outerOperatorName,
std::vector< std::string >  nestedOperatorNames 
)

◆ sleep_ms()

void AMP::Utilities::sleep_ms ( int  N)
inline

Sleep for X ms

Parameters
NTime to sleep (ms)

Definition at line 348 of file Utilities.h.

◆ sleep_s()

void AMP::Utilities::sleep_s ( int  N)
inline

Sleep for X s

Parameters
NTime to sleep (s)

Definition at line 354 of file Utilities.h.

◆ stringf()

std::string AMP::Utilities::stringf ( const char *  format,
  ... 
)
inline

std::string version of sprintf

Definition at line 397 of file Utilities.h.

References AMP_INSIST.

◆ strrep()

std::string AMP::Utilities::strrep ( const std::string &  str,
const std::string &  s,
const std::string &  r 
)

Replace part of a strig with another

Parameters
strInput string to search/replace
sSearch string
rReplacement string

◆ to_string()

template<class TYPE >
std::string AMP::Utilities::to_string ( const std::vector< TYPE > &  x)

Print a vector.

◆ trilinear()

double AMP::Utilities::trilinear ( const std::vector< double > &  x,
const std::vector< double > &  y,
const std::vector< double > &  z,
const std::vector< double > &  f,
double  xi,
double  yi,
double  zi 
)

Function to perform tri-linear interpolation

Parameters
xx-coordinates
yy-coordinates
zz-coordinates
ffunction values at the coordinates ( Nx x Ny x Nz )
xix-coordinate of desired point
yiy-coordinate of desired point
ziz-coordinate of desired point

◆ unique() [1/2]

template<class T >
void AMP::Utilities::unique ( std::vector< T > &  x)

Get the unique set on a std::vector

Parameters
xvector to create the unique set (elements will be returned in sorted order)

◆ unique() [2/2]

template<class T >
void AMP::Utilities::unique ( std::vector< T > &  X,
std::vector< size_t > &  I 
)

Subroutine to perform the unique operation on the elements in X This function performs the unique operation on the values in X storing them in Y. It also returns the index vector I such that Y[k] = X[I[k]].

Parameters
XPoints to sort (nx)
IThe index vector I (ny)

◆ zero()

void AMP::Utilities::zero ( void *  dest,
std::size_t  count 
)

Perform memory zero (pointer may be in any memory space)



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:45.
Comments on this page