spades Namespace Reference

SPADES API: spades Namespace Reference
SPADES API
spades Namespace Reference

Solver for PArallel Discrete Event Simulation. More...

Namespaces

namespace  constants
 SPADES constants.
 
namespace  ic
 SPADES initial conditions.
 
namespace  io
 IO functionality for SPADES.
 
namespace  particles
 SPADES particles.
 

Classes

struct  Factory
 
class  SPADES
 Main SPADES class. More...
 

Functions

amrex::Real random_exponential (const amrex::Real lambda)
 Exponential distribution.
 
void goto_next_line (std::istream &is)
 Skip to the next line in stream.
 
void read_file (const std::string &filename, amrex::Vector< char > &charBuf, bool bExitOnError)
 Read and broadcast file to all ranks.
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Long pairing_function (const amrex::Long k1, const amrex::Long k2)
 Cantor pairing function.
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real random_exponential (const amrex::Real lambda, amrex::RandomEngine const &engine)
 Exponential distribution.
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint64_t max_representation (const int nbits)
 Maximum unsigned integer representation given a number of bits.
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint64_t bitmask (const int nbits)
 bitmask given a number of bits
 

Detailed Description

Solver for PArallel Discrete Event Simulation.

Function Documentation

◆ bitmask()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint64_t spades::bitmask ( const int nbits)

bitmask given a number of bits

Parameters
nbits[in] number of bits
Returns
bitmask
65{
66 AMREX_ASSERT(nbits < 64);
67 // Shift 1 by nbits (create power of 2)
68 // Subtract 1 to fill all lower nbits with 1s
69 // bitmask(16): 0xFFFF
70 return (1ULL << nbits) - 1;
71}

◆ goto_next_line()

void spades::goto_next_line ( std::istream & is)

Skip to the next line in stream.

Parameters
is[in, out] stream
11{
12 constexpr std::streamsize bl_ignore_max{100000};
13 is.ignore(bl_ignore_max, '\n');
14}
Here is the caller graph for this function:

◆ max_representation()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint64_t spades::max_representation ( const int nbits)

Maximum unsigned integer representation given a number of bits.

Parameters
nbits[in] number of bits
Returns
maximum integer representation
50{
51 AMREX_ASSERT(nbits < 64);
52 std::uint64_t result = 2;
53 for (int i = 0; i < nbits; i++) {
54 result *= 2;
55 }
56 return result;
57}

◆ pairing_function()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Long spades::pairing_function ( const amrex::Long k1,
const amrex::Long k2 )

Cantor pairing function.

Parameters
k1[in] first number
k2[in] second number
Returns
value of the Cantor pairing function
20{
21 return (k1 + k2) * (k1 + k2 + 1) / 2 + k2;
22}

◆ random_exponential() [1/2]

amrex::Real spades::random_exponential ( const amrex::Real lambda)

Exponential distribution.

Parameters
lambda[in] rate parameter
Returns
sample from an exponential distribution
5{
6
7 return std::log(1 - amrex::Random()) / (-lambda);
8}
Here is the caller graph for this function:

◆ random_exponential() [2/2]

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real spades::random_exponential ( const amrex::Real lambda,
amrex::RandomEngine const & engine )

Exponential distribution.

Parameters
lambda[in] rate parameter
engine[in] random number generator
Returns
sample from an exponential distribution
32{
33 return std::log(1 - amrex::Random(engine)) / (-lambda);
34}

◆ read_file()

void spades::read_file ( const std::string & filename,
amrex::Vector< char > & charBuf,
bool bExitOnError )

Read and broadcast file to all ranks.

Equivalent to amrex::ParallelDescriptor::ReadAndBcastFile but for all ranks.

Parameters
filename[in] file to read
charBuf[out] character buffer
bExitOnError[in] exit if error
20{
21 enum { IO_Buffer_Size = 262144 * 8 };
22
23#ifdef BL_SETBUF_SIGNED_CHAR
24 using Setbuf_Char_Type = signed char;
25#else
26 using Setbuf_Char_Type = char;
27#endif
28
29 amrex::Vector<Setbuf_Char_Type> io_buffer(IO_Buffer_Size);
30
31 amrex::Long file_length(0);
32 amrex::Long file_length_padded(0);
33
34 std::ifstream iss;
35
36 iss.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
37 iss.open(filename.c_str(), std::ios::in);
38 if (!iss.good()) {
39 if (bExitOnError) {
40 amrex::FileOpenFailed(filename);
41 } else {
42 file_length = -1;
43 }
44 } else {
45 iss.seekg(0, std::ios::end);
46 file_length = static_cast<std::streamoff>(iss.tellg());
47 iss.seekg(0, std::ios::beg);
48 }
49
50 if (file_length == -1) {
51 return;
52 }
53
54 file_length_padded = file_length + 1;
55 charBuf.resize(file_length_padded);
56
57 iss.read(charBuf.dataPtr(), file_length);
58 iss.close();
59
60 charBuf[file_length] = '\0';
61}
Here is the caller graph for this function: