Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Fix crash with -mtree
Browse files Browse the repository at this point in the history
  • Loading branch information
bqminh committed Dec 21, 2017
1 parent 08073e9 commit 0d2cc01
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
30 changes: 17 additions & 13 deletions main/phylotesting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,12 +1297,12 @@ string testOneModel(string &model_name, Params &params, Alignment *in_aln,
// iqtree->num_precision = in_tree->num_precision;

// clear all checkpointed information
Checkpoint *newCheckpoint = new Checkpoint;
iqtree->getCheckpoint()->getSubCheckpoint(newCheckpoint, "iqtree");
iqtree->getCheckpoint()->clear();
iqtree->getCheckpoint()->insert(newCheckpoint->begin(), newCheckpoint->end());
delete newCheckpoint;
// Checkpoint *newCheckpoint = new Checkpoint;
// iqtree->getCheckpoint()->getSubCheckpoint(newCheckpoint, "iqtree");
// iqtree->getCheckpoint()->clear();
// iqtree->getCheckpoint()->insert(newCheckpoint->begin(), newCheckpoint->end());
// delete newCheckpoint;

cout << endl << "===> Testing model " << model_name << endl;

if (iqtree->root) {
Expand All @@ -1326,13 +1326,17 @@ string testOneModel(string &model_name, Params &params, Alignment *in_aln,
params.stop_condition = orig_stop_condition;

// clear all checkpointed information
newCheckpoint = new Checkpoint;
iqtree->getCheckpoint()->getSubCheckpoint(newCheckpoint, "iqtree");
iqtree->getCheckpoint()->clear();
iqtree->getCheckpoint()->insert(newCheckpoint->begin(), newCheckpoint->end());
iqtree->getCheckpoint()->putBool("finished", false);
iqtree->getCheckpoint()->dump(true);
delete newCheckpoint;
// newCheckpoint = new Checkpoint;
// iqtree->getCheckpoint()->getSubCheckpoint(newCheckpoint, "iqtree");
// iqtree->getCheckpoint()->clear();
// iqtree->getCheckpoint()->insert(newCheckpoint->begin(), newCheckpoint->end());
// iqtree->getCheckpoint()->putBool("finished", false);
// iqtree->getCheckpoint()->dump(true);
// delete newCheckpoint;

int count = iqtree->getCheckpoint()->eraseKeyPrefix("finished");
cout << count << " finished checkpoint entries erased" << endl;


} else {
//--- FIX TREE TOPOLOGY AND ESTIMATE MODEL PARAMETERS ----//
Expand Down
16 changes: 16 additions & 0 deletions utils/checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ bool Checkpoint::hasKeyPrefix(string key_prefix) {
return false;
}

int Checkpoint::eraseKeyPrefix(string key_prefix) {
int count = 0;
iterator first_it = lower_bound(key_prefix);
iterator i;
for (i = first_it; i != end(); i++) {
if (i->first.compare(0, key_prefix.size(), key_prefix) == 0)
count++;
else
break;

}
if (count)
erase(first_it, i);
return count;
}

/*-------------------------------------------------------------
* series of get function to get value of a key
*-------------------------------------------------------------*/
Expand Down
7 changes: 7 additions & 0 deletions utils/checkpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ class Checkpoint : public map<string, string> {
*/
bool hasKeyPrefix(string key_prefix);

/**
erase all entries with a key prefix
@param key_prefix key prefix
@return number of entries removed
*/
int eraseKeyPrefix(string key_prefix);

/*-------------------------------------------------------------
* series of get function to get value of a key
*-------------------------------------------------------------*/
Expand Down

0 comments on commit 0d2cc01

Please sign in to comment.