Skip to content

Commit

Permalink
Relocating the pragma instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Sep 28, 2023
1 parent 8481f54 commit ce6d98e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 63 deletions.
12 changes: 4 additions & 8 deletions include/barry/model-bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,32 +240,28 @@ class Model {
double likelihood(
const std::vector<double> & params,
const size_t & i,
bool as_log = false,
BARRY_NCORES_ARG(=2)
bool as_log = false
);

double likelihood(
const std::vector<double> & params,
const Array_Type & Array_,
int i = -1,
bool as_log = false,
BARRY_NCORES_ARG(=2)
bool as_log = false
);

double likelihood(
const std::vector<double> & params,
const std::vector<double> & target_,
const size_t & i,
bool as_log = false,
BARRY_NCORES_ARG(=2)
bool as_log = false
);

double likelihood(
const std::vector<double> & params,
const double * target_,
const size_t & i,
bool as_log = false,
BARRY_NCORES_ARG(=2)
bool as_log = false
);

double likelihood_total(
Expand Down
45 changes: 12 additions & 33 deletions include/barry/model-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ inline double update_normalizing_constant(

std::vector< double > resv(n, 0.0);

#if defined(__OPENMP) || defined(_OPENMP)
#pragma omp parallel for shared(resv) firstprivate(params, n, k)
#elif defined(__GNUC__) && !defined(__clang__)
#pragma GCC ivdep
#endif
// #if defined(__OPENMP) || defined(_OPENMP)
// #pragma omp parallel for shared(resv) firstprivate(params, n, k)
// #elif defined(__GNUC__) && !defined(__clang__)
// #pragma GCC ivdep
// #endif
for (size_t j = 0u; j < (k - 1u); ++j)
{

Expand Down Expand Up @@ -600,13 +600,8 @@ template <typename Array_Type, typename Data_Counter_Type, typename Data_Rule_Ty
inline double Model<Array_Type,Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_Type>::likelihood(
const std::vector<double> & params,
const size_t & i,
bool as_log,
BARRY_NCORES_ARG()
bool as_log
) {

#if defined(__OPENMP) || defined(_OPENMP)
omp_set_num_threads(ncores);
#endif

// Checking if the index exists
if (i >= arrays2support.size())
Expand Down Expand Up @@ -650,13 +645,8 @@ inline double Model<Array_Type,Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_
const std::vector<double> & params,
const Array_Type & Array_,
int i,
bool as_log,
BARRY_NCORES_ARG()
bool as_log
) {

#if defined(__OPENMP) || defined(_OPENMP)
omp_set_num_threads(ncores);
#endif

// Key of the support set to use
int loc;
Expand Down Expand Up @@ -736,13 +726,8 @@ inline double Model<Array_Type,Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_
const std::vector<double> & params,
const std::vector<double> & target_,
const size_t & i,
bool as_log,
BARRY_NCORES_ARG()
bool as_log
) {

#if defined(__OPENMP) || defined(_OPENMP)
omp_set_num_threads(ncores);
#endif

// Checking if the index exists
if (i >= arrays2support.size())
Expand Down Expand Up @@ -804,13 +789,8 @@ inline double Model<Array_Type,Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_
const std::vector<double> & params,
const double * target_,
const size_t & i,
bool as_log,
BARRY_NCORES_ARG()
bool as_log
) {

#if defined(__OPENMP) || defined(_OPENMP)
omp_set_num_threads(ncores);
#endif

// Checking if the index exists
if (i >= arrays2support.size())
Expand Down Expand Up @@ -879,13 +859,12 @@ inline double Model<Array_Type,Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_
bool as_log,
BARRY_NCORES_ARG()
) {

#if defined(__OPENMP) || defined(_OPENMP)
omp_set_num_threads(ncores);
#endif

size_t params_last_size = params_last.size();

// #if defined(__OPENMP) || defined(_OPENMP)
// #pragma omp parallel for num_threads(ncores)
// #endif
for (size_t i = 0u; i < params_last_size; ++i)
{

Expand Down
51 changes: 29 additions & 22 deletions include/barry/models/geese/geese-meat-likelihood.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ inline double Geese::likelihood(

double ll = 0.0;

Node * n_off;

// Following the prunning sequence
std::vector< size_t > * preseq;

Expand Down Expand Up @@ -60,38 +58,47 @@ inline double Geese::likelihood(
{

// Starting the prob
double totprob = 0.0;
size_t array_id = node.narray[s];

// Retrieving the sets of arrays
const std::vector< PhyloArray > * psets =
model->get_pset(node.narray[s]);
const std::vector< PhyloArray > & psets =
*(model->get_pset(array_id));

const std::vector<double> * psets_stats =
model->get_pset_stats(node.narray[s]);
const std::vector<double> & psets_stats =
*(model->get_pset_stats(array_id));

std::vector< std::vector< size_t > > & locations = pset_loc[
arrays2support->operator[](node.narray[s])
arrays2support->operator[](array_id)
];

// Summation over all possible values of X
const auto & node_offspring = node.offspring;
std::vector< double > totprob_n(psets.size(), 0.0);
size_t nstate = 0u;
size_t narray = 0u;
for (auto x = psets->begin(); x != psets->end(); ++x)
#if defined(_OPENMP) || defined(__OPENMP)
#pragma omp parallel for num_threads(ncores) \
shared(locations, psets, psets_stats, totprob_n) \
firstprivate(nfunctions, par0, node_offspring, array_id)
#endif
for (size_t n = 0u; n < psets.size(); ++n) // x = psets->begin(); x != psets->end(); ++x)
{

if (!x->is_dense())
// Retrieving the pset
const auto & x = psets[n];

if (!x.is_dense())
throw std::logic_error("This is only supported for dense arrays.");

std::vector< size_t > & location_x = locations[narray++];
const std::vector< size_t > & location_x = locations[n];

// Extracting the possible values of each offspring
double off_mult = 1.0;

for (auto o = 0u; o < x->ncol(); ++o)
for (auto o = 0u; o < x.ncol(); ++o)
{

// Setting the node
n_off = node.offspring[o];
const Node * n_off = node_offspring[o];

// In the case that the offspring is a leaf, then we need to
// check whether the state makes sense.
Expand All @@ -102,7 +109,7 @@ inline double Geese::likelihood(
if (n_off->annotations[f] != 9u)
{

if (x->operator()(f, o) != n_off->annotations[f])
if (x(f, o) != n_off->annotations[f])
{

off_mult = -1.0;
Expand All @@ -123,7 +130,7 @@ inline double Geese::likelihood(
}

// Retrieving the location to the respective set of probabilities
off_mult *= node.offspring[o]->subtree_prob[location_x[o]];
off_mult *= n_off->subtree_prob[location_x[o]];

}

Expand All @@ -140,7 +147,7 @@ inline double Geese::likelihood(
std::vector< double > temp_stats;
temp_stats.reserve(par0.size());
for (auto p = 0u; p < par0.size(); ++p)
temp_stats.push_back(psets_stats->operator[](par0.size() * nstate + p));
temp_stats.push_back(psets_stats[par0.size() * nstate + p]);

nstate++;

Expand All @@ -149,9 +156,8 @@ inline double Geese::likelihood(
off_mult *= model->likelihood(
par0,
temp_stats,
node.narray[s],
false,
ncores
array_id,
false
);
} catch (std::exception & e) {

Expand All @@ -171,12 +177,13 @@ inline double Geese::likelihood(
}

// Adding to the total probabilities
totprob += off_mult;
totprob_n[n] = off_mult;

}

// Setting the probability at the node
node.subtree_prob[s] = totprob;
for (size_t n = 0u; n < psets.size(); ++n)
node.subtree_prob[s] += totprob_n[n];

}

Expand Down

0 comments on commit ce6d98e

Please sign in to comment.