Dhairya Malhotra 7 years ago
parent
commit
548c9620c5
5 changed files with 20 additions and 28 deletions
  1. 5 2
      Makefile
  2. 6 7
      include/sctl.hpp
  3. 4 13
      include/sctl/mem_mgr.hpp
  4. 4 6
      include/sctl/mem_mgr.txx
  5. 1 0
      include/sctl/profile.hpp

+ 5 - 2
Makefile

@@ -13,8 +13,9 @@ else
 endif
 
 CXXFLAGS += -DSCTL_MEMDEBUG # Enable memory checks
+CXXFLAGS += -DSCTL_GLOBAL_MEM_BUFF=0 # Global memory buffer size in MB
 
-CXXFLAGS += -DSCTL_QUAD_T=__float128 -Wfloat-conversion
+CXXFLAGS += -DSCTL_QUAD_T=__float128 -Wfloat-conversion # Enable quadruple precision
 
 #CXXFLAGS += -DSCTL_HAVE_MPI #use MPI
 
@@ -26,6 +27,8 @@ CXXFLAGS += -lfftw3 -DSCTL_HAVE_FFTW
 CXXFLAGS += -lfftw3f -DSCTL_HAVE_FFTWF
 CXXFLAGS += -lfftw3l -DSCTL_HAVE_FFTWL
 
+CXXFLAGS += -DSCTL_PROFILE=5 -DSCTL_VERBOSE # Enable profiling
+
 
 RM = rm -f
 MKDIRS = mkdir -p
@@ -50,4 +53,4 @@ $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
 
 clean:
 	$(RM) -r $(BINDIR)/* $(OBJDIR)/*
-	$(RM) *~ */*~
+	$(RM) *~ */*~ */*/*~

+ 6 - 7
include/sctl.hpp

@@ -9,17 +9,16 @@
 #define SCTL_QUOTEME_1(x) #x
 #define SCTL_INCLUDE(x) SCTL_QUOTEME(sctl/x)
 
-// Have MPI
-//#define SCTL_HAVE_MPI
-
 // Parameters for memory manager
 #define SCTL_MEM_ALIGN 64
+#ifndef SCTL_GLOBAL_MEM_BUFF
 #define SCTL_GLOBAL_MEM_BUFF 1024LL * 0LL  // in MB
-//#define SCTL_MEMDEBUG // Enable memory checks.
+#endif
 
 // Profiling parameters
-#define SCTL_PROFILE 5 // Granularity level
-#define SCTL_VERBOSE
+#ifndef SCTL_PROFILE
+#define SCTL_PROFILE -1 // Granularity level
+#endif
 
 // MPI Wrapper
 #include SCTL_INCLUDE(comm.hpp)
@@ -42,7 +41,7 @@
 // Parallel solver
 #include SCTL_INCLUDE(parallel_solver.hpp)
 
-// ChebBasis
+// Chebyshev basis
 #include SCTL_INCLUDE(cheb_utils.hpp)
 
 // Morton

+ 4 - 13
include/sctl/mem_mgr.hpp

@@ -267,15 +267,6 @@ template <class ValueType> const ValueType* Ptr2ConstItr(const void* ptr, Long l
 
 #endif
 
-/**
- * \brief Identify each type uniquely.
- */
-template <class T> class TypeTraits {
-
- public:
-  static uintptr_t ID();
-};
-
 /**
  * \brief MemoryManager class declaration.
  */
@@ -288,11 +279,12 @@ class MemoryManager {
    * \brief Header data for each memory block.
    */
   struct MemHead {
+    typedef decltype(typeid(char).hash_code()) TypeID;
     Long n_indx;
     Long n_elem;
     Long type_size;
     Long alloc_ctr;
-    uintptr_t type_id;
+    TypeID type_id;
     unsigned char check_sum;
   };
 
@@ -310,7 +302,7 @@ class MemoryManager {
 
   static void CheckMemHead(const MemHead& p);
 
-  Iterator<char> malloc(const Long n_elem = 1, const Long type_size = sizeof(char), const uintptr_t type_id = TypeTraits<char>::ID()) const;
+  Iterator<char> malloc(const Long n_elem, const Long type_size = sizeof(char), const MemHead::TypeID type_id = typeid(char).hash_code()) const;
 
   void free(Iterator<char> p) const;
 
@@ -383,8 +375,7 @@ template <class ValueType> Iterator<ValueType> aligned_new(Long n_elem = 1, cons
 
 /**
  * \brief Aligned de-allocation as an alternative to delete. Calls the object
- * destructors. Not sure which destructor is called for virtual classes, this
- * is why we also match the TypeTraits<T>::ID()
+ * destructor.
  */
 template <class ValueType> void aligned_delete(Iterator<ValueType> A, const MemoryManager* mem_mgr = &MemoryManager::glbMemMgr());
 

+ 4 - 6
include/sctl/mem_mgr.txx

@@ -92,8 +92,6 @@ template <class ValueType, Long DIM> inline StaticArray<ValueType, DIM>& StaticA
 
 #endif
 
-template <class T> inline uintptr_t TypeTraits<T>::ID() { return (uintptr_t) & ID; }
-
 inline MemoryManager::MemoryManager(Long N) {
   buff_size = N;
   {  // Allocate buff
@@ -169,7 +167,7 @@ inline void MemoryManager::CheckMemHead(const MemHead& mem_head) {  // Verify he
 #endif
 }
 
-inline Iterator<char> MemoryManager::malloc(const Long n_elem, const Long type_size, const uintptr_t type_id) const {
+inline Iterator<char> MemoryManager::malloc(const Long n_elem, const Long type_size, const MemHead::TypeID type_id) const {
   if (!n_elem) return nullptr;
   static uintptr_t alignment = SCTL_MEM_ALIGN - 1;
   static uintptr_t header_size = (uintptr_t)(sizeof(MemHead) + alignment) & ~(uintptr_t)alignment;
@@ -471,7 +469,7 @@ template <class ValueType> inline Iterator<ValueType> aligned_new(Long n_elem, c
 
   static MemoryManager def_mem_mgr(0);
   if (!mem_mgr) mem_mgr = &def_mem_mgr;
-  Iterator<ValueType> A = (Iterator<ValueType>)mem_mgr->malloc(n_elem, sizeof(ValueType));
+  Iterator<ValueType> A = (Iterator<ValueType>)mem_mgr->malloc(n_elem, sizeof(ValueType), typeid(ValueType).hash_code());
   SCTL_ASSERT_MSG(A != nullptr, "memory allocation failed.");
 
   if (!std::is_trivial<ValueType>::value) {  // Call constructors
@@ -504,7 +502,7 @@ template <class ValueType> inline void aligned_delete(Iterator<ValueType> A, con
     MemoryManager::MemHead& mem_head = MemoryManager::GetMemHead((char*)&A[0]);
 #ifdef SCTL_MEMDEBUG
     MemoryManager::CheckMemHead(mem_head);
-// SCTL_ASSERT_MSG(mem_head.n_elem==1 || mem_head.type_id==TypeTraits<ValueType>::ID(), "pointer to aligned_delete has different type than what was used in aligned_new.");
+    SCTL_ASSERT_MSG(mem_head.type_id==typeid(ValueType).hash_code(), "pointer to aligned_delete has different type than what was used in aligned_new.");
 #endif
     Long n_elem = mem_head.n_elem;
     for (Long i = 0; i < n_elem; i++) {
@@ -514,7 +512,7 @@ template <class ValueType> inline void aligned_delete(Iterator<ValueType> A, con
 #ifdef SCTL_MEMDEBUG
     MemoryManager::MemHead& mem_head = MemoryManager::GetMemHead((char*)&A[0]);
     MemoryManager::CheckMemHead(mem_head);
-    // SCTL_ASSERT_MSG(mem_head.type_id==TypeTraits<ValueType>::ID(), "pointer to aligned_delete has different type than what was used in aligned_new.");
+    SCTL_ASSERT_MSG(mem_head.type_id==typeid(ValueType).hash_code(), "pointer to aligned_delete has different type than what was used in aligned_new.");
     Long size = mem_head.n_elem * mem_head.type_size;
     Iterator<char> A_ = (Iterator<char>)A;
 #pragma omp parallel for

+ 1 - 0
include/sctl/profile.hpp

@@ -51,6 +51,7 @@ class Profile {
     std::vector<Long> f_log;
     std::vector<Long> m_log;
     std::vector<Long> max_m_log;
+
     ProfileData() {
       FLOP = 0;
       MEM = 0;