24 unsigned char *unaligned;
27 unsigned char *aligned;
29 size_t bytes_to_alloc;
30 bytes_to_alloc = n_bytes;
31 if ( n_bytes % (32*1024) == 0 ) {
38 unaligned =
new unsigned char[ bytes_to_alloc ];
40 catch( std::bad_alloc ) {
41 QDPIO::cerr <<
"Unable to allocate memory in allocate()" << std::endl;
49#if defined(QDP_DEBUG_MEMORY)
51 FuncInfo_t& info = infostack.top();
55 std::make_pair(aligned, MapVal(unaligned, info.func, info.line, bytes_to_alloc)));
58 InsertRetVal r = the_alignment_map.insert(std::make_pair(aligned, unaligned));
63 QDPIO::cerr <<
"Failed to insert (unaligned,aligned) pair into map" << std::endl;
68 return (
void *)aligned;
75 unsigned char* unaligned;
78 MapT::iterator iter = the_alignment_map.find((
unsigned char*)mem);
79 if( iter != the_alignment_map.end() )
81#if defined(QDP_DEBUG_MEMORY)
83 unaligned = iter->second.unaligned;
86 unaligned = iter->second;
90 the_alignment_map.erase(iter);
96 QDPIO::cerr <<
"Pointer not found in map" << std::endl;
102#if defined(QDP_DEBUG_MEMORY)
110 typedef MapT::const_iterator CI;
112 for( CI j = the_alignment_map.begin();
113 j != the_alignment_map.end(); j++)
115 sum += j->second.bytes;
116 printf(
"mem= 0x%x bytes= %d bytes/site= %d line= %d func= %s\n", j->first,
117 j->second.bytes, j->second.bytes/
Layout::sitesOnNode(), j->second.line, j->second.func.c_str());
119 printf(
"total bytes= %d\n",
sum);
127 infostack.push(FuncInfo_t(func,line));
134 if (infostack.empty())
136 QDPIO::cerr << __func__ <<
": invalid pop" << std::endl;
144 static const char* nowhere =
"nowhere";
150 infostack.push(FuncInfo_t(nowhere,0));
161 typedef MapT::const_iterator CI;
163 for( CI j = the_alignment_map.begin();
164 j != the_alignment_map.end(); j++)
166 printf(
"mem= 0x%lx unaligned= 0x%lx\n", (
unsigned long)j->first,
167 (
unsigned long)j->second);
183 QDPIO::cout <<
"Initializing QDPDefaultAllocator." << std::endl;
void init(size_t PoolSizeinMB)
void free(void *mem)
Free an aligned pointer, which was allocated by us.
void pushFunc(const char *func, int line)
void * allocate(size_t n_bytes, const MemoryPoolHint &mem_pool_hint)
UnaryReturn< C, FnSum >::Type_t sum(const QDPType< T, C > &s1)
OScalar = sum(source).
std::pair< MapT::iterator, bool > InsertRetVal
int sitesOnNode()
Subgrid lattice volume.
bool primaryNode()
Returns whether this is the primary node.
StandardOutputStream cout
StandardOutputStream cerr
Yet another random number generator.
void QDP_abort(int status)
Panic button.
Primary include file for QDP.
#define QDP_ALIGNMENT_SIZE
Default memory allocator for QDP.