void clear (u_int64_t toErase) { u_int64_t totalPhysical = System::info().getMemoryPhysicalTotal(); if (toErase == 0) { toErase = totalPhysical; } size_t blockSize = 32*1024; u_int32_t nbIter = toErase/blockSize; vector<void*> buffers (nbIter, 0); SubjectIterator<u_int32_t> it (new Range<u_int32_t>::Iterator (1, nbIter), nbIter/100); it.addObserver (new ProgressTimer (nbIter, "clear cache")); size_t i=0; for (it.first(); !it.isDone(); it.next()) { void* b = calloc (blockSize, 1); if (b != 0) { buffers[i]=b; i++; } } //#if 0 // size_t j=0; // for (size_t k=0; k<nbIter; k++) // { // void* b = buffers[k]; // if (b != 0) { free (b); j++; } // } //#endif }
int main (int argc, char* argv[]) { // We declare a STL list with some values. int values[] = {1,2,3,5,8,13,21,34}; int valuesLen = sizeof(values)/sizeof(values[0]); std::list<int> l (values, values + valuesLen); // We create an iterator on the list. ListIterator<int>* itList = new ListIterator<int> (l); // We declare an iterator that will send progress status every 3 iterations. // Note that it refers a ListIterator instance given as constructor parameter. SubjectIterator<int> itNotif (itList, 3); // We create some listener to be notified about progress and attach it to the iterator. itNotif.addObserver (new ProgressFunctor ()); // We iterate the truncated list for (itNotif.first(); !itNotif.isDone(); itNotif.next()) { // We can do something in the loop, but there is nothing here about progress management } }
int main (int argc, char* argv[]) { if (argc < 2) { std::cerr << "you must provide a bank." << std::endl; return EXIT_FAILURE; } // We define a try/catch block in case some method fails try { // We declare an input Bank and use it locally IBank* inputBank = Bank::open (argv[1]); LOCAL (inputBank); // Note also that we have to parameterize the SubjectIterator by the kind of iterated // items (Sequence) and the processing that has to be done on each iteration (ProgressFunctor). SubjectIterator<Sequence> iter (inputBank->iterator(), 10); // We create some listener to be notified every 10 iterations and attach it to the iterator. iter.addObserver (new ProgressFunctor()); // We loop over sequences. for (iter.first(); !iter.isDone(); iter.next()) { // Note that we do nothing inside the sequence iterating loop about the progression management. // In other words, we don't "pollute" the code inside this loop by presentation concerns and // we can therefore focus on the job to be done on the iterated sequences. } } catch (Exception& e) { std::cerr << "EXCEPTION: " << e.getMessage() << std::endl; } }
void MPHFAlgorithm<span,Abundance_t,NodeState_t>::populate () { size_t nb_iterated = 0; size_t n = _abundanceMap->size(); _nb_abundances_above_precision = 0; /** We need a progress object. */ tools::dp::IteratorListener* delegate = createIteratorListener(_solidCounts->getNbItems(),messages[3]); LOCAL (delegate); setProgress (new ProgressCustom(delegate)); SubjectIterator<Count>* itKmers = new SubjectIterator<Count> (_solidCounts->iterator(), _solidCounts->getNbItems()/100); itKmers->addObserver (_progress); LOCAL (itKmers); // TODO parallize that std::vector<int> & _abundanceDiscretization = _abundanceMap->_abundanceDiscretization ; int max_abundance_discrete = _abundanceDiscretization[_abundanceDiscretization.size()-2]; // set counts and at the same time, test the mphf for (itKmers->first(); !itKmers->isDone(); itKmers->next()) { //cout << "kmer: " << itKmers->item().value.toString(21) << std::endl; /** We get the hash code of the current item. */ typename AbundanceMap::Hash::Code h = _abundanceMap->getCode (itKmers->item().value); /** Little check. */ if (h >= n) { throw Exception ("MPHF check: value out of bounds"); } /** We get the abundance of the current kmer. */ int abundance = itKmers->item().abundance; if (abundance > max_abundance_discrete) { _nb_abundances_above_precision++; abundance = max_abundance_discrete; } //get first cell strictly greater than abundance std::vector<int>::iterator up = std::upper_bound(_abundanceDiscretization.begin(), _abundanceDiscretization.end(), abundance); up--; // get previous cell int idx = up- _abundanceDiscretization.begin() ; /** We set the abundance of the current kmer. */ _abundanceMap->at (h) = idx; nb_iterated ++; } if (nb_iterated != n && n > 3) { throw Exception ("ERROR during abundance population: itKmers iterated over %d/%d kmers only", nb_iterated, n); } #if 1 // you know what? let's always test if the MPHF does not have collisions, it won't hurt. check (); #endif /** We gather some statistics. */ getInfo()->add (1, "stats"); getInfo()->add (2, "nb_keys", "%ld", _abundanceMap->size()); getInfo()->add (2, "data_size", "%ld", _dataSize); getInfo()->add (2, "bits_per_key", "%.3f", (float)(_dataSize*8)/(float)_abundanceMap->size()); getInfo()->add (2, "prec", "%d", MAX_ABUNDANCE); getInfo()->add (2, "nb_abund_above_prec", "%d", _nb_abundances_above_precision); getInfo()->add (1, getTimeInfo().getProperties("time")); }