Permalink
Browse files

some code cosmetics and additional cleanup

  • Loading branch information...
1 parent fdb6693 commit 31557628235cf077c0568237059463e4fbb7cd1c @stamatak committed Sep 30, 2012
Showing with 24 additions and 41 deletions.
  1. +5 −6 examl/evaluateGenericSpecial.c
  2. +10 −19 examl/makenewzGenericSpecial.c
  3. +2 −5 examl/models.c
  4. +6 −9 examl/optimizeModel.c
  5. +1 −2 examl/searchAlgo.c
@@ -745,12 +745,11 @@ void evaluateGeneric (tree *tr, nodeptr p, boolean fullTraversal)
MPI_Bcast(recv, tr->NumberOfModels, MPI_DOUBLE, 0, MPI_COMM_WORLD);
#endif
- for(model = 0; model < tr->NumberOfModels; model++)
- {
- tr->perPartitionLH[model] = recv[model];
- result += recv[model];
- }
-
+ memcpy(tr->perPartitionLH, recv, tr->NumberOfModels * sizeof(double));
+
+ for(model = 0; model < tr->NumberOfModels; model++)
+ result += tr->perPartitionLH[model];
+
free(recv);
}
@@ -852,7 +852,7 @@ void execCore(tree *tr, volatile double *_dlnLdlz, volatile double *_d2lnLdlz2)
static void topLevelMakenewz(tree *tr, double *z0, int _maxiter, double *result)
{
double z[NUM_BRANCHES], zprev[NUM_BRANCHES], zstep[NUM_BRANCHES];
- volatile double dlnLdlz[NUM_BRANCHES], d2lnLdlz2[NUM_BRANCHES];
+ double dlnLdlz[NUM_BRANCHES], d2lnLdlz2[NUM_BRANCHES];
int i, maxiter[NUM_BRANCHES], model;
boolean firstIteration = TRUE;
boolean outerConverged[NUM_BRANCHES];
@@ -952,31 +952,22 @@ static void topLevelMakenewz(tree *tr, double *z0, int _maxiter, double *result)
{
double
*send = (double *)malloc(sizeof(double) * tr->numBranches * 2),
- *recv = (double *)malloc(sizeof(double) * tr->numBranches * 2);
-
- int
- model;
+ *recv = (double *)malloc(sizeof(double) * tr->numBranches * 2);
- for(model = 0; model < tr->numBranches; model++)
- {
- send[model * 2 + 0] = dlnLdlz[model];
- send[model * 2 + 1] = d2lnLdlz2[model];
- }
+ memcpy(&send[0], dlnLdlz, sizeof(double) * tr->numBranches);
+ memcpy(&send[tr->numBranches], d2lnLdlz2, sizeof(double) * tr->numBranches);
#ifdef _USE_ALLREDUCE
/* the MPI_Allreduce implementation is apparently sometimes not deterministic */
MPI_Allreduce(send, recv, tr->numBranches * 2, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
#else
MPI_Reduce(send, recv, tr->numBranches * 2, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
- MPI_Bcast(recv, tr->numBranches * 2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
-#endif
-
- for(model = 0; model < tr->numBranches; model++)
- {
- dlnLdlz[model] = recv[model * 2 + 0];
- d2lnLdlz2[model] = recv[model * 2 + 1];
- }
+ MPI_Bcast(recv, tr->numBranches * 2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
+#endif
+
+ memcpy(dlnLdlz, &recv[0], sizeof(double) * tr->numBranches);
+ memcpy(d2lnLdlz2, &recv[tr->numBranches], sizeof(double) * tr->numBranches);
free(send);
free(recv);
@@ -996,7 +987,7 @@ static void topLevelMakenewz(tree *tr, double *z0, int _maxiter, double *result)
}
}
- /* do the standard NR step to obrain the next value, depending on the state for eahc partition */
+ /* do the standard NR step to obrain the next value, depending on the state for each partition */
for(i = 0; i < tr->numBranches; i++)
{
View
@@ -3833,12 +3833,9 @@ void initModel(tree *tr, double **empiricalFrequencies)
tr->partitionData[model].alpha = 1.0;
if(tr->partitionData[model].protModels == AUTO)
tr->partitionData[model].autoProtModels = WAG; /* initialize by WAG per default */
-
-
-#ifndef _LOCAL_DISCRETIZATION
+
initReversibleGTR(tr, model);
- makeGammaCats(tr->partitionData[model].alpha, tr->partitionData[model].gammaRates, 4, tr->useMedian);
-#endif
+ makeGammaCats(tr->partitionData[model].alpha, tr->partitionData[model].gammaRates, 4, tr->useMedian);
}
View
@@ -962,9 +962,8 @@ static void optAlpha(tree *tr, double modelEpsilon, linkageList *ll)
for(k = 0; k < ll->ld[i].partitions; k++)
{
tr->partitionData[ll->ld[i].partitionList[k]].alpha = startAlpha[i];
-#ifndef _LOCAL_DISCRETIZATION
- makeGammaCats(tr->partitionData[ll->ld[i].partitionList[k]].alpha, tr->partitionData[ll->ld[i].partitionList[k]].gammaRates, 4, tr->useMedian);
-#endif
+
+ makeGammaCats(tr->partitionData[ll->ld[i].partitionList[k]].alpha, tr->partitionData[ll->ld[i].partitionList[k]].gammaRates, 4, tr->useMedian);
}
}
@@ -1094,9 +1093,8 @@ static void optRates(tree *tr, double modelEpsilon, linkageList *ll, int numberO
{
int index = ll->ld[k].partitionList[j];
tr->partitionData[index].substRates[i] = startRates[pos * numberOfRates + i];
-#ifndef _LOCAL_DISCRETIZATION
+
initReversibleGTR(tr, index);
-#endif
}
}
@@ -2837,9 +2835,8 @@ static void autoProtein(tree *tr)
if(tr->partitionData[model].protModels == AUTO)
{
tr->partitionData[model].autoProtModels = i;
-#ifndef _LOCAL_DISCRETIZATION
+
initReversibleGTR(tr, model);
-#endif
}
}
@@ -2870,9 +2867,9 @@ static void autoProtein(tree *tr)
if(tr->partitionData[model].protModels == AUTO)
{
tr->partitionData[model].autoProtModels = bestIndex[model];
-#ifndef _LOCAL_DISCRETIZATION
+
initReversibleGTR(tr, model);
-#endif
+
printBothOpen("Partition: %d best-scoring AA model: %s likelihood %f\n", model, protModels[tr->partitionData[model].autoProtModels], bestScores[model]);
}
}
View
@@ -1307,9 +1307,8 @@ static void readCheckpoint(tree *tr)
myfread(tr->partitionData[model].tipVector, sizeof(double), pLengths[dataType].tipVectorLength, f);
myfread(tr->partitionData[model].substRates, sizeof(double), pLengths[dataType].substRatesLength, f);
myfread(&(tr->partitionData[model].alpha), sizeof(double), 1, f);
-#ifndef _LOCAL_DISCRETIZATION
+
makeGammaCats(tr->partitionData[model].alpha, tr->partitionData[model].gammaRates, 4, tr->useMedian);
-#endif
}

0 comments on commit 3155762

Please sign in to comment.