36 #ifndef __EMPQ_ADAPTIVE_IMPL_H
37 #define __EMPQ_ADAPTIVE_IMPL_H
58 template <
class T,
class Key>
62 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: starting in-memory pqueue" << endl;
69 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: desired memory: "
70 << ((float)inMem / (1 << 20)) <<
"MB" << endl;
77 template <
class T,
class Key>
81 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: starting in-memory pqueue" << endl;
88 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: available memory: "
89 << ((float)mm_avail / (1 << 20)) <<
"MB" << endl;
97 template <
class T,
class Key>
101 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: desired memory: "
102 << ((float)initMem / (1 << 20)) <<
"MB" << endl;
115 cerr <<
"EMPQueueAdaptive constr: failing to get stream_usage\n";
120 unsigned short max_nbuf = 2;
121 unsigned int buf_arity = initMem / (2 * sz_stream);
126 2 * sz_stream + max_nbuf * sz_stream;
131 <<
" buf_arity: " << buf_arity
132 <<
" mm_overhead: " << mm_overhead
133 <<
" mm_avail: " << initMem <<
".\n";
135 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: memory overhead set to "
136 << ((float)mm_overhead / (1 << 20)) <<
"MB" << endl;
137 if (mm_overhead > initMem) {
138 cerr <<
"overhead bigger than available memory (" << initMem <<
"); "
139 <<
"increase -m and try again\n";
142 initMem -= mm_overhead;
145 long pqsize = initMem /
sizeof(T);
146 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: pqsize set to " << pqsize << endl;
154 template <
class T,
class Key>
172 template <
class T,
class Key>
179 m = im->get_maxsize();
193 template <
class T,
class Key>
207 assert(dim->empty() == em->is_empty());
215 template <
class T,
class Key>
218 cerr <<
"EMPQueueAdaptive::is_full(): sorry not implemented\n";
224 template <
class T,
class Key>
243 cerr <<
"------------------------------" << endl;
245 cerr <<
"------------------------------" << endl;
247 cerr <<
"------------------------------" << endl;
248 cerr <<
"tmp=" << tmp << endl;
249 cerr <<
"elt=" << elt << endl;
250 cerr <<
"------------------------------" << endl;
251 dim->destructiveVerify();
261 template <
class T,
class Key>
277 template <
class T,
class Key>
293 template <
class T,
class Key>
301 v = im->extract_all_min(elt);
305 v = em->extract_all_min(elt);
308 v1 = dim->extract_all_min(tmp);
309 v = em->extract_all_min(elt);
310 assert(dim->size() == em->size());
319 template <
class T,
class Key>
342 template <
class T,
class Key>
350 v = im->extract_min(elt);
354 v = em->extract_min(elt);
357 v1 = dim->extract_min(tmp);
358 v = em->extract_min(elt);
361 assert(dim->size() == em->size());
372 template <
class T,
class Key>
393 assert(dim->size() == em->size());
399 template <
class T,
class Key>
422 return (
x < y ? -1 : (
x > y ? 1 : 0));
427 template <
class T,
class Key>
440 <<
"EMPQUEUEADAPTIVE: memory full: "
441 <<
"switching to external-memory pqueue " << endl;
447 unsigned long pqsize = im->size();
450 for (
unsigned long i = 0; i < pqsize / 2; i++) {
451 int z = im->extract_max(
x);
459 cout <<
"written " << pqsize / 2 <<
" elts to stream\n";
463 assert(im->size() == pqsize / 2 + (pqsize % 2));
474 cout <<
"sorted the stream\n";
486 cout <<
"empq initialized from im\n";
496 assert(sizeCheck == size());
AMI_err AMI_sort(AMI_STREAM< T > *instream, AMI_STREAM< T > **outstream, Compare *cmp, int deleteInputStream=0)
static AMI_err main_memory_usage(size_t *usage, MM_stream_usage usage_type=MM_STREAM_USAGE_OVERHEAD)
AMI_err write_item(const T &elt)
bool extract_all_min(T &elt)
bool insert(const T &elt)
static int compare(const T &x, const T &y)
#define assert(condition)
@ MM_STREAM_USAGE_MAXIMUM
size_t getAvailableMemory()