Skip to content

Commit

Permalink
The broyden mixer class no longer needs the communicator member.
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierandrade committed Sep 20, 2024
1 parent 09ff39b commit 1b37e01
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/ground_state/calculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class calculator {
auto mixer = [&]()->std::unique_ptr<mixers::base<mix_arr_type>>{
switch(solver_.mixing_algorithm()){
case options::ground_state::mixing_algo::LINEAR : return std::make_unique<mixers::linear <mix_arr_type>>(solver_.mixing());
case options::ground_state::mixing_algo::BROYDEN: return std::make_unique<mixers::broyden<mix_arr_type>>(4, solver_.mixing(), electrons.spin_density().matrix().flatted().size(), electrons.density_basis().comm());
case options::ground_state::mixing_algo::BROYDEN: return std::make_unique<mixers::broyden<mix_arr_type>>(4, solver_.mixing(), electrons.spin_density().matrix().flatted().size());
} __builtin_unreachable();
}();

Expand Down
28 changes: 12 additions & 16 deletions src/mixers/broyden.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@ class broyden : public base<FieldType> {

using element_type = typename FieldType::element_type;

template <class CommType>
broyden(const int arg_steps, const double arg_mix_factor, const long long dim, CommType & comm):
broyden(const int arg_steps, const double arg_mix_factor, const long long dim):
iter_(0),
max_size_(arg_steps),
mix_factor_(arg_mix_factor),
dv_({max_size_, dim}, NAN),
df_({max_size_, dim}, NAN),
f_old_(dim, NAN),
vin_old_(dim, NAN),
last_pos_(-1),
comm_(comm){
last_pos_(-1){
}

///////////////////////////////////////////////////////////////////////////////////////////////////
template <typename Array>
void broyden_extrapolation(Array & input_value, int const iter_used, gpu::array<element_type, 1> const & ff){
template <typename Comm, typename Array>
void broyden_extrapolation(Comm & comm, Array & input_value, int const iter_used, gpu::array<element_type, 1> const & ff){

CALI_CXX_MARK_SCOPE("broyden_extrapolation");

Expand All @@ -70,12 +68,12 @@ class broyden : public base<FieldType> {
auto workmat = +blas::gemm(1.0, matff, blas::H(subdf));
auto work = +workmat[0];

gpu::run(iter_used, [w0, ww, be = begin(beta), dfactor = 1.0/comm_.size()] GPU_LAMBDA (auto ii){ be[ii][ii] = dfactor*(w0*w0 + ww*ww); });
gpu::run(iter_used, [w0, ww, be = begin(beta), dfactor = 1.0/comm.size()] GPU_LAMBDA (auto ii){ be[ii][ii] = dfactor*(w0*w0 + ww*ww); });

if(comm_.size() > 1){
if(comm.size() > 1){
CALI_CXX_MARK_SCOPE("broyden_extrapolation::reduce");
comm_.all_reduce_n(raw_pointer_cast(beta.data_elements()), beta.num_elements());
comm_.all_reduce_n(raw_pointer_cast(work.data_elements()), work.num_elements());
comm.all_reduce_n(raw_pointer_cast(beta.data_elements()), beta.num_elements());
comm.all_reduce_n(raw_pointer_cast(work.data_elements()), work.num_elements());
}

solvers::least_squares(beta, work);
Expand Down Expand Up @@ -129,9 +127,9 @@ class broyden : public base<FieldType> {

gamma_ = dot(conj(df_[pos]), df_[pos]);

if(comm_.size() > 1){
if(input_field.full_comm().size() > 1){
CALI_CXX_MARK_SCOPE("broyden_mixing::reduce");
comm_.all_reduce_in_place_n(&gamma_, 1, std::plus<>{});
input_field.full_comm().all_reduce_in_place_n(&gamma_, 1, std::plus<>{});
}

gamma_ = std::max(1e-8, sqrt(gamma_));
Expand All @@ -151,7 +149,7 @@ class broyden : public base<FieldType> {

auto iter_used = std::min(iter_ - 1, max_size_);

broyden_extrapolation(input_value, iter_used, ff);
broyden_extrapolation(input_field.full_comm(), input_value, iter_used, ff);

}

Expand All @@ -166,8 +164,6 @@ class broyden : public base<FieldType> {
gpu::array<element_type, 1> vin_old_;
element_type gamma_;
int last_pos_;
mutable parallel::communicator comm_;

};

}
Expand Down Expand Up @@ -196,7 +192,7 @@ TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) {
vout.matrix()[0][0] = 0.0;
vout.matrix()[1][0] = 22.2;

mixers::broyden<decltype(vin)> mixer(5, 0.5, 2, comm);
mixers::broyden<decltype(vin)> mixer(5, 0.5, 2);

mixer(vin, vout);

Expand Down
2 changes: 1 addition & 1 deletion src/real_time/crank_nicolson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void crank_nicolson(double const time, double const dt, systems::ions & ions, sy
}

using mix_arr_type = std::remove_reference_t<decltype(electrons.spin_density())>;
auto mixer = mixers::broyden<mix_arr_type>(4, 0.3, electrons.spin_density().matrix().flatted().size(), electrons.density_basis().comm());
auto mixer = mixers::broyden<mix_arr_type>(4, 0.3, electrons.spin_density().matrix().flatted().size());

auto old_exxe = 0.0;
auto update_hf = true;
Expand Down

0 comments on commit 1b37e01

Please sign in to comment.