openGPMP
Open Source Mathematics Package
Namespaces | Classes | Typedefs | Enumerations | Functions
gpmp::core Namespace Reference

Namespaces

 rndm
 

Classes

class  DataTable
 
class  ThreadPool
 
class  ThreadDispatch
 A class that provides a function to dispatch a function call to a thread pool and return a future object for obtaining the result. More...
 
class  TypeCast
 
class  Logger
 
class  Misc
 A class containing miscellaneous utility functions. More...
 

Typedefs

typedef std::pair< std::vector< std::string >, std::vector< std::vector< std::string > > > DataTableStr
 
typedef std::pair< std::vector< int64_t >, std::vector< std::vector< int64_t > > > DataTableInt
 
typedef std::pair< std::vector< long double >, std::vector< std::vector< long double > > > DataTableDouble
 
typedef std::pair< std::vector< std::string >, std::vector< std::vector< std::variant< int64_t, long double, std::string > > > > TableType
 
typedef std::vector< std::vector< std::variant< int64_t, long double, std::string > > > MixedType
 

Enumerations

enum class  DataType {
  Unknown , String , Integer , Double ,
  dt_uint8 , dt_int8 , dt_uint16 , dt_int16 ,
  dt_uint32 , dt_int32 , dt_uint64 , dt_int64 ,
  dt_double , dt_ldouble , dt_str
}
 enum for representing different data types More...
 
enum class  DataType {
  Unknown , String , Integer , Double ,
  dt_uint8 , dt_int8 , dt_uint16 , dt_int16 ,
  dt_uint32 , dt_int32 , dt_uint64 , dt_int64 ,
  dt_double , dt_ldouble , dt_str
}
 enum for representing different data types More...
 

Functions

static void parallel_for (unsigned nb_elements, std::function< void(int start, int end)> functor, bool use_threads=true)
 Thread rudimentary for loops. More...
 

Typedef Documentation

◆ DataTableDouble

typedef std::pair< std::vector< long double >, std::vector< std::vector< long double > > > gpmp::core::DataTableDouble

Definition at line 74 of file datatable.hpp.

◆ DataTableInt

typedef std::pair< std::vector< int64_t >, std::vector< std::vector< int64_t > > > gpmp::core::DataTableInt

Definition at line 69 of file datatable.hpp.

◆ DataTableStr

typedef std::pair< std::vector< std::string >, std::vector< std::vector< std::string > > > gpmp::core::DataTableStr

Definition at line 65 of file datatable.hpp.

◆ MixedType

typedef std::vector< std::vector<std::variant<int64_t, long double, std::string> > > gpmp::core::MixedType

Definition at line 76 of file datatable_wip.hpp.

◆ TableType

typedef std::pair< std::vector<std::string>, std::vector<std::vector<std::variant<int64_t, long double, std::string> > > > gpmp::core::TableType

Definition at line 72 of file datatable_wip.hpp.

Enumeration Type Documentation

◆ DataType [1/2]

enum gpmp::core::DataType
strong

enum for representing different data types

Enumerator
Unknown 
String 
Integer 
Double 
dt_uint8 
dt_int8 

represents 8 bit unsigned integer

dt_uint16 

represents 8 bit signed integer

dt_int16 

represents 16 bit unsigned integer

dt_uint32 

represents 16 bit signed integer

dt_int32 

represents 32 bit unsigned integer

dt_uint64 

represents 32 bit signed integer

dt_int64 

represents 64 bit unsigned integer

dt_double 

represents 64 bit signed integer

dt_ldouble 

represents double

dt_str 

represent long double

Definition at line 59 of file datatable.hpp.

◆ DataType [2/2]

enum gpmp::core::DataType
strong

enum for representing different data types

Enumerator
Unknown 
String 
Integer 
Double 
dt_uint8 
dt_int8 

represents 8 bit unsigned integer

dt_uint16 

represents 8 bit signed integer

dt_int16 

represents 16 bit unsigned integer

dt_uint32 

represents 16 bit signed integer

dt_int32 

represents 32 bit unsigned integer

dt_uint64 

represents 32 bit signed integer

dt_int64 

represents 64 bit unsigned integer

dt_double 

represents 64 bit signed integer

dt_ldouble 

represents double

dt_str 

represent long double

Definition at line 55 of file datatable_wip.hpp.

Function Documentation

◆ parallel_for()

static void gpmp::core::parallel_for ( unsigned  nb_elements,
std::function< void(int start, int end)>  functor,
bool  use_threads = true 
)
static

Thread rudimentary for loops.

Parameters
[in]nb_elements: size of your for loop
[in]functor(start,end): your function processing a sub chunk of the for loop. "start" is the first index to process (included) until the index "end" (excluded)
for(int i = start; i < end; ++i)
computation(i);
use_threads: enable / disable threads

Definition at line 246 of file threads.hpp.

248  {
249  // -------
250  unsigned nb_threads_hint = 10; // std::thread::hardware_concurrency();
251  unsigned nb_threads = nb_threads_hint == 0 ? 8 : (nb_threads_hint);
252 
253  unsigned batch_size = nb_elements / nb_threads;
254  unsigned batch_remainder = nb_elements % nb_threads;
255 
256  std::vector<std::thread> my_threads(nb_threads);
257 
258  if (use_threads) {
259  // Multithread execution
260  for (unsigned i = 0; i < nb_threads; ++i) {
261  int start = i * batch_size;
262  my_threads[i] = std::thread(functor, start, start + batch_size);
263  }
264  } else {
265  // Single thread execution (for easy debugging)
266  for (unsigned i = 0; i < nb_threads; ++i) {
267  int start = i * batch_size;
268  functor(start, start + batch_size);
269  }
270  }
271 
272  // Deform the elements left
273  int start = nb_threads * batch_size;
274  functor(start, start + batch_remainder);
275 
276  // Wait for the other thread to finish their task
277  if (use_threads) {
278  std::for_each(my_threads.begin(),
279  my_threads.end(),
280  std::mem_fn(&std::thread::join));
281  }
282 }