5 #ifndef ROCKY_ZAGROS_COMM_STRATEGY
6 #define ROCKY_ZAGROS_COMM_STRATEGY
8 #include <rocky/zagros/strategies/strategy.h>
9 #include<nlohmann/json.hpp>
20 template<
typename T_e,
int T_dim>
23 virtual void apply() = 0;
31 template<
typename T_e,
int T_dim>
47 MPI_Comm_size(MPI_COMM_WORLD, &mpi_num_procs_);
48 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank_);
51 int mpi_num_procs()
const{
52 return mpi_num_procs_;
64 template<
typename T_e,
int T_dim>
70 this->set_target_container = container;
73 this->cluster_best_container_ = container;
77 this->cluster_best_container_ =
nullptr;
82 int rank = this->mpi_rank();
89 data_out.cluster_best_min = cluster_best_container_->values[0];
92 if constexpr(std::is_same<T_e, double>::value){
93 MPI_Allreduce(&data_out, &result, 1, MPI_DOUBLE_INT, MPI_MINLOC, MPI_COMM_WORLD);
94 MPI_Bcast(cluster_best_container_->
particle(0), T_dim, MPI_DOUBLE, result.rank, MPI_COMM_WORLD);
96 if constexpr(std::is_same<T_e, float>::value){
97 MPI_Allreduce(&data_out, &result, 1, MPI_FLOAT_INT, MPI_MINLOC, MPI_COMM_WORLD);
98 MPI_Bcast(cluster_best_container_->
particle(0), T_dim, MPI_FLOAT, result.rank, MPI_COMM_WORLD);
100 cluster_best_container_->values[0] = result.cluster_best_min;
107 template<
typename T_e,
int T_dim>
113 this->bcd_mask_ = bcd_mask;
116 virtual void apply(){
117 MPI_Bcast(this->bcd_mask_, T_dim, MPI_INT, 0, MPI_COMM_WORLD);