Skip to content

Commit

Permalink
Committing clang-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Clang Robot committed Nov 21, 2023
1 parent fe6948b commit 05d6390
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 314 deletions.
22 changes: 12 additions & 10 deletions include/macis/asci/determinant_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ struct ASCISettings {

double pt2_tol = 1e-16;
size_t pt2_reserve_count = 70000000;
bool pt2_prune = false;
bool pt2_precompute_eps = false;
bool pt2_precompute_idx = false;
bool pt2_print_progress = false;
bool pt2_prune = false;
bool pt2_precompute_eps = false;
bool pt2_precompute_idx = false;
bool pt2_print_progress = false;
size_t pt2_bigcon_thresh = 250;

size_t nxtval_bcount_thresh = 1000;
size_t nxtval_bcount_inc = 10;
size_t nxtval_bcount_inc = 10;

bool just_singles = false;
size_t grow_factor = 8;
Expand Down Expand Up @@ -306,15 +306,17 @@ asci_contrib_container<wfn_t<N>> asci_contributions_constraint(

// Atomically get the next task ID and increment for other
// MPI ranks and threads
size_t ntake = ic < asci_settings.nxtval_bcount_thresh ? 1 : asci_settings.nxtval_bcount_inc;
size_t ntake = ic < asci_settings.nxtval_bcount_thresh
? 1
: asci_settings.nxtval_bcount_inc;
ic = nxtval.fetch_and_add(ntake);

// Loop over assigned tasks
const size_t c_end = std::min(ncon_total, ic + ntake);
for(; ic < c_end; ++ic) {
const auto& con = constraints[ic].first;
//printf("[rank %4d tid:%4d] %10lu / %10lu\n", world_rank,
// omp_get_thread_num(), ic, ncon_total);
// printf("[rank %4d tid:%4d] %10lu / %10lu\n", world_rank,
// omp_get_thread_num(), ic, ncon_total);

for(size_t i_alpha = 0, iw = 0; i_alpha < nuniq_alpha; ++i_alpha) {
const auto& alpha_det = uniq_alpha[i_alpha].first;
Expand Down Expand Up @@ -462,8 +464,8 @@ std::vector<wfn_t<N>> asci_search(
logger->info(" MAX_RV_SIZE = {}, JUST_SINGLES = {}",
asci_settings.pair_size_max, asci_settings.just_singles);
logger->info(" CDET_SUM = {:.2e}",
std::accumulate(C.begin(),C.begin() + ncdets, 0.0,
[](auto s, auto c){ return s + c*c; }));
std::accumulate(C.begin(), C.begin() + ncdets, 0.0,
[](auto s, auto c) { return s + c * c; }));

MACIS_MPI_CODE(MPI_Barrier(comm);)
auto asci_search_st = clock_type::now();
Expand Down
2 changes: 0 additions & 2 deletions include/macis/asci/determinant_sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ void reorder_ci_on_alpha(WfnIterator begin, WfnIterator end, double* C) {
std::copy(reorder_C.begin(), reorder_C.end(), C);
}


template <typename PairIterator>
PairIterator accumulate_asci_pairs(PairIterator pairs_begin,
PairIterator pairs_end) {

// Accumulate the ASCI scores into first instance of unique bitstrings
auto cur_it = pairs_begin;
for(auto it = cur_it + 1; it != pairs_end; ++it) {
Expand Down
182 changes: 93 additions & 89 deletions include/macis/asci/mask_constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ auto gen_constraints_general(size_t nlevels, size_t norb, size_t ns_othr,
// Generate triplets + heuristic
std::vector<std::pair<constraint_type, size_t>> constraint_sizes;
constraint_sizes.reserve(norb * norb * norb);
#if 0
#if 0
size_t total_work = 0;
for(int t_i = 0; t_i < norb; ++t_i)
for(int t_j = 0; t_j < t_i; ++t_j)
Expand All @@ -664,72 +664,74 @@ auto gen_constraints_general(size_t nlevels, size_t norb, size_t ns_othr,
}

size_t local_average = (0.8 * total_work) / world_size;
#else
#else
// Generate all the triplets
for(int t_i = 0; t_i < norb; ++t_i)
for(int t_j = 0; t_j < t_i; ++t_j)
for(int t_k = 0; t_k < t_j; ++t_k) {
auto constraint = constraint_type::make_triplet(t_i, t_j, t_k);
constraint_sizes.emplace_back(constraint, 0ul);
}
}

// Build up higher-order constraints as base if requested
if(nrec_min < 0 or nrec_min >= constraint_sizes.size()) // nrec_min < 0 implies that you want all the constraints upfront
for(size_t ilevel = 0; ilevel < nlevel_min; ++ilevel) {
decltype(constraint_sizes) cur_constraints;
cur_constraints.reserve(constraint_sizes.size() * norb);
for(auto [c,nw] : constraint_sizes) {
const auto C_min = c.C_min();
for(auto q_l = 0; q_l < C_min; ++q_l) {
// Generate masks / counts
string_type cn_C = c.C();
cn_C.flip(q_l);
string_type cn_B = c.B() >> (C_min - q_l);
constraint_type c_next(cn_C, cn_B, q_l);
cur_constraints.emplace_back(c_next, 0ul);
if(nrec_min < 0 or
nrec_min >= constraint_sizes.size()) // nrec_min < 0 implies that you want
// all the constraints upfront
for(size_t ilevel = 0; ilevel < nlevel_min; ++ilevel) {
decltype(constraint_sizes) cur_constraints;
cur_constraints.reserve(constraint_sizes.size() * norb);
for(auto [c, nw] : constraint_sizes) {
const auto C_min = c.C_min();
for(auto q_l = 0; q_l < C_min; ++q_l) {
// Generate masks / counts
string_type cn_C = c.C();
cn_C.flip(q_l);
string_type cn_B = c.B() >> (C_min - q_l);
constraint_type c_next(cn_C, cn_B, q_l);
cur_constraints.emplace_back(c_next, 0ul);
}
}
constraint_sizes = std::move(cur_constraints);
}
constraint_sizes = std::move(cur_constraints);
}

struct atomic_wrapper {
std::atomic<size_t> value;
atomic_wrapper(size_t i = 0) : value(i) {};
atomic_wrapper(const atomic_wrapper& other) :
atomic_wrapper(other.value.load()) {};
atomic_wrapper(size_t i = 0) : value(i){};
atomic_wrapper(const atomic_wrapper& other)
: atomic_wrapper(other.value.load()){};
atomic_wrapper& operator=(const atomic_wrapper& other) {
value.store(other.value.load());
return *this;
}
};

// Compute histogram
const auto ntrip_full = constraint_sizes.size();
const auto ntrip_full = constraint_sizes.size();
std::vector<atomic_wrapper> constraint_work(ntrip_full, 0ul);
{
global_atomic<size_t> nxtval(MPI_COMM_WORLD);
#pragma omp parallel
{
size_t i_trip = 0;
while(i_trip < ntrip_full) {
i_trip = nxtval.fetch_and_add(1);
if(i_trip >= ntrip_full) break;
//if(!(i_trip%1000)) printf("cgen %lu / %lu\n", i_trip, ntrip_full);
auto& [constraint, __nw] = constraint_sizes[i_trip];
auto& c_nw = constraint_work[i_trip];
size_t nw = 0;
for(const auto& alpha : unique_alpha) {
if constexpr(flat_container)
nw += constraint_histogram(wfn_traits::alpha_string(alpha), ns_othr,
nd_othr, constraint);
else
nw += alpha.second * constraint_histogram(alpha.first, ns_othr,
nd_othr, constraint);
global_atomic<size_t> nxtval(MPI_COMM_WORLD);
#pragma omp parallel
{
size_t i_trip = 0;
while(i_trip < ntrip_full) {
i_trip = nxtval.fetch_and_add(1);
if(i_trip >= ntrip_full) break;
// if(!(i_trip%1000)) printf("cgen %lu / %lu\n", i_trip, ntrip_full);
auto& [constraint, __nw] = constraint_sizes[i_trip];
auto& c_nw = constraint_work[i_trip];
size_t nw = 0;
for(const auto& alpha : unique_alpha) {
if constexpr(flat_container)
nw += constraint_histogram(wfn_traits::alpha_string(alpha), ns_othr,
nd_othr, constraint);
else
nw += alpha.second * constraint_histogram(alpha.first, ns_othr,
nd_othr, constraint);
}
if(nw) c_nw.value.fetch_add(nw);
}
}
if(nw) c_nw.value.fetch_add(nw);
}
}
} // Scope nxtval
} // Scope nxtval

std::vector<size_t> constraint_work_bare(ntrip_full);
for(auto i_trip = 0; i_trip < ntrip_full; ++i_trip) {
Expand All @@ -744,28 +746,28 @@ auto gen_constraints_general(size_t nlevels, size_t norb, size_t ns_othr,

// Remove zeros
{
auto it = std::partition(constraint_sizes.begin(), constraint_sizes.end(),
[](const auto& p) { return p.second > 0; });
constraint_sizes.erase(it, constraint_sizes.end());
auto it = std::partition(constraint_sizes.begin(), constraint_sizes.end(),
[](const auto& p) { return p.second > 0; });
constraint_sizes.erase(it, constraint_sizes.end());
}

// Compute average
size_t total_work = std::accumulate(constraint_sizes.begin(), constraint_sizes.end(),
0ul, [](auto s, const auto& p){ return s + p.second; });
size_t total_work =
std::accumulate(constraint_sizes.begin(), constraint_sizes.end(), 0ul,
[](auto s, const auto& p) { return s + p.second; });
size_t local_average = total_work / world_size;


// Manual refinement of top configurations
if(nrec_min > 0 and nrec_min < constraint_sizes.size()) {

const size_t nleave = constraint_sizes.size() - nrec_min;
std::vector<std::pair<constraint_type, size_t>> constraint_to_refine,
constraint_to_leave;
std::vector<std::pair<constraint_type, size_t>> constraint_to_refine,
constraint_to_leave;
constraint_to_refine.reserve(nrec_min);
constraint_to_refine.reserve(nleave);

std::copy_n(constraint_sizes.begin(), nrec_min, std::back_inserter(constraint_to_refine));
std::copy_n(constraint_sizes.begin() + nrec_min, nleave,
std::copy_n(constraint_sizes.begin(), nrec_min,
std::back_inserter(constraint_to_refine));
std::copy_n(constraint_sizes.begin() + nrec_min, nleave,
std::back_inserter(constraint_to_leave));

// Deallocate original array
Expand All @@ -774,8 +776,8 @@ auto gen_constraints_general(size_t nlevels, size_t norb, size_t ns_othr,
// Generate refined constraints
for(size_t ilevel = 0; ilevel < nlevel_min; ++ilevel) {
decltype(constraint_sizes) cur_constraints;
cur_constraints.reserve(constraint_to_refine.size() * norb);
for(auto [c,nw] : constraint_to_refine) {
cur_constraints.reserve(constraint_to_refine.size() * norb);
for(auto [c, nw] : constraint_to_refine) {
const auto C_min = c.C_min();
for(auto q_l = 0; q_l < C_min; ++q_l) {
// Generate masks / counts
Expand All @@ -795,27 +797,27 @@ auto gen_constraints_general(size_t nlevels, size_t norb, size_t ns_othr,
std::vector<atomic_wrapper>().swap(constraint_work);
std::vector<size_t>().swap(constraint_work_bare);
constraint_work.resize(nrefine, 0ul);
#pragma omp parallel
#pragma omp parallel
{
size_t i_ref = 0;
while(i_ref < nrefine) {
i_ref = nxtval.fetch_and_add(1);
if(i_ref >= nrefine) break;
//if(!(i_ref%1000)) printf("cgen %lu / %lu\n", i_ref, nrefine);
auto& [constraint, __nw] = constraint_to_refine[i_ref];
auto& c_nw = constraint_work[i_ref];
size_t nw = 0;
for(const auto& alpha : unique_alpha) {
if constexpr(flat_container)
nw += constraint_histogram(wfn_traits::alpha_string(alpha), ns_othr,
nd_othr, constraint);
else
nw += alpha.second * constraint_histogram(alpha.first, ns_othr,
nd_othr, constraint);
}
if(nw) c_nw.value.fetch_add(nw);
} // constraint "loop"
} // OpenMP Context
size_t i_ref = 0;
while(i_ref < nrefine) {
i_ref = nxtval.fetch_and_add(1);
if(i_ref >= nrefine) break;
// if(!(i_ref%1000)) printf("cgen %lu / %lu\n", i_ref, nrefine);
auto& [constraint, __nw] = constraint_to_refine[i_ref];
auto& c_nw = constraint_work[i_ref];
size_t nw = 0;
for(const auto& alpha : unique_alpha) {
if constexpr(flat_container)
nw += constraint_histogram(wfn_traits::alpha_string(alpha), ns_othr,
nd_othr, constraint);
else
nw += alpha.second * constraint_histogram(alpha.first, ns_othr,
nd_othr, constraint);
}
if(nw) c_nw.value.fetch_add(nw);
} // constraint "loop"
} // OpenMP Context

constraint_work_bare.resize(nrefine);
for(auto i_ref = 0; i_ref < nrefine; ++i_ref) {
Expand All @@ -830,24 +832,26 @@ auto gen_constraints_general(size_t nlevels, size_t norb, size_t ns_othr,

// Remove zeros
{
auto it = std::partition(constraint_to_refine.begin(), constraint_to_refine.end(),
[](const auto& p) { return p.second > 0; });
constraint_to_refine.erase(it, constraint_to_refine.end());
auto it = std::partition(constraint_to_refine.begin(),
constraint_to_refine.end(),
[](const auto& p) { return p.second > 0; });
constraint_to_refine.erase(it, constraint_to_refine.end());
}

// Concatenate the arrays
constraint_sizes.reserve(nrefine + nleave);
std::copy_n(constraint_to_refine.begin(), nrefine, std::back_inserter(constraint_sizes));
std::copy_n(constraint_to_leave.begin(), nleave, std::back_inserter(constraint_sizes));

size_t tmp = std::accumulate(constraint_sizes.begin(), constraint_sizes.end(),
0ul, [](auto s, const auto& p){ return s + p.second; });
std::copy_n(constraint_to_refine.begin(), nrefine,
std::back_inserter(constraint_sizes));
std::copy_n(constraint_to_leave.begin(), nleave,
std::back_inserter(constraint_sizes));

size_t tmp =
std::accumulate(constraint_sizes.begin(), constraint_sizes.end(), 0ul,
[](auto s, const auto& p) { return s + p.second; });
if(tmp != total_work) throw std::runtime_error("Incorrect Refinement");
} // Selective refinement logic
} // Selective refinement logic



#endif
#endif

for(size_t ilevel = 0; ilevel < nlevels; ++ilevel) {
// Select constraints larger than average to be broken apart
Expand Down
Loading

0 comments on commit 05d6390

Please sign in to comment.