PURIFY
Next-generation radio interferometric imaging
Functions
purify::random_updater Namespace Reference

Functions

std::function< bool()> random_updater (const sopt::mpi::Communicator &comm, const t_int total, const t_int update_size, const std::shared_ptr< bool > update_pointer, const std::string &update_name)
 

Function Documentation

◆ random_updater()

std::function<bool()> purify::random_updater::random_updater ( const sopt::mpi::Communicator &  comm,
const t_int  total,
const t_int  update_size,
const std::shared_ptr< bool >  update_pointer,
const std::string &  update_name 
)

Definition at line 7 of file random_update_factory.cc.

10  {
11  if (update_size > comm.size())
12  throw std::runtime_error(
13  "Number of random updates cannot be greater than number of MPI processors in the "
14  "communicator " +
15  std::to_string(comm.size()) + " < " + std::to_string(update_size) + " .");
16  std::shared_ptr<std::vector<t_int>> ind = std::make_shared<std::vector<t_int>>(total, 0);
17  for (t_int i = 0; i < total; i++) (*ind)[i] = i;
18  std::random_device rng;
19  std::shared_ptr<std::mt19937> urng = std::make_shared<std::mt19937>(rng());
20  return [update_pointer, update_size, update_name, ind, comm, urng]() -> bool {
21  if (comm.is_root()) {
22  std::shuffle(std::begin(*ind), std::end(*ind), *urng);
23  };
24  *ind = comm.broadcast(*ind);
25  *update_pointer = false;
26  for (t_int i = 0; i < update_size; i++)
27  if (comm.rank() == ind->at(i)) {
28  SOPT_DEBUG("Process {} doing {}", comm.rank(), update_name);
29  *update_pointer = true;
30  }
31  return *update_pointer;
32  };
33 }

Referenced by BENCHMARK_DEFINE_F(), and purify::factory::primaldual_factory().