diff --git a/lib/allocator/AlignedAllocator.cc b/lib/allocator/AlignedAllocator.cc index 10b49f4b..2a80dbf9 100644 --- a/lib/allocator/AlignedAllocator.cc +++ b/lib/allocator/AlignedAllocator.cc @@ -1,7 +1,7 @@ #include #include -namespace Grid { +NAMESPACE_BEGIN(Grid); MemoryStats *MemoryProfiler::stats = nullptr; bool MemoryProfiler::debug = false; @@ -49,7 +49,7 @@ void *PointerCache::Insert(void *ptr,size_t bytes) { void *PointerCache::Lookup(size_t bytes) { - if (bytes < 4096 ) return NULL; + if (bytes < 4096 ) return NULL; #ifdef _OPENMP assert(omp_in_parallel()==0); @@ -90,7 +90,7 @@ void check_huge_pages(void *Buf,uint64_t BYTES) ++n4ktotal; if (pageaddr != baseaddr + j * page_size) ++nnothuge; - } + } } int rank = CartesianCommunicator::RankWorld(); printf("rank %d Allocated %d 4k pages, %d not in huge pages\n", rank, n4ktotal, nnothuge); @@ -106,20 +106,21 @@ std::string sizeString(const size_t bytes) double count = bytes; while (count >= 1024 && s < 7) - { + { s++; count /= 1024; - } + } if (count - floor(count) == 0.0) - { + { snprintf(buf, bufSize, "%d %sB", (int)count, suffixes[s]); - } + } else - { + { snprintf(buf, bufSize, "%.1f %sB", count, suffixes[s]); - } + } return std::string(buf); } -} +NAMESPACE_END(Grid); + diff --git a/lib/allocator/AlignedAllocator.h b/lib/allocator/AlignedAllocator.h index 3b27aec9..49798d7a 100644 --- a/lib/allocator/AlignedAllocator.h +++ b/lib/allocator/AlignedAllocator.h @@ -24,8 +24,8 @@ Author: Peter Boyle 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory - *************************************************************************************/ - /* END LEGAL */ +*************************************************************************************/ +/* END LEGAL */ #ifndef GRID_ALIGNED_ALLOCATOR_H #define GRID_ALIGNED_ALLOCATOR_H @@ -40,89 +40,89 @@ Author: Peter Boyle #include #endif -namespace Grid { +NAMESPACE_BEGIN(Grid); - class PointerCache { - private: +class PointerCache { +private: - static const int Ncache=8; - static int victim; + static const int Ncache=8; + static int victim; - typedef struct { - void *address; - size_t bytes; - int valid; - } PointerCacheEntry; + typedef struct { + void *address; + size_t bytes; + int valid; + } PointerCacheEntry; - static PointerCacheEntry Entries[Ncache]; + static PointerCacheEntry Entries[Ncache]; - public: +public: - static void *Insert(void *ptr,size_t bytes) ; - static void *Lookup(size_t bytes) ; + static void *Insert(void *ptr,size_t bytes) ; + static void *Lookup(size_t bytes) ; - }; +}; - std::string sizeString(size_t bytes); +std::string sizeString(size_t bytes); - struct MemoryStats - { - size_t totalAllocated{0}, maxAllocated{0}, - currentlyAllocated{0}, totalFreed{0}; - }; +struct MemoryStats +{ + size_t totalAllocated{0}, maxAllocated{0}, + currentlyAllocated{0}, totalFreed{0}; +}; - class MemoryProfiler - { - public: - static MemoryStats *stats; - static bool debug; - }; +class MemoryProfiler +{ +public: + static MemoryStats *stats; + static bool debug; +}; - #define memString(bytes) std::to_string(bytes) + " (" + sizeString(bytes) + ")" - #define profilerDebugPrint \ - if (MemoryProfiler::stats)\ - {\ - auto s = MemoryProfiler::stats;\ - std::cout << GridLogDebug << "[Memory debug] Stats " << MemoryProfiler::stats << std::endl;\ - std::cout << GridLogDebug << "[Memory debug] total : " << memString(s->totalAllocated) \ - << std::endl;\ - std::cout << GridLogDebug << "[Memory debug] max : " << memString(s->maxAllocated) \ - << std::endl;\ - std::cout << GridLogDebug << "[Memory debug] current: " << memString(s->currentlyAllocated) \ - << std::endl;\ - std::cout << GridLogDebug << "[Memory debug] freed : " << memString(s->totalFreed) \ - << std::endl;\ - } +#define memString(bytes) std::to_string(bytes) + " (" + sizeString(bytes) + ")" +#define profilerDebugPrint \ + if (MemoryProfiler::stats) \ + { \ + auto s = MemoryProfiler::stats; \ + std::cout << GridLogDebug << "[Memory debug] Stats " << MemoryProfiler::stats << std::endl; \ + std::cout << GridLogDebug << "[Memory debug] total : " << memString(s->totalAllocated) \ + << std::endl; \ + std::cout << GridLogDebug << "[Memory debug] max : " << memString(s->maxAllocated) \ + << std::endl; \ + std::cout << GridLogDebug << "[Memory debug] current: " << memString(s->currentlyAllocated) \ + << std::endl; \ + std::cout << GridLogDebug << "[Memory debug] freed : " << memString(s->totalFreed) \ + << std::endl; \ + } - #define profilerAllocate(bytes)\ - if (MemoryProfiler::stats)\ - {\ - auto s = MemoryProfiler::stats;\ - s->totalAllocated += (bytes);\ - s->currentlyAllocated += (bytes);\ - s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated);\ - }\ - if (MemoryProfiler::debug)\ - {\ - std::cout << GridLogDebug << "[Memory debug] allocating " << memString(bytes) << std::endl;\ - profilerDebugPrint;\ - } +#define profilerAllocate(bytes) \ + if (MemoryProfiler::stats) \ + { \ + auto s = MemoryProfiler::stats; \ + s->totalAllocated += (bytes); \ + s->currentlyAllocated += (bytes); \ + s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated); \ + } \ + if (MemoryProfiler::debug) \ + { \ + std::cout << GridLogDebug << "[Memory debug] allocating " << memString(bytes) << std::endl; \ + profilerDebugPrint; \ + } - #define profilerFree(bytes)\ - if (MemoryProfiler::stats)\ - {\ - auto s = MemoryProfiler::stats;\ - s->totalFreed += (bytes);\ - s->currentlyAllocated -= (bytes);\ - }\ - if (MemoryProfiler::debug)\ - {\ - std::cout << GridLogDebug << "[Memory debug] freeing " << memString(bytes) << std::endl;\ - profilerDebugPrint;\ - } +#define profilerFree(bytes) \ + if (MemoryProfiler::stats) \ + { \ + auto s = MemoryProfiler::stats; \ + s->totalFreed += (bytes); \ + s->currentlyAllocated -= (bytes); \ + } \ + if (MemoryProfiler::debug) \ + { \ + std::cout << GridLogDebug << "[Memory debug] freeing " << memString(bytes) << std::endl; \ + profilerDebugPrint; \ + } - void check_huge_pages(void *Buf,uint64_t BYTES); +void check_huge_pages(void *Buf,uint64_t BYTES); //////////////////////////////////////////////////////////////////// // A lattice of something, but assume the something is SIMDized. @@ -159,7 +159,7 @@ public: ////////////////// // Hack 2MB align; could make option probably doesn't need configurability ////////////////// -//define GRID_ALLOC_ALIGN (128) + //define GRID_ALLOC_ALIGN (128) #define GRID_ALLOC_ALIGN (2*1024*1024) #ifdef HAVE_MM_MALLOC_H if ( ptr == (_Tp *) NULL ) ptr = (_Tp *) _mm_malloc(bytes,GRID_ALLOC_ALIGN); @@ -205,8 +205,8 @@ template inline bool operator!=(const alignedAllocator<_Tp>&, con #ifdef GRID_COMMS_SHMEM extern "C" { #include -extern void * shmem_align(size_t, size_t); -extern void shmem_free(void *); + extern void * shmem_align(size_t, size_t); + extern void shmem_free(void *); } #define PARANOID_SYMMETRIC_HEAP #endif @@ -276,7 +276,7 @@ public: #endif uint8_t *cp = (uint8_t *)ptr; if ( ptr ) { - // One touch per 4k page, static OMP loop to catch same loop order + // One touch per 4k page, static OMP loop to catch same loop order #pragma omp parallel for schedule(static) for(size_type n=0;n using Vector = std::vector >; template using commVector = std::vector >; template using Matrix = std::vector > >; -}; // namespace Grid +NAMESPACE_END(Grid); + #endif