Skip to content

Performance and Correctness Improvements #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed data/bpcomp
Binary file not shown.
Binary file removed data/cvrep
Binary file not shown.
Binary file removed data/pb_mpi
Binary file not shown.
Binary file removed data/readpb_mpi
Binary file not shown.
Binary file removed data/tracecomp
Binary file not shown.
77 changes: 39 additions & 38 deletions sources/BipartitionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ along with PhyloBayes. If not, see <http://www.gnu.org/licenses/>.

**********************/

#include <vector>
#include "phylo.h"

// ---------------------------------------------------------------------------------
Expand Down Expand Up @@ -57,7 +58,7 @@ double BPCompare(string* ChainName, int P, string reftreename, int burnin, int e
}
}
BipartitionList** bplist = new BipartitionList*[P];
TaxaParameters* taxaparam = 0;
TaxaParameters* taxaparam = 0;
BipartitionList* refbplist = 0;

if (verbose) {
Expand Down Expand Up @@ -141,13 +142,14 @@ double BPCompare(string* ChainName, int P, string reftreename, int burnin, int e

int bpsize = mergedbplist->GetSize();

double diff[bpsize];
double refdiff[bpsize];
double prob[Q][bpsize];
double length[Q][bpsize];
double meanprob[bpsize];
double refprob[bpsize];
double reflength[bpsize];
vector<double> diff(bpsize);
vector<double> refdiff(bpsize);
vector<vector<double> > prob(Q, vector<double>(bpsize));
vector<vector<double> > length(Q, vector<double>(bpsize));
vector<double> meanprob(bpsize);
vector<double> refprob(bpsize);
vector<double> reflength(bpsize);

for (int k=0; k<bpsize; k++) {
meanprob[k] = 0;
refprob[k] = 0;
Expand Down Expand Up @@ -222,7 +224,7 @@ double BPCompare(string* ChainName, int P, string reftreename, int burnin, int e
meanprob[k] = mean;
}
meandiff /= weight;

if (! bench) {
osp << "total number of bp : " << bpsize << '\n';
osp << "cutoff : " << cutoff << '\n';
Expand Down Expand Up @@ -312,7 +314,7 @@ double BPCompare(string* ChainName, int P, string reftreename, int burnin, int e
}
meandiff /= weight;
// meandiff = sqrt(meandiff);

if (! bench) {
osp << "total number of bp : " << bpsize << '\n';
osp << "cutoff : " << cutoff << '\n';
Expand Down Expand Up @@ -408,7 +410,7 @@ double BPCompare(string* ChainName, int P, string reftreename, int burnin, int e
cout << "meandiff : " << meandiff << '\n';
cout << '\n';
}

ofstream sos((OutFile + ".bpdiff").c_str());
sos << '\n';
sos << "maxdiff : " << maxdiff << '\n';
Expand Down Expand Up @@ -475,7 +477,7 @@ void BipartitionList::BasicAllocation() {
mAllocatedSize = basicsize;
mSize = 0;
mWeight = 0;

mCompatibleArray = 0;

mWeightArray = new double[mAllocatedSize];
Expand Down Expand Up @@ -511,7 +513,7 @@ BipartitionList::BipartitionList(TaxaParameters* inParam) {
BipartitionList::BipartitionList(string filename, int burnin, int every, int until, double cutoff, bool rootonly) {

BasicAllocation();

if (burnin <0) {
if (burnin == -1) {
burnin = -5;
Expand All @@ -525,16 +527,16 @@ BipartitionList::BipartitionList(string filename, int burnin, int every, int unt
}
burnin = - n / burnin;
}

ifstream is(filename.c_str());
PBTree tree;
PBTree tree;
int size = 0;
Ntree = 0;
if (! tree.ReadFromStream(is)) {
return;
}
size = 1;
mParam = new TaxaParameters(&tree);
mParam = new TaxaParameters(&tree);
int cycle = 0;
if (size > burnin) {
if (rootonly) {
Expand Down Expand Up @@ -635,10 +637,10 @@ int BipartitionList::IsEqualTo(BipartitionList* comp) {


void BipartitionList::Prune(PBTree* inTree) {

if (inTree->IsDichotomous()) {
cerr << "in BipartitionList::Prune : warning, tree is dichotomous\n";
}
}
Flush();
inTree->GetRoot()->BipartitionPruning(this);
Modulo();
Expand All @@ -647,7 +649,7 @@ void BipartitionList::Prune(PBTree* inTree) {


void BipartitionList::PruneWithSupports(PBTree* inTree) {

Flush();
inTree->GetRoot()->BipartitionPruningWithSupports(this);
Modulo();
Expand All @@ -664,7 +666,7 @@ BipartitionList::BipartitionList( TreeList* inTreeList, double* weightarray, dou

mParam = inTreeList->GetParameters();
BasicAllocation();

for (int i=0; i<inTreeList->GetSize(); i++) {
BipartitionList tempList(mParam);
inTreeList->GetTree(i)->Trichotomise();
Expand Down Expand Up @@ -694,7 +696,7 @@ BipartitionList::~BipartitionList() {
delete[] mCompatibleArray;
}


// ---------------------------------------------------------------------------------
// Sort(); // reverse order !
// ---------------------------------------------------------------------------------
Expand Down Expand Up @@ -723,12 +725,12 @@ void BipartitionList::Sort() {
}
}
}

// ---------------------------------------------------------------------------------
// GetHisto();
// ---------------------------------------------------------------------------------


void BipartitionList::GetHisto(int* histo, int ncat) {
for (int i=0; i<ncat; i++) {
histo[i] = 0;
Expand All @@ -739,12 +741,12 @@ void BipartitionList::GetHisto(int* histo, int ncat) {
histo[k] ++;
}
}

// ---------------------------------------------------------------------------------
// RegisterWith();
// ---------------------------------------------------------------------------------


int BipartitionList::RegisterWith(TaxaParameters* inParam) {

int ok = 1;
Expand All @@ -770,7 +772,7 @@ int BipartitionList::RegisterWith(TaxaParameters* inParam) {

for (int i=0; i<mSize; i++) {
mBipartitionArray[i]->PermutTaxa(permut);
}
}
delete[] permut;
}
return ok;
Expand All @@ -781,7 +783,7 @@ int BipartitionList::RegisterWith(TaxaParameters* inParam) {
// ---------------------------------------------------------------------------------

void BipartitionList::Truncate(double cutoff) {

int i=0;
while ( (i<mSize) && (GetProb(i) >= cutoff)) {
i++;
Expand All @@ -802,21 +804,21 @@ void BipartitionList::Flush(){
mSize = 0;
mWeight = 0;
}


// ---------------------------------------------------------------------------------
// Pop()
// ---------------------------------------------------------------------------------

void BipartitionList::Pop(){

if (! mSize) {
cerr << "error in BipartitionList : pop called on list of size 0\n";
exit(1);
}
mSize--;
}


// ---------------------------------------------------------------------------------
// Modulo
Expand Down Expand Up @@ -890,20 +892,20 @@ void BipartitionList::Suppress(const Bipartition& bp) {
mBipartitionArray[i]->Suppress(bp);
}
}


// ---------------------------------------------------------------------------------
// GetIndex()
// ---------------------------------------------------------------------------------

int BipartitionList::GetIndex(const Bipartition& inPartition){

int i=0;
while ( (i<mSize) && (*mBipartitionArray[i] != inPartition)) {
i++;
}
if (i == mSize) {
i = -1;
i = -1;
}
return i;
}
Expand Down Expand Up @@ -1015,7 +1017,7 @@ void BipartitionList::Insert(Bipartition inPartition, double weight, double leng
exit(1);
}
}

mSize++;
if (mSize > mAllocatedSize) {
Reallocate();
Expand Down Expand Up @@ -1077,7 +1079,7 @@ void BipartitionList::WriteToStream(ostream& os, int header, int verbose) {
if (header) {
mParam->WriteToStream(os);
}
os << "BipartitionList\n";
os << "BipartitionList\n";
os << "Size " << mSize << '\n';
os << "Weight " << mWeight << '\n';
os << '\n';
Expand Down Expand Up @@ -1113,12 +1115,12 @@ void BipartitionList::ReadFromStream(istream& is) {
mParam->ReadFromStream(is);
}
else if (temp == "BipartitionList") {

int size;
is >> temp >> size >> temp >> mWeight;
cerr << size << '\n';
mSize = 0;

for (int i=0; i<size; i++) {
double prob;
double length;
Expand All @@ -1136,4 +1138,3 @@ void BipartitionList::ReadFromStream(istream& is) {
is >> temp;
}
}

4 changes: 2 additions & 2 deletions sources/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC=mpic++
CPPFLAGS= -w -O3 -c
LDFLAGS= -O3
CPPFLAGS= -w -O3 -flto -c
LDFLAGS= -O3 -flto
SRCS= TaxonSet.cpp Tree.cpp Random.cpp SequenceAlignment.cpp CodonSequenceAlignment.cpp \
StateSpace.cpp CodonStateSpace.cpp ZippedSequenceAlignment.cpp SubMatrix.cpp \
GTRSubMatrix.cpp CodonSubMatrix.cpp linalg.cpp Chrono.cpp BranchProcess.cpp \
Expand Down