37 #ifndef __EMPQ_ADAPTIVE_IMPL_H 38 #define __EMPQ_ADAPTIVE_IMPL_H 63 template<
class T,
class Key>
66 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: starting in-memory pqueue" 74 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: desired memory: " 75 << ( (float)inMem/ (1<< 20)) <<
"MB" << endl;
83 template<
class T,
class Key>
86 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: starting in-memory pqueue" 94 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: available memory: " 95 << ( (float)mm_avail/ (1<< 20)) <<
"MB" << endl;
106 template<
class T,
class Key>
110 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: desired memory: " 111 << ( (float)initMem/ (1<< 20)) <<
"MB" << endl;
125 cerr <<
"EMPQueueAdaptive constr: failing to get stream_usage\n";
131 unsigned short max_nbuf = 2;
132 unsigned int buf_arity = initMem/(2 * sz_stream);
136 2*sz_stream + max_nbuf*sz_stream;
140 EMPQAD_DEBUG cout <<
"sz_stream: " << sz_stream <<
" buf_arity: " << buf_arity <<
141 " mm_overhead: " << mm_overhead <<
" mm_avail: " << initMem <<
".\n";
145 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: memory overhead set to " 146 << ((float)mm_overhead / (1 << 20)) <<
"MB" << endl;
147 if (mm_overhead > initMem) {
148 cerr <<
"overhead bigger than available memory ("<< initMem <<
"); " 149 <<
"increase -m and try again\n";
152 initMem -= mm_overhead;
156 long pqsize = initMem/
sizeof(T);
157 EMPQAD_DEBUG cout <<
"EMPQUEUEADAPTIVE: pqsize set to " << pqsize << endl;
166 template<
class T,
class Key>
185 template<
class T,
class Key>
192 m = im->get_maxsize();
209 template<
class T,
class Key>
223 assert(dim->empty() == em->is_empty());
232 template<
class T,
class Key>
235 cerr <<
"EMPQueueAdaptive::is_full(): sorry not implemented\n";
242 template<
class T,
class Key>
261 cerr <<
"------------------------------" << endl;
263 cerr <<
"------------------------------" << endl;
265 cerr <<
"------------------------------" << endl;
266 cerr <<
"tmp=" << tmp << endl;
267 cerr <<
"elt=" << elt << endl;
268 cerr <<
"------------------------------" << endl;
269 dim->destructiveVerify();
279 template<
class T,
class Key>
296 template<
class T,
class Key>
312 template<
class T,
class Key>
320 v = im->extract_all_min(elt);
324 v = em->extract_all_min(elt);
327 v1 = dim->extract_all_min(tmp);
328 v = em->extract_all_min(elt);
329 assert(dim->size() == em->size());
338 template<
class T,
class Key>
364 template<
class T,
class Key>
372 v = im->extract_min(elt);
376 v = em->extract_min(elt);
379 v1 = dim->extract_min(tmp);
380 v = em->extract_min(elt);
383 assert(dim->size() == em->size());
397 template<
class T,
class Key>
417 assert(dim->size() == em->size());
423 template<
class T,
class Key>
447 return (x < y ? -1 : (x > y ? 1 : 0));
453 template<
class T,
class Key>
466 <<
"EMPQUEUEADAPTIVE: memory full: " 467 <<
"switching to external-memory pqueue " << endl;
473 unsigned long pqsize = im->size();
476 for (
unsigned long i=0; i< pqsize/2; i++) {
477 int z = im->extract_max(x);
484 <<
" elts to stream\n"; cout.flush(); }
486 assert(im->size() == pqsize/2 + (pqsize % 2));
495 EMPQAD_DEBUG { cout <<
"sorted the stream\n"; cout.flush(); }
503 EMPQAD_DEBUG { cout <<
"empq initialized from im\n"; cout.flush(); }
508 assert(sizeCheck == size());
static int compare(const T &x, const T &y)
static AMI_err main_memory_usage(size_t *usage, MM_stream_usage usage_type=MM_STREAM_USAGE_OVERHEAD)
size_t getAvailableMemory()
AMI_err write_item(const T &elt)
#define assert(condition)
bool insert(const T &elt)
bool extract_all_min(T &elt)
AMI_err AMI_sort(AMI_STREAM< T > *instream, AMI_STREAM< T > **outstream, Compare *cmp, int deleteInputStream=0)