Grappa  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
common.hpp File Reference
#include <stdint.h>
#include <iostream>
#include <glog/logging.h>
#include <memory>
#include <algorithm>
#include <cstddef>
#include <time.h>

Go to the source code of this file.

Classes

struct  Range< T >
 Range type that represents the values [start,end). More...
 
struct  block_offset_t
 
struct  Functor
 

Namespaces

 Grappa
 this core's base pointer
 
 bittwiddle
 

Macros

#define ONE   (1ULL)
 
#define KILO   (1024ULL * ONE)
 
#define MEGA   (1024ULL * KILO)
 
#define GIGA   (1024ULL * MEGA)
 
#define TERA   (1024ULL * GIGA)
 
#define PETA   (1024ULL * TERA)
 
#define CACHE_LINE_SIZE   (64ULL)
 
#define SIZE_OF_CACHE   (MEGA * 64ULL)
 
#define THOUSAND   (1000ULL * ONE)
 
#define MILLION   (1000ULL * THOUSAND)
 
#define BILLION   (1000ULL * MILLION)
 
#define MAX(a, b)   ((a) < (b) ? (b) : (a))
 
#define MIN(a, b)   ((a) > (b) ? (b) : (a))
 
#define ALIGN_UP(x, y)
 
#define GRAPPA_DEPRECATED   __attribute__((deprecated))
 Use to deprecate old APIs. More...
 
#define GRAPPA_TIME(var, block)
 
#define GRAPPA_TIMER(var)
 
#define GRAPPA_TIME_LOG(name)
 
#define GRAPPA_TIME_VLOG(level, name, indent)
 
#define GRAPPA_TIME_REGION(var)
 
#define DISALLOW_COPY_AND_ASSIGN(Name)
 Disable copy constructor and assignment operator. More...
 
#define rdtscll(val)
 Read 64-bit timestamp counter. More...
 
#define GET_TYPE(member)   BOOST_PP_TUPLE_ELEM(2,0,member)
 
#define GET_NAME(member)   BOOST_PP_TUPLE_ELEM(2,1,member)
 
#define CAT_EACH(r, data, elem)   BOOST_PP_CAT(elem, data)
 
#define AUTO_CONSTRUCTOR_DETAIL_PARAM(r, data, member)   GET_TYPE(member) GET_NAME(member)
 
#define DECL_W_TYPE(r, data, member)   GET_TYPE(member) GET_NAME(member);
 
#define AUTO_CONSTRUCTOR_DETAIL_INIT(r, data, member)   GET_NAME(member) ( GET_NAME(member) )
 
#define AUTO_CONSTRUCTOR_DETAIL(className, members)
 
#define AUTO_CONSTRUCTOR(className, members)   AUTO_CONSTRUCTOR_DETAIL(className, members)
 
#define AUTO_DECLS(members)   BOOST_PP_SEQ_FOR_EACH(CAT_EACH, ,BOOST_PP_SEQ_TRANSFORM(DECL_W_TYPE, BOOST_PP_EMPTY, members))
 
#define FUNCTOR(name, members)
 
#define CHECK_NULL(val)   Grappa::impl::CheckNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val))
 
#define DCHECK_NULL(val)   ;
 
#define MPI_CHECK(mpi_call)
 

Typedefs

using range_t = Range< int64_t >
 range for block distribution More...
 

Enumerations

enum  Grappa::TaskMode { Grappa::TaskMode::Bound, Grappa::TaskMode::Unbound }
 Specify whether tasks are bound to the core they're spawned on, or if they can be load-balanced (via work-stealing). More...
 
enum  Grappa::SyncMode { Grappa::SyncMode::Blocking, Grappa::SyncMode::Async }
 Specify whether an operation blocks until complete, or returns "immediately". More...
 

Functions

template<typename T , typename... Args>
std::unique_ptr< T > make_unique (Args &&...args)
 Construct unique_ptr more easily. More...
 
double Grappa::walltime (void)
 "Universal" wallclock time (works at least for Mac, MTA, and most Linux) More...
 
template<typename T , unsigned B>
bittwiddle::signextend (const T x)
 Sign extension. More...
 
unsigned int bittwiddle::log2 (unsigned int v)
 Base 2 log of 32-bit number. More...
 
template<typename T >
T * Grappa_magic_identity_function (T *t)
 OMGWTFBBQ Grappa magic identity function Use this to get a pointer to a template function inside a template function, etc. More...
 
template<typename Container , typename Comparator >
auto min_element (const Container &c, Comparator cmp) -> decltype(*c.begin())
 Helper for invoking 'std::min_element' on containers. More...
 
template<typename Container , typename Comparator >
auto min_element (const Container &c0, const Container &c1, Comparator cmp) -> decltype(*c0.begin())
 Helper for invoking 'std::min_element' on containers. More...
 
template<typename T , typename Comparator >
min_element (Range< T > r, Comparator cmp)
 Helper for invoking 'std::min_element' on a Range. More...
 
std::ostream & operator<< (std::ostream &o, const range_t &r)
 
range_t blockDist (int64_t start, int64_t end, int64_t rank, int64_t numBlocks)
 
block_offset_t indexToBlock (int64_t index, int64_t numElements, int64_t numBlocks)
 
void fast_srand (int seed)
 
int fast_rand ()
 
template<typename T >
const char * Grappa::typename_of ()
 Get string containing name of type. More...
 
template<typename T >
const char * Grappa::typename_of (const T &unused)
 Get string containing name of type. More...
 

Macro Definition Documentation

#define ALIGN_UP (   x,
 
)
Value:
((((u_int64_t)(x) & (((u_int64_t)(y))-1)) != 0) ? \
((void *)(((u_int64_t)(x) & (~(u_int64_t)((y)-1)))+(y))) \
: ((void *)(x)))

Definition at line 81 of file common.hpp.

#define AUTO_CONSTRUCTOR (   className,
  members 
)    AUTO_CONSTRUCTOR_DETAIL(className, members)

Definition at line 296 of file common.hpp.

#define AUTO_CONSTRUCTOR_DETAIL (   className,
  members 
)
Value:
className(BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TRANSFORM( \
AUTO_CONSTRUCTOR_DETAIL_PARAM, BOOST_PP_EMPTY, members))) : \
BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TRANSFORM( \
AUTO_CONSTRUCTOR_DETAIL_INIT, BOOST_PP_EMPTY, members)) \
{}
#define AUTO_CONSTRUCTOR_DETAIL_INIT(r, data, member)
Definition: common.hpp:286
#define AUTO_CONSTRUCTOR_DETAIL_PARAM(r, data, member)
Definition: common.hpp:280

Definition at line 289 of file common.hpp.

#define AUTO_CONSTRUCTOR_DETAIL_INIT (   r,
  data,
  member 
)    GET_NAME(member) ( GET_NAME(member) )

Definition at line 286 of file common.hpp.

#define AUTO_CONSTRUCTOR_DETAIL_PARAM (   r,
  data,
  member 
)    GET_TYPE(member) GET_NAME(member)

Definition at line 280 of file common.hpp.

#define AUTO_DECLS (   members)    BOOST_PP_SEQ_FOR_EACH(CAT_EACH, ,BOOST_PP_SEQ_TRANSFORM(DECL_W_TYPE, BOOST_PP_EMPTY, members))

Definition at line 299 of file common.hpp.

#define BILLION   (1000ULL * MILLION)

Definition at line 71 of file common.hpp.

#define CACHE_LINE_SIZE   (64ULL)

Definition at line 67 of file common.hpp.

#define CAT_EACH (   r,
  data,
  elem 
)    BOOST_PP_CAT(elem, data)

Definition at line 278 of file common.hpp.

#define DECL_W_TYPE (   r,
  data,
  member 
)    GET_TYPE(member) GET_NAME(member);

Definition at line 283 of file common.hpp.

#define DISALLOW_COPY_AND_ASSIGN (   Name)
Value:
Name( const Name & ); \
void operator=( const Name & )
Message & operator=(const Message &m)=delete
Not allowed.

Disable copy constructor and assignment operator.

Put this in your class' private declarations. (from google public C++ coding standards)

Definition at line 157 of file common.hpp.

#define FUNCTOR (   name,
  members 
)
Value:
struct name : public Functor { \
AUTO_DECLS(members) \
AUTO_CONSTRUCTOR( name, members ) \
name() {} /* default constructor */\
inline void operator()() const; \
}; \
inline void name::operator()() const
#define AUTO_DECLS(members)
Definition: common.hpp:299
#define AUTO_CONSTRUCTOR(className, members)
Definition: common.hpp:296
void operator()()
#define inline
Definition: Worker.cpp:130

Definition at line 306 of file common.hpp.

#define GET_NAME (   member)    BOOST_PP_TUPLE_ELEM(2,1,member)

Definition at line 276 of file common.hpp.

#define GET_TYPE (   member)    BOOST_PP_TUPLE_ELEM(2,0,member)

Definition at line 274 of file common.hpp.

#define GIGA   (1024ULL * MEGA)

Definition at line 64 of file common.hpp.

#define GRAPPA_DEPRECATED   __attribute__((deprecated))

Use to deprecate old APIs.

Definition at line 87 of file common.hpp.

#define GRAPPA_TIME (   var,
  block 
)
Value:
do { \
double _tmptime = Grappa::walltime(); \
block \
var = Grappa::walltime()-_tmptime; \
} while(0)
double walltime(void)
"Universal" wallclock time (works at least for Mac, MTA, and most Linux)
Definition: common.hpp:99

Definition at line 123 of file common.hpp.

#define GRAPPA_TIME_LOG (   name)
Value:
for (double _tmpstart = Grappa::walltime(), _tmptime = -1; _tmptime < 0; \
LOG(INFO) << name << ": " << (Grappa::walltime()-_tmpstart), _tmptime = 1)
double walltime(void)
"Universal" wallclock time (works at least for Mac, MTA, and most Linux)
Definition: common.hpp:99

Definition at line 135 of file common.hpp.

#define GRAPPA_TIME_REGION (   var)
Value:
for (double _tmpstart = Grappa::walltime(), _tmptime = -1; _tmptime < 0; \
var += (Grappa::walltime()-_tmpstart), _tmptime = 1)
double walltime(void)
"Universal" wallclock time (works at least for Mac, MTA, and most Linux)
Definition: common.hpp:99

Definition at line 144 of file common.hpp.

#define GRAPPA_TIME_VLOG (   level,
  name,
  indent 
)
Value:
VLOG(level) << indent << name << "..."; \
for (double _tmpstart = Grappa::walltime(), _tmptime = -1; _tmptime < 0; \
VLOG(level) << indent << " (" << (Grappa::walltime()-_tmpstart) << " s)", _tmptime = 1)
double walltime(void)
"Universal" wallclock time (works at least for Mac, MTA, and most Linux)
Definition: common.hpp:99

Definition at line 139 of file common.hpp.

#define GRAPPA_TIMER (   var)
Value:
for (double _tmpstart = Grappa::walltime(), _tmptime = -1; \
_tmptime < 0; \
var = _tmptime = Grappa::walltime() - _tmpstart)
double walltime(void)
"Universal" wallclock time (works at least for Mac, MTA, and most Linux)
Definition: common.hpp:99

Definition at line 130 of file common.hpp.

#define KILO   (1024ULL * ONE)

Definition at line 62 of file common.hpp.

#define MAX (   a,
 
)    ((a) < (b) ? (b) : (a))

Definition at line 74 of file common.hpp.

#define MEGA   (1024ULL * KILO)

Definition at line 63 of file common.hpp.

#define MILLION   (1000ULL * THOUSAND)

Definition at line 70 of file common.hpp.

#define MIN (   a,
 
)    ((a) > (b) ? (b) : (a))

Definition at line 77 of file common.hpp.

#define ONE   (1ULL)

Definition at line 61 of file common.hpp.

#define PETA   (1024ULL * TERA)

Definition at line 66 of file common.hpp.

#define rdtscll (   val)
Value:
do { \
unsigned int __a,__d; \
asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \
(val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \
} while(0)

Read 64-bit timestamp counter.

Definition at line 188 of file common.hpp.

#define SIZE_OF_CACHE   (MEGA * 64ULL)

Definition at line 68 of file common.hpp.

#define TERA   (1024ULL * GIGA)

Definition at line 65 of file common.hpp.

#define THOUSAND   (1000ULL * ONE)

Definition at line 69 of file common.hpp.

Typedef Documentation

using range_t = Range<int64_t>

range for block distribution

Definition at line 240 of file common.hpp.

Function Documentation

range_t blockDist ( int64_t  start,
int64_t  end,
int64_t  rank,
int64_t  numBlocks 
)
inline

Definition at line 248 of file common.hpp.

int fast_rand ( )
inline

Definition at line 322 of file common.hpp.

void fast_srand ( int  seed)
inline

Definition at line 319 of file common.hpp.

template<typename T >
T* Grappa_magic_identity_function ( T *  t)

OMGWTFBBQ Grappa magic identity function Use this to get a pointer to a template function inside a template function, etc.

Definition at line 204 of file common.hpp.

block_offset_t indexToBlock ( int64_t  index,
int64_t  numElements,
int64_t  numBlocks 
)
inline

Definition at line 260 of file common.hpp.

template<typename T , typename... Args>
std::unique_ptr<T> make_unique ( Args &&...  args)

Construct unique_ptr more easily.

(to be included in C++1y)

auto m = make_unique<MyClass>(a,5);
// equivalent to:
auto m = std::unique_ptr<MyClass>(new MyClass(a,5));

Definition at line 45 of file common.hpp.

template<typename Container , typename Comparator >
auto min_element ( const Container &  c,
Comparator  cmp 
) -> decltype(*c.begin())

Helper for invoking 'std::min_element' on containers.

Definition at line 210 of file common.hpp.

template<typename Container , typename Comparator >
auto min_element ( const Container &  c0,
const Container &  c1,
Comparator  cmp 
) -> decltype(*c0.begin())

Helper for invoking 'std::min_element' on containers.

Definition at line 216 of file common.hpp.

template<typename T , typename Comparator >
T min_element ( Range< T >  r,
Comparator  cmp 
)

Helper for invoking 'std::min_element' on a Range.

Definition at line 229 of file common.hpp.

std::ostream& operator<< ( std::ostream &  o,
const range_t r 
)
inline

Definition at line 243 of file common.hpp.