common.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef _SCTL_COMMON_HPP_
  2. #define _SCTL_COMMON_HPP_
  3. #ifndef SCTL_NAMESPACE
  4. #define SCTL_NAMESPACE sctl
  5. #endif
  6. #define SCTL_QUOTEME(x) SCTL_QUOTEME_1(x)
  7. #define SCTL_QUOTEME_1(x) #x
  8. #define SCTL_INCLUDE(x) SCTL_QUOTEME(SCTL_NAMESPACE/x)
  9. // Profiling parameters
  10. #ifndef SCTL_PROFILE
  11. #define SCTL_PROFILE -1 // Granularity level
  12. #endif
  13. #if defined(__AVX512__) || defined(__AVX512F__)
  14. #define SCTL_ALIGN_BYTES 64
  15. #elif defined(__AVX__)
  16. #define SCTL_ALIGN_BYTES 32
  17. #elif defined(__SSE__)
  18. #define SCTL_ALIGN_BYTES 16
  19. #else
  20. #define SCTL_ALIGN_BYTES 8
  21. #endif
  22. // Parameters for memory manager
  23. #ifndef SCTL_MEM_ALIGN
  24. #define SCTL_MEM_ALIGN (64 > SCTL_ALIGN_BYTES ? 64 : SCTL_ALIGN_BYTES)
  25. #endif
  26. #ifndef SCTL_GLOBAL_MEM_BUFF
  27. #define SCTL_GLOBAL_MEM_BUFF 1024LL * 0LL // in MB
  28. #endif
  29. // Define NULL
  30. #ifndef NULL
  31. #define NULL 0
  32. #endif
  33. #include <cstddef>
  34. #include <cstdint>
  35. namespace SCTL_NAMESPACE {
  36. typedef long Integer; // bounded numbers < 32k
  37. typedef int64_t Long; // problem size
  38. }
  39. #include <iostream>
  40. #define SCTL_WARN(msg) \
  41. do { \
  42. std::cerr << "\n\033[1;31mWarning:\033[0m " << msg << '\n'; \
  43. } while (0)
  44. #define SCTL_ERROR(msg) \
  45. do { \
  46. std::cerr << "\n\033[1;31mError:\033[0m " << msg << '\n'; \
  47. abort(); \
  48. } while (0)
  49. #define SCTL_ASSERT_MSG(cond, msg) \
  50. do { \
  51. if (!(cond)) SCTL_ERROR(msg); \
  52. } while (0)
  53. #define SCTL_ASSERT(cond) \
  54. do { \
  55. if (!(cond)) { \
  56. fprintf(stderr, "\n%s:%d: %s: Assertion `%s' failed.\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond); \
  57. abort(); \
  58. } \
  59. } while (0)
  60. #define SCTL_UNUSED(x) (void)(x) // to ignore unused variable warning.
  61. namespace SCTL_NAMESPACE {
  62. #ifdef SCTL_MEMDEBUG
  63. template <class ValueType> class ConstIterator;
  64. template <class ValueType> class Iterator;
  65. template <class ValueType, Long DIM> class StaticArray;
  66. #else
  67. template <typename ValueType> using Iterator = ValueType*;
  68. template <typename ValueType> using ConstIterator = const ValueType*;
  69. template <typename ValueType, Long DIM> using StaticArray = ValueType[DIM];
  70. #endif
  71. }
  72. #endif //_SCTL_COMMON_HPP_