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 3, 2023
1 parent d0809f7 commit f67afe1
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 212 deletions.
1 change: 0 additions & 1 deletion include/macis/asci/pt2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ double asci_pt2_constraint(wavefunction_iterator_t<N> cdets_begin,
asci_pairs.reserve(100000000ul);
size_t ic = 0;
while(ic < ncon_total) {

// Atomically get the next task ID and increment for other
// MPI ranks and threads
size_t ntake = ic < 1000 ? 1 : 10;
Expand Down
234 changes: 118 additions & 116 deletions include/macis/hamiltonian_generator/sorted_double_loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,140 +76,142 @@ class SortedDoubleLoopHamiltonianGenerator
// << std::endl;

// Populate COO matrix locally
//sparsexx::coo_matrix<double, index_t> coo_mat(nbra_dets, nket_dets, 0, 0);
// sparsexx::coo_matrix<double, index_t> coo_mat(nbra_dets, nket_dets, 0,
// 0);
std::vector<index_t> row_ind, col_ind;
std::vector<double> nz_val;
std::vector<double> nz_val;

//size_t skip1 = 0;
//size_t skip2 = 0;
// size_t skip1 = 0;
// size_t skip2 = 0;

std::mutex coo_mat_thread_mutex;

// Loop over uniq alphas in bra/ket
auto pop_st = std::chrono::high_resolution_clock::now();
#pragma omp parallel
#pragma omp parallel
{
std::vector<index_t> row_ind_loc, col_ind_loc;
std::vector<double> nz_val_loc;
std::vector<uint32_t> bra_occ_alpha, bra_occ_beta;
#pragma omp for schedule(dynamic)
for(size_t ia_bra = 0; ia_bra < nuniq_bra; ++ia_bra) {
if(unique_alpha_bra[ia_bra].first.any()) {
// Extract alpha bra
const auto bra_alpha = unique_alpha_bra[ia_bra].first;
const size_t beta_st_bra = unique_alpha_bra_idx[ia_bra];
const size_t beta_en_bra = unique_alpha_bra_idx[ia_bra + 1];
spin_wfn_traits::state_to_occ(bra_alpha, bra_occ_alpha);

const auto ket_lower = is_symm ? ia_bra : 0;
for(size_t ia_ket = ket_lower; ia_ket < nuniq_ket; ++ia_ket) {
if(unique_alpha_ket[ia_ket].first.any()) {
// Extract alpha ket
const auto ket_alpha = unique_alpha_ket[ia_ket].first;

// Compute alpha excitation
const auto ex_alpha = bra_alpha ^ ket_alpha;
const auto ex_alpha_count = spin_wfn_traits::count(ex_alpha);

// Early exit
if(ex_alpha_count > 4) {
//skip1++;
continue;
}
std::vector<index_t> row_ind_loc, col_ind_loc;
std::vector<double> nz_val_loc;
std::vector<uint32_t> bra_occ_alpha, bra_occ_beta;
#pragma omp for schedule(dynamic)
for(size_t ia_bra = 0; ia_bra < nuniq_bra; ++ia_bra) {
if(unique_alpha_bra[ia_bra].first.any()) {
// Extract alpha bra
const auto bra_alpha = unique_alpha_bra[ia_bra].first;
const size_t beta_st_bra = unique_alpha_bra_idx[ia_bra];
const size_t beta_en_bra = unique_alpha_bra_idx[ia_bra + 1];
spin_wfn_traits::state_to_occ(bra_alpha, bra_occ_alpha);

const auto ket_lower = is_symm ? ia_bra : 0;
for(size_t ia_ket = ket_lower; ia_ket < nuniq_ket; ++ia_ket) {
if(unique_alpha_ket[ia_ket].first.any()) {
// Extract alpha ket
const auto ket_alpha = unique_alpha_ket[ia_ket].first;

// Compute alpha excitation
const auto ex_alpha = bra_alpha ^ ket_alpha;
const auto ex_alpha_count = spin_wfn_traits::count(ex_alpha);

// Early exit
if(ex_alpha_count > 4) {
// skip1++;
continue;
}

// Precompute all-alpha excitation if it will be used
const double mat_el_4_alpha =
(ex_alpha_count == 4)
? this->matrix_element_4(bra_alpha, ket_alpha, ex_alpha)
: 0.0;
if(ex_alpha_count == 4 and std::abs(mat_el_4_alpha) < H_thresh) {
// The only possible matrix element is too-small, skip everyhing
//skip2++;
continue;
}
// Precompute all-alpha excitation if it will be used
const double mat_el_4_alpha =
(ex_alpha_count == 4)
? this->matrix_element_4(bra_alpha, ket_alpha, ex_alpha)
: 0.0;
if(ex_alpha_count == 4 and std::abs(mat_el_4_alpha) < H_thresh) {
// The only possible matrix element is too-small, skip everyhing
// skip2++;
continue;
}

const size_t beta_st_ket = unique_alpha_ket_idx[ia_ket];
const size_t beta_en_ket = unique_alpha_ket_idx[ia_ket + 1];

// Loop over local betas according to their global indices
for(size_t ibra = beta_st_bra; ibra < beta_en_bra; ++ibra) {
const auto bra_beta =
wfn_traits::beta_string(*(bra_begin + ibra));
spin_wfn_traits::state_to_occ(bra_beta, bra_occ_beta);
for(size_t iket = beta_st_ket; iket < beta_en_ket; ++iket) {
if(is_symm and (iket < ibra)) continue;
const auto ket_beta =
wfn_traits::beta_string(*(ket_begin + iket));

// Compute beta excitation
const auto ex_beta = bra_beta ^ ket_beta;
const auto ex_beta_count = spin_wfn_traits::count(ex_beta);

if((ex_alpha_count + ex_beta_count) > 4) continue;

double h_el = 0.0;
if(ex_alpha_count == 4) {
// Use precomputed value
h_el = mat_el_4_alpha;
} else if(ex_beta_count == 4) {
h_el = this->matrix_element_4(bra_beta, ket_beta, ex_beta);
} else if(ex_alpha_count == 2) {
if(ex_beta_count == 2) {
h_el =
this->matrix_element_22(bra_alpha, ket_alpha, ex_alpha,
bra_beta, ket_beta, ex_beta);
const size_t beta_st_ket = unique_alpha_ket_idx[ia_ket];
const size_t beta_en_ket = unique_alpha_ket_idx[ia_ket + 1];

// Loop over local betas according to their global indices
for(size_t ibra = beta_st_bra; ibra < beta_en_bra; ++ibra) {
const auto bra_beta =
wfn_traits::beta_string(*(bra_begin + ibra));
spin_wfn_traits::state_to_occ(bra_beta, bra_occ_beta);
for(size_t iket = beta_st_ket; iket < beta_en_ket; ++iket) {
if(is_symm and (iket < ibra)) continue;
const auto ket_beta =
wfn_traits::beta_string(*(ket_begin + iket));

// Compute beta excitation
const auto ex_beta = bra_beta ^ ket_beta;
const auto ex_beta_count = spin_wfn_traits::count(ex_beta);

if((ex_alpha_count + ex_beta_count) > 4) continue;

double h_el = 0.0;
if(ex_alpha_count == 4) {
// Use precomputed value
h_el = mat_el_4_alpha;
} else if(ex_beta_count == 4) {
h_el = this->matrix_element_4(bra_beta, ket_beta, ex_beta);
} else if(ex_alpha_count == 2) {
if(ex_beta_count == 2) {
h_el = this->matrix_element_22(bra_alpha, ket_alpha,
ex_alpha, bra_beta,
ket_beta, ex_beta);
} else {
h_el =
this->matrix_element_2(bra_alpha, ket_alpha, ex_alpha,
bra_occ_alpha, bra_occ_beta);
}
} else if(ex_beta_count == 2) {
h_el = this->matrix_element_2(bra_beta, ket_beta, ex_beta,
bra_occ_beta, bra_occ_alpha);
} else {
// Diagonal matrix element
h_el =
this->matrix_element_2(bra_alpha, ket_alpha, ex_alpha,
bra_occ_alpha, bra_occ_beta);
}
} else if(ex_beta_count == 2) {
h_el = this->matrix_element_2(bra_beta, ket_beta, ex_beta,
bra_occ_beta, bra_occ_alpha);
} else {
// Diagonal matrix element
h_el = this->matrix_element_diag(bra_occ_alpha, bra_occ_beta);
}

// Insert matrix element
if(std::abs(h_el) > H_thresh) {
//coo_mat.template insert<false>(ibra, iket, h_el);
row_ind_loc.emplace_back(ibra);
col_ind_loc.emplace_back(iket);
nz_val_loc. emplace_back(h_el);
if(is_symm and ibra != iket) {
//coo_mat.template insert<false>(iket, ibra, h_el);
row_ind_loc.emplace_back(iket);
col_ind_loc.emplace_back(ibra);
nz_val_loc. emplace_back(h_el);
this->matrix_element_diag(bra_occ_alpha, bra_occ_beta);
}
}

} // ket beta
} // bra beta

}
} // Loop over ket alphas
}
} // Loop over bra alphas

// Atomically insert into larger matrix arrays
#pragma omp critical
{
row_ind.insert(row_ind.end(), row_ind_loc.begin(), row_ind_loc.end());
//row_ind_loc.clear(); row_ind_loc.shrink_to_fit();
col_ind.insert(col_ind.end(), col_ind_loc.begin(), col_ind_loc.end());
//col_ind_loc.clear(); col_ind_loc.shrink_to_fit();
nz_val.insert(nz_val.end(), nz_val_loc.begin(), nz_val_loc.end());
//nz_val_loc.clear(); nz_val_loc.shrink_to_fit();
}
// Insert matrix element
if(std::abs(h_el) > H_thresh) {
// coo_mat.template insert<false>(ibra, iket, h_el);
row_ind_loc.emplace_back(ibra);
col_ind_loc.emplace_back(iket);
nz_val_loc.emplace_back(h_el);
if(is_symm and ibra != iket) {
// coo_mat.template insert<false>(iket, ibra, h_el);
row_ind_loc.emplace_back(iket);
col_ind_loc.emplace_back(ibra);
nz_val_loc.emplace_back(h_el);
}
}

} // OpenMP
} // ket beta
} // bra beta
}
} // Loop over ket alphas
}
} // Loop over bra alphas

// Atomically insert into larger matrix arrays
#pragma omp critical
{
row_ind.insert(row_ind.end(), row_ind_loc.begin(), row_ind_loc.end());
// row_ind_loc.clear(); row_ind_loc.shrink_to_fit();
col_ind.insert(col_ind.end(), col_ind_loc.begin(), col_ind_loc.end());
// col_ind_loc.clear(); col_ind_loc.shrink_to_fit();
nz_val.insert(nz_val.end(), nz_val_loc.begin(), nz_val_loc.end());
// nz_val_loc.clear(); nz_val_loc.shrink_to_fit();
}

} // OpenMP
auto pop_en = std::chrono::high_resolution_clock::now();

// Generate Sparse Matrix
sparsexx::coo_matrix<double, index_t> coo_mat(nbra_dets, nket_dets,
std::move(col_ind), std::move(row_ind), std::move(nz_val), 0);
sparsexx::coo_matrix<double, index_t> coo_mat(
nbra_dets, nket_dets, std::move(col_ind), std::move(row_ind),
std::move(nz_val), 0);

// Sort for CSR Conversion
auto sort_st = std::chrono::high_resolution_clock::now();
Expand Down
17 changes: 6 additions & 11 deletions include/macis/util/mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,17 @@ struct mpi_traits<std::bitset<N>> {
}
};




template <typename T>
class global_atomic {
MPI_Win window_;
T* buffer_;

public:
T* buffer_;

public:
global_atomic() = delete;

global_atomic(MPI_Comm comm) {
MPI_Win_allocate(sizeof(T), sizeof(T), MPI_INFO_NULL, comm, &buffer_,
&window_);
&window_);
if(window_ == MPI_WIN_NULL) {
throw std::runtime_error("Window creation failed");
}
Expand All @@ -257,16 +253,15 @@ class global_atomic {

global_atomic(const global_atomic&) = delete;
global_atomic(global_atomic&&) noexcept = delete;

T fetch_and_add(T val) {
T next_val;
MPI_Fetch_and_op(&val, &next_val, mpi_traits<T>::datatype(), 0, 0, MPI_SUM,
window_);
MPI_Win_flush(0,window_);
window_);
MPI_Win_flush(0, window_);
return next_val;
}
};


} // namespace macis
#endif
18 changes: 8 additions & 10 deletions include/macis/util/trexio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,30 @@
* See LICENSE.txt for details
*/
#include <trexio.h>

#include <stdexcept>

namespace macis {

class trexio_exception : public std::exception {
std::string msg_;
const char* what() const noexcept override;
const char* what() const noexcept override;

public:
public:
trexio_exception(std::string func_name, trexio_exit_code rc);
};

class TREXIOFile {
trexio_t * file_handle_ = nullptr;

public:
trexio_t* file_handle_ = nullptr;

public:
TREXIOFile() noexcept = default;

TREXIOFile(std::string name, char mode, int backend);
TREXIOFile(std::string name, char mode, int backend);
~TREXIOFile() noexcept;

TREXIOFile(const TREXIOFile&) = delete;
TREXIOFile(TREXIOFile&& other) noexcept;

TREXIOFile(TREXIOFile&& other) noexcept;

int64_t read_mo_num() const;
int64_t read_mo_2e_int_eri_size() const;
Expand All @@ -43,7 +42,6 @@ class TREXIOFile {
void write_nucleus_repulsion(double E);
void write_mo_1e_int_core_hamiltonian(const double* h);
void write_mo_2e_int_eri(const double* V);

};

}
} // namespace macis
Loading

0 comments on commit f67afe1

Please sign in to comment.