7#ifndef GPR_LINALG_DISTRIBUTEDSTATE_H_
8#define GPR_LINALG_DISTRIBUTEDSTATE_H_
49#if defined(GPR_LINALG_SLATE)
51#elif defined(GPR_LINALG_SCALAPACK)
79 [[nodiscard]]
bool valid() const noexcept
107 throw std::invalid_argument(
108 "distributed state requires communication");
115 MPI_Initialized(&mpi_up);
116 MPI_Finalized(&mpi_fin);
117 if (!mpi_up || mpi_fin)
return;
119 communication_.reset();
120 if (owns_mpi_) MPI_Finalize();
126 return communication_;
131 return grid_generation_;
151 int rows = 0, cols = 0;
152 descriptor_grid(desc, rows, cols);
163 const int* other =
nullptr)
const
169 static std::atomic<bool> reported{
false};
170 if (
is_root() && !reported.exchange(
true)) {
171 int rows = 0, cols = 0;
172 descriptor_grid(desc, rows, cols);
175 "[gpr::linalg] library factorization: %s on order %d needs "
176 "%lld local entries on a %d x %d grid, past the %lld an "
177 "LP64 ScaLAPACK indexes; operations on this order run on "
178 "the tile kernels\n",
191 int rows = 0, cols = 0;
192 descriptor_grid(desc, rows, cols);
193 throw std::length_error(
194 std::string(routine) +
": a " + std::to_string(desc[2]) +
" x " +
195 std::to_string(desc[3]) +
" matrix on a " + std::to_string(rows) +
196 " x " + std::to_string(cols) +
" grid needs " +
199 " an LP64 ScaLAPACK indexes; run on more processes");
238 if (requested_block <= 0)
return 64;
239 return requested_block;
245 if (
nprocs <= 1)
return 1;
246 int nprow =
static_cast<int>(std::sqrt(
static_cast<double>(
nprocs)));
263 bool computation_tile =
false) noexcept
267 computation_tile_ = computation_tile;
272 return configured_block_size_;
279 if (configured_block_size_ > 0)
return configured_block_size_;
280 const bool tile_sets_arithmetic =
283 if (computation_tile_ && tile_sets_arithmetic)
290 return configured_nprow_;
297 const int requested_block_size =
298 configured_block > 0 ? configured_block :
block_size;
299 const int requested_nprow =
300 configured_nprow_ > 0 ? configured_nprow_ :
nprow;
309 (requested_block_size <= 0 || requested_block_size == mb_) &&
310 (requested_nprow <= 0 || requested_nprow == nprow_)) {
316 MPI_Initialized(&mpi_up);
317 int provided = MPI_THREAD_SINGLE;
319 if (MPI_Init_thread(
nullptr,
nullptr, requiredMpiThreadSupport(),
320 &provided) != MPI_SUCCESS)
321 throw std::runtime_error(
"could not initialize MPI");
323 }
else if (MPI_Query_thread(&provided) != MPI_SUCCESS) {
324 throw std::runtime_error(
"could not inspect MPI thread support");
326 if (provided < requiredMpiThreadSupport()) {
331 throw std::runtime_error(mpiThreadSupportError());
335 communication_ = std::make_shared<MpiCommunicator>(MPI_COMM_WORLD);
336 const MpiContext process_group = communication_->view();
337 const int next_nprocs = process_group.
nprocs;
338 const int next_myrank = process_group.
rank;
340 if (requested_block_size > 0) {
352 if (requested_nprow > 0 && next_nprocs % requested_nprow == 0) {
353 next_nprow = requested_nprow;
355 const int next_npcol = next_nprocs / next_nprow;
359 nprocs_ == next_nprocs &&
360 myrank_ == next_myrank &&
361 nprow_ == next_nprow && npcol_ == next_npcol;
362 if (same_grid)
return;
374 L_lin_cache_.clear();
378 initialized_ =
false;
381 nprocs_ = next_nprocs;
382 myrank_ = next_myrank;
387 gpr_comm_ = process_group.
comm;
390 blacs_communication_ = std::make_unique<MpiCommunicator>(gpr_comm_);
393 ictxt_ = system_handle_;
404 lin_ictxt_ = system_handle_;
406 int lin_nprow = 0, lin_npcol = 0;
412 col_ictxt_ = system_handle_;
414 int col_nprow = 0, col_npcol = 0;
420 MPI_Comm node = MPI_COMM_NULL;
421 MPI_Comm_split_type(gpr_comm_, MPI_COMM_TYPE_SHARED, myrank_,
422 MPI_INFO_NULL, &node);
423 MPI_Comm_size(node, &node_ranks_);
424 cpu_share_ = node_cpu_share(node);
425 MPI_Comm_free(&node);
454 descinit_(desc, &m, &n, &mb_, &mb_, &zero, &zero, &lin_ictxt_, &lld,
462 return numroc_(&m, &mb_, &lin_myrow_, &zero, &nprocs_);
472 return (n + nprocs_ - 1) / nprocs_;
480 start = col_mycol_ * nb;
485 count = std::min(nb, n - start);
496 int lld = std::max(1, m);
499 descinit_(desc, &m, &n, &m, &nb, &zero, &zero, &col_ictxt_, &lld,
526 std::vector<double> local(
static_cast<size_t>(lr) * lc, 0.0);
529 int lld_g = std::max(1, m);
532 descinit_(desc_g, &m, &n, &m, &n, &zero, &zero, &lin_ictxt_, &lld_g,
537 const bool root_has_data =
538 lin_myrow_ == 0 && lin_mycol_ == 0 &&
539 global.size() ==
static_cast<Eigen::Index
>(m) * n;
543 desc, local.data(), lin_myrow_, 0, nprocs_, 1);
546 const double* global_data = root_has_data ? global.data() : &dummy;
547 Cpdgemr2d(m, n, global_data, 1, 1, desc_g, local.data(), 1, 1, desc,
558 const Eigen::VectorXd& global,
int m,
int* desc)
const
562 std::vector<double> local(
static_cast<size_t>(lr), 0.0);
564 Eigen::VectorXd replicated =
565 is_root() ? global : Eigen::VectorXd::Zero(m);
566 if (replicated.size() != m) replicated.resize(m);
568 MPI_Bcast(replicated.data(), m, MPI_DOUBLE, 0, gpr_comm_);
571 for (
int i = 0; i < m; ++i) {
572 const int owner_row = (i / mb_) % nprocs_;
573 if (owner_row != lin_myrow_)
continue;
576 local[
static_cast<size_t>(local_i)] = replicated(i);
588 const int* desc,
int m)
const
591 Eigen::VectorXd result = Eigen::VectorXd::Zero(m);
592 for (
int i = 0; i < m; ++i) {
593 const int owner_row = (i / mb_) % nprocs_;
594 if (owner_row != lin_myrow_)
continue;
597 result(i) = local[
static_cast<size_t>(local_i)];
600 MPI_Allreduce(MPI_IN_PLACE, result.data(), m, MPI_DOUBLE, MPI_SUM,
626 std::lock_guard<std::mutex> guard(desc_cache_mutex_);
627 for (
const auto& entry: desc_cache_) {
628 if (entry.m == m && entry.n == n) {
629 std::copy_n(entry.desc, 9, desc);
636 descinit_(desc, &m, &n, &mb_, &mb_, &zero, &zero, &ictxt_, &lld, &info);
638 DescCacheEntry entry;
641 std::copy_n(desc, 9, entry.desc);
642 desc_cache_.push_back(entry);
649 return numroc_(&m, &mb_, &myrow_, &zero, &nprow_);
656 return numroc_(&n, &mb_, &mycol_, &zero, &npcol_);
660 int nprocs_dim)
const
665 const int owner = block % nprocs_dim;
666 assert(owner == proc_coord);
670 const int local_block = block / nprocs_dim;
675 int nprocs_dim)
const
677 const int local_block = local_index /
block_size;
679 const int global_block = local_block * nprocs_dim + proc_coord;
692 std::vector<double> local(
static_cast<size_t>(lr) * lc, 0.0);
696 assert(lr == m && lc == n);
697 if (global.size() > 0)
698 std::copy_n(global.data(),
static_cast<size_t>(m) * n,
705 int lld_g = std::max(1, m);
708 descinit_(desc_g, &m, &n, &m, &n, &zero, &zero, &ictxt_, &lld_g, &info);
715 const bool root_has_data =
716 is_root() && global.size() ==
static_cast<Eigen::Index
>(m) * n;
719 desc, local.data(), myrow_, mycol_, nprow_,
723 const double* global_data = root_has_data ? global.data() : &dummy;
724 Cpdgemr2d(m, n, global_data, 1, 1, desc_g, local.data(), 1, 1, desc,
736 double* local,
int row,
int col,
int nprow,
739 constexpr int transfer_elements = 1024 * 1024;
740 const int panel_columns =
741 std::max(1, transfer_elements / std::max(1, m));
742 const int local_rows_here =
744 std::vector<int> owned_rows(
static_cast<std::size_t
>(local_rows_here));
745 for (
int il = 0; il < local_rows_here; ++il)
746 owned_rows[
static_cast<std::size_t
>(il)] =
750 std::vector<double> panel;
751 for (
int first = 0; first < n; first += panel_columns) {
752 const int columns = std::min(panel_columns, n - first);
753 panel.assign(
static_cast<std::size_t
>(m) * columns, 0.0);
754 if (
is_root() && global !=
nullptr)
755 std::copy_n(global +
static_cast<std::size_t
>(first) * m,
756 panel.size(), panel.data());
757 MPI_Bcast(panel.data(),
static_cast<int>(panel.size()), MPI_DOUBLE,
759 for (
int j = first; j < first + columns; ++j) {
760 if ((j / desc[5] + desc[7]) %
npcol != col)
continue;
761 const int jl = (j / desc[5] /
npcol) * desc[5] + j % desc[5];
762 double* target = local +
static_cast<std::size_t
>(jl) * desc[8];
763 const double* source =
764 panel.data() +
static_cast<std::size_t
>(j - first) * m;
765 for (
int il = 0; il < local_rows_here; ++il)
767 source[owned_rows[
static_cast<std::size_t
>(il)]];
778 return std::vector<double>(
786 int m,
int* desc)
const
791 std::vector<double> local(
static_cast<size_t>(lr) * lc, 0.0);
794 assert(lr == m && lc == 1);
795 if (global.size() > 0)
796 std::copy_n(global.data(),
static_cast<size_t>(m),
801 Eigen::VectorXd replicated =
802 is_root() ? global : Eigen::VectorXd::Zero(m);
803 if (replicated.size() != m) replicated.resize(m);
804 MPI_Bcast(replicated.data(), m, MPI_DOUBLE, 0, gpr_comm_);
806 if (lc == 0 || mycol_ != 0)
return local;
808 for (
int i = 0; i < m; ++i) {
809 const int owner_row = (i / mb_) % nprow_;
810 if (owner_row != myrow_)
continue;
812 local[
static_cast<size_t>(local_i)] = replicated(i);
822 bool broadcast_result =
true)
const
824 return gather_block(local, desc, 0, 0, m, n, broadcast_result);
832 int col0,
int m,
int n,
833 bool broadcast_result =
true)
const
839 for (
int j = 0; j < n; ++j)
841 local +
static_cast<std::size_t
>(col0 + j) * desc[8] + row0,
842 m, global.data() +
static_cast<std::size_t
>(j) * m);
846 if (broadcast_result ||
is_root()) {
849 global = EigenMatrix::Zero(1, 1);
855 int grid_rows = 0, grid_columns = 0, row = 0, column = 0;
861 std::vector<std::uint64_t> bits(
static_cast<std::size_t
>(m), 0);
862 if ((col0 / desc[5] + desc[7]) % grid_columns == column) {
863 const std::size_t local_column =
864 (col0 / desc[5] / grid_columns) * desc[5] + col0 % desc[5];
865 for (
int i = 0; i < m; ++i) {
866 const int global_row = row0 + i;
867 if ((global_row / desc[4] + desc[6]) % grid_rows != row)
869 const std::size_t local_row =
870 (global_row / desc[4] / grid_rows) * desc[4] +
871 global_row % desc[4];
872 bits[
static_cast<std::size_t
>(i)] =
873 std::bit_cast<std::uint64_t>(
874 local[local_column * desc[8] + local_row]);
877 if (broadcast_result) {
878 MPI_Allreduce(MPI_IN_PLACE, bits.data(), m, MPI_UINT64_T,
881 MPI_Reduce(MPI_IN_PLACE, bits.data(), m, MPI_UINT64_T, MPI_BOR,
884 MPI_Reduce(bits.data(),
nullptr, m, MPI_UINT64_T, MPI_BOR, 0,
888 for (
int i = 0; i < m; ++i)
890 std::bit_cast<double>(bits[
static_cast<std::size_t
>(i)]);
893 const int coordinates[2] = {row, column};
894 std::vector<int> owners(2 * nprocs_);
895 MPI_Gather(coordinates, 2, MPI_INT, owners.data(), 2, MPI_INT, 0,
899 const int row_end = row0 + m;
900 const int local_first =
901 numroc_(&row0, &desc[4], &row, &desc[6], &grid_rows);
902 const int local_count =
903 numroc_(&row_end, &desc[4], &row, &desc[6], &grid_rows) -
905 std::vector<std::vector<int>> global_rows;
907 global_rows.resize(grid_rows);
908 for (
int i = row0; i < row_end; ++i)
909 global_rows[(i / desc[4] + desc[6]) % grid_rows].push_back(
912 constexpr int transfer_elements = 1024 * 1024;
913 const int panel_columns =
914 std::max(1, transfer_elements / std::max(1, m));
915 std::vector<double> send, receive;
916 std::vector<int> counts(nprocs_), offsets(nprocs_);
917 std::vector<int> column_counts(grid_columns);
919 for (
int first = 0; first < n;) {
920 const int columns = std::min(panel_columns, n - first);
921 std::fill(column_counts.begin(), column_counts.end(), 0);
922 for (
int j = col0 + first; j < col0 + first + columns; ++j)
923 ++column_counts[(j / desc[5] + desc[7]) % grid_columns];
924 const int send_count = local_count * column_counts[column];
925 send.resize(send_count);
927 for (
int j = col0 + first; j < col0 + first + columns; ++j) {
928 if ((j / desc[5] + desc[7]) % grid_columns != column)
continue;
929 const int local_column =
930 (j / desc[5] / grid_columns) * desc[5] + j % desc[5];
931 if (local_count > 0) {
934 static_cast<std::size_t
>(local_column) * desc[8] +
936 local_count, send.data() + at);
942 for (
int rank = 0; rank < nprocs_; ++rank) {
944 static_cast<int>(global_rows[owners[2 * rank]].size()) *
945 column_counts[owners[2 * rank + 1]];
946 offsets[rank] = offset;
947 offset += counts[rank];
949 assert(offset == m * columns);
950 receive.resize(offset);
952 MPI_Gatherv(send.empty() ? &dummy : send.data(), send_count,
953 MPI_DOUBLE, receive.empty() ? &dummy : receive.data(),
954 counts.data(), offsets.data(), MPI_DOUBLE, 0,
957 for (
int rank = 0; rank < nprocs_; ++rank) {
958 int cursor = offsets[rank];
959 const auto& rows = global_rows[owners[2 * rank]];
960 const int owner_column = owners[2 * rank + 1];
961 for (
int j = first; j < first + columns; ++j) {
962 if (((col0 + j) / desc[5] + desc[7]) % grid_columns !=
965 for (
const int i: rows)
966 global(i, j) = receive[cursor++];
970 if (broadcast_result)
971 MPI_Bcast(global.data() +
static_cast<std::size_t
>(first) * m,
972 m * columns, MPI_DOUBLE, 0, gpr_comm_);
975 if (!broadcast_result && !
is_root()) {
987 bool broadcast_result =
true)
const
991 throw std::invalid_argument(
992 "distributed column-vector gather requires a nonnegative size");
993 if (m == 0)
return Eigen::VectorXd();
996 throw std::invalid_argument(
997 "distributed column-vector gather requires a source "
999 Eigen::VectorXd global(m);
1000 for (
int i = 0; i < m; ++i)
1001 global(i) = local[i];
1005 const bool owns_entries =
1007 int missing_source = owns_entries && !local ? 1 : 0;
1008 int any_missing_source = 0;
1009 MPI_Allreduce(&missing_source, &any_missing_source, 1, MPI_INT, MPI_MAX,
1011 if (any_missing_source)
1012 throw std::invalid_argument(
1013 "distributed column-vector gather requires source buffers on "
1014 "ranks that own vector entries");
1016 Eigen::VectorXd local_full = Eigen::VectorXd::Zero(m);
1018 for (
int i = 0; i < m; ++i) {
1019 const int owner_row = (i / mb_) % nprow_;
1020 if (owner_row != myrow_)
continue;
1023 local_full(i) = local[
static_cast<size_t>(local_i)];
1030 if (broadcast_result) {
1031 MPI_Allreduce(MPI_IN_PLACE, local_full.data(), m, MPI_DOUBLE,
1032 MPI_SUM, gpr_comm_);
1036 MPI_Reduce(MPI_IN_PLACE, local_full.data(), m, MPI_DOUBLE, MPI_SUM,
1040 MPI_Reduce(local_full.data(),
nullptr, m, MPI_DOUBLE, MPI_SUM, 0,
1042 return Eigen::VectorXd();
1046 void cache_L(std::vector<double> L_dist,
const int* desc,
int n)
1048 L_cache_ = std::move(L_dist);
1049 std::copy_n(desc, 9, L_desc_);
1061 if (L_current()) L_owner_ = owner;
1066 return L_current() && owner !=
nullptr && L_owner_ == owner;
1071 return L_current() && L_owner_ ==
nullptr;
1078 snapshot.
values = std::move(L_cache_);
1079 std::copy_n(L_desc_, 9, snapshot.
descriptor.begin());
1080 snapshot.
order = L_n_;
1092 if (!snapshot.
valid() || owner ==
nullptr)
return false;
1105 return L_cache_.data();
1112 return L_cache_.data();
1119 return L_current() && has_U_;
1123 U_cache_ = std::move(U);
1128 return U_cache_.data();
1154 L_lin_cache_ = std::move(L_dist);
1155 std::copy_n(desc, 9, L_lin_desc_);
1167 return L_lin_cache_.data();
1171 return L_lin_cache_.data();
1182 void cache_inv(std::vector<double> inv_dist,
const int* desc,
int n)
1185 Inv_cache_ = std::move(inv_dist);
1186 std::copy_n(desc, 9, Inv_desc_);
1194 return inverse_builds_;
1203 return Inv_cache_.data();
1228 static void release(std::vector<double>& buffer)
noexcept
1230 std::vector<double>().swap(buffer);
1235 const int owner_row = (global_row / mb_) % nprow_;
1236 const int owner_col = (global_col / mb_) % npcol_;
1237 return owner_row == myrow_ && owner_col == mycol_;
1245 return (global_row / mb_) % nprocs_ == lin_myrow_;
1253 int& leading_dimension)
const
1261 leading_dimension = Inv_desc_[8];
1262 return Inv_cache_.data() +
static_cast<size_t>(local_i) +
1263 static_cast<size_t>(local_j) * leading_dimension;
1276 const int leading_dimension = Inv_desc_[8];
1277 return Inv_cache_[
static_cast<size_t>(local_i) +
1278 static_cast<size_t>(local_j) * leading_dimension];
1332 return myrank_ == 0;
1345 const bool linear =
context == lin_ictxt_;
1347 throw std::invalid_argument(
1348 "tile communicator needs an active grid");
1349 auto& row_comm = linear ? lin_tile_row_comm_ : tile_row_comm_;
1350 auto& col_comm = linear ? lin_tile_col_comm_ : tile_col_comm_;
1351 auto& rank_of = linear ? lin_tile_rank_of_ : tile_rank_of_;
1352 const int row = linear ? lin_myrow_ : myrow_;
1353 const int col = linear ? lin_mycol_ : mycol_;
1354 const int columns = linear ? 1 : npcol_;
1355 if (row_comm == MPI_COMM_NULL) {
1356 MPI_Comm_split(gpr_comm_, row, col, &row_comm);
1357 MPI_Comm_split(gpr_comm_, col, row, &col_comm);
1358 std::vector<int> coordinates(2 *
static_cast<std::size_t
>(nprocs_));
1359 const int mine[2] = {row, col};
1360 MPI_Allgather(mine, 2, MPI_INT, coordinates.data(), 2, MPI_INT,
1362 rank_of.assign(
static_cast<std::size_t
>(nprocs_), -1);
1363 for (
int r = 0; r < nprocs_; ++r)
1364 rank_of[
static_cast<std::size_t
>(coordinates[2 * r]) * columns +
1365 coordinates[2 * r + 1]] = r;
1367 return {row_comm, col_comm, rank_of};
1375 static int node_cpu_share(MPI_Comm node)
1380 const int known = sched_getaffinity(0,
sizeof(mine), &mine) == 0;
1381 int all_known = known;
1382 MPI_Allreduce(MPI_IN_PLACE, &all_known, 1, MPI_INT, MPI_MIN, node);
1384 MPI_Comm_size(node, &ranks);
1385 std::vector<cpu_set_t> masks(
static_cast<std::size_t
>(ranks));
1386 MPI_Allgather(&mine,
static_cast<int>(
sizeof(mine)), MPI_BYTE,
1387 masks.data(),
static_cast<int>(
sizeof(mine)), MPI_BYTE,
1389 if (!all_known || CPU_COUNT(&mine) <= 0)
return 0;
1391 for (cpu_set_t& other: masks) {
1393 CPU_AND(&common, &mine, &other);
1394 if (CPU_COUNT(&common) > 0) ++sharers;
1396 return std::max(1, CPU_COUNT(&mine) / std::max(1, sharers));
1405 void descriptor_grid(
const int* desc,
int& rows,
int& cols)
const
1407 int row = 0, col = 0;
1410 if (rows <= 0 || cols <= 0) {
1416 [[nodiscard]]
bool L_current() const noexcept
1421 void release_grids() noexcept
1423 if (tile_row_comm_ != MPI_COMM_NULL) MPI_Comm_free(&tile_row_comm_);
1424 if (tile_col_comm_ != MPI_COMM_NULL) MPI_Comm_free(&tile_col_comm_);
1425 if (lin_tile_row_comm_ != MPI_COMM_NULL)
1426 MPI_Comm_free(&lin_tile_row_comm_);
1427 if (lin_tile_col_comm_ != MPI_COMM_NULL)
1428 MPI_Comm_free(&lin_tile_col_comm_);
1429 tile_rank_of_.clear();
1430 lin_tile_rank_of_.clear();
1431 for (
int*
context: {&ictxt_, &lin_ictxt_, &col_ictxt_}) {
1436 system_handle_ = -1;
1437 blacs_communication_.reset();
1443 int nprow_ = 1, npcol_ = 1;
1444 int myrow_ = 0, mycol_ = 0;
1445 int nprocs_ = 1, myrank_ = 0;
1446 int node_ranks_ = 1;
1449 int configured_block_size_ = 0;
1450 int configured_nprow_ = 0;
1451 bool computation_tile_ =
false;
1452 bool initialized_ =
false;
1453 bool owns_mpi_ =
false;
1454 std::shared_ptr<const MpiCommunicator> communication_;
1455 std::unique_ptr<MpiCommunicator> blacs_communication_;
1456 int system_handle_ = -1;
1457 std::uint64_t grid_generation_ = 0;
1460 int lin_ictxt_ = -1;
1469 int col_ictxt_ = -1;
1473 std::vector<double> L_lin_cache_;
1474 int L_lin_desc_[9] = {};
1476 bool has_L_lin_ =
false;
1477 std::uint64_t L_lin_generation_ = 0;
1480 MPI_Comm gpr_comm_ = MPI_COMM_NULL;
1483 MPI_Comm tile_row_comm_ = MPI_COMM_NULL;
1484 MPI_Comm tile_col_comm_ = MPI_COMM_NULL;
1485 std::vector<int> tile_rank_of_;
1486 MPI_Comm lin_tile_row_comm_ = MPI_COMM_NULL;
1487 MPI_Comm lin_tile_col_comm_ = MPI_COMM_NULL;
1488 std::vector<int> lin_tile_rank_of_;
1491 std::vector<double> L_cache_;
1492 std::vector<double> U_cache_;
1493 bool has_U_ =
false;
1494 int L_desc_[9] = {};
1496 bool has_L_ =
false;
1497 std::uint64_t L_generation_ = 0;
1498 const void* L_owner_ =
nullptr;
1500 std::vector<double> Inv_cache_;
1501 int Inv_desc_[9] = {};
1503 bool has_inv_ =
false;
1504 std::uint64_t Inv_generation_ = 0;
1505 std::size_t inverse_builds_ = 0;
1512 struct DescCacheEntry {
1517 mutable std::vector<DescCacheEntry> desc_cache_;
1518 mutable std::mutex desc_cache_mutex_;
1536 if (!active_)
return;
1542 if (!active_)
return;
Index range of LP64 ScaLAPACK, PBLAS and BLACS on a descriptor.
Runtime loader for ScaLAPACK / BLACS symbols (dlopen + dlsym).
void Cblacs_gridinfo(int a, int *b, int *c, int *d, int *e)
int numroc_(const int *n, const int *nb, const int *iproc, const int *isrcproc, const int *nprocs)
void Cpdgemr2d(int m, int n, const double *a, int ia, int ja, const int *desca, double *b, int ib, int jb, const int *descb, int ictxt)
int Csys2blacs_handle(MPI_Comm communicator)
void Cblacs_gridexit(int a)
void Cfree_blacs_system_handle(int handle)
void descinit_(int *desc, const int *m, const int *n, const int *mb, const int *nb, const int *irsrc, const int *icsrc, const int *ictxt, const int *lld, int *info)
void Cblacs_gridinit(int *a, const char *b, int c, int d)
bool restore_cached_L(CholeskyFactorSnapshot snapshot, const void *owner)
void scatter_by_panels(const double *global, int m, int n, const int *desc, double *local, int row, int col, int nprow, int npcol) const
std::uint64_t grid_generation() const noexcept
void make_col_desc(int m, int n, int *desc) const
int local_rows(int m) const
static void release(std::vector< double > &buffer) noexcept
Returns the storage of buffer to the allocator.
bool exceeds_lp64(const int *desc) const
void configure(int block_size, int nprow, bool computation_tile=false) noexcept
const int * cached_inv_desc() const
static int recommended_block_size(int requested_block, int nprocs)
int effective_configured_block_size() const noexcept
int global_index_for_local(int local_index, int block_size, int proc_coord, int nprocs_dim) const
const std::shared_ptr< const MpiCommunicator > & communication() const noexcept
void make_lin_desc(int m, int n, int *desc) const
void cache_L(std::vector< double > L_dist, const int *desc, int n)
bool tile_kernels(const int *desc, const char *routine, const int *other=nullptr) const
bool has_cached_L() const
static constexpr DistributedBackendKind compiled_backend() noexcept
int configured_block_size() const noexcept
double * cached_L_lin_mut()
int lin_local_rows(int m) const
EigenMatrix gather(const double *local, const int *desc, int m, int n, bool broadcast_result=true) const
std::vector< double > scatter_lin(const EigenMatrix &global, int m, int n, int *desc) const
const double * cached_inv() const
static int recommended_nprow(int nprocs, int block_size)
void require_lp64(const int *desc, const char *routine) const
std::vector< double > scatter_colvector_root(const Eigen::VectorXd &global, int m, int *desc) const
MPI_Comm world_comm() const
void make_desc(int m, int n, int *desc) const
void cache_U(std::vector< double > U)
int local_index_for_global(int global_index, int block_size, int proc_coord, int nprocs_dim) const
const int * cached_L_desc() const
const double * cached_inv_block(int global_row, int global_col, int &leading_dimension) const
bool owns_global_entry(int global_row, int global_col) const
int local_cols(int n) const
int compute_ictxt() const
std::vector< double > scatter_lin_colvector_root(const Eigen::VectorXd &global, int m, int *desc) const
bool has_cached_L_lin() const
bool has_cached_inv() const
const char * backend_name() const noexcept
Eigen::VectorXd gather_colvector_root(const double *local, const int *desc, int m, bool broadcast_result=true) const
EigenMatrix gather_block(const double *local, const int *desc, int row0, int col0, int m, int n, bool broadcast_result=true) const
DistributedBackendKind backend_kind() const noexcept
TileCommunicators tile_communicators(int context=-1)
void cache_L_lin(std::vector< double > L_dist, const int *desc, int n)
DistributedState(std::shared_ptr< const MpiCommunicator > communication)
bool cached_L_owned_by(const void *owner) const noexcept
Eigen::VectorXd gather_lin_colvector_root(const double *local, const int *desc, int m) const
int col_block_nb(int n) const
double cached_inv_local_entry(int global_row, int global_col) const
bool cached_L_is_unowned() const noexcept
const double * cached_U() const
std::vector< double > scatter(const EigenMatrix &global, int m, int n, int *desc) const
static DistributedState & instance()
void claim_cached_L(const void *owner) noexcept
const int * cached_L_lin_desc() const
bool reproducible() const noexcept
void set_factorization(DistributedFactorization mode)
bool has_cached_U() const noexcept
std::vector< double > alloc_local(int m, int n, int *desc) const
std::size_t inverse_builds() const noexcept
DistributedFactorization factorization() const noexcept
void cache_inv(std::vector< double > inv_dist, const int *desc, int n)
int node_ranks() const noexcept
Ranks of this process group on this node (one before initialize).
int lin_local_cols(int n) const
int cpu_share() const noexcept
bool owns_lin_entry(int global_row, int global_col) const
void initialize(int block_size=0, int nprow=0)
static std::uint64_t factorization_generation() noexcept
CholeskyFactorSnapshot take_cached_L(const void *owner)
const double * cached_L() const
void invalidate_derived_cholesky()
void col_block_range(int n, int &start, int &count) const
int configured_nprow() const noexcept
const double * cached_L_lin() const
ScopedTileKernelThreads(const DistributedState &st)
~ScopedTileKernelThreads()
ScopedTileKernelThreads & operator=(const ScopedTileKernelThreads &)=delete
ScopedTileKernelThreads(const ScopedTileKernelThreads &)=delete
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
void setTileThreads(int threads) noexcept
Sets the tile thread count (at least one).
std::uint64_t distributedFactorizationGeneration() noexcept
std::int64_t lp64IndexLimit() noexcept
constexpr const char * distributed_backend_name(DistributedBackendKind backend) noexcept
void configureProductThreads(int threads)
constexpr std::int64_t largestLocalEntries(std::int64_t m, std::int64_t n, std::int64_t mb, std::int64_t nb, std::int64_t rsrc, std::int64_t csrc, std::int64_t nprow, std::int64_t npcol) noexcept
constexpr DistributedBackendKind compiled_distributed_backend() noexcept
bool exceedsLp64(const int *desc, int nprow, int npcol) noexcept
DistributedFactorization distributedFactorization() noexcept
Process-wide selection; Reproducible unless configured otherwise.
int configuredLinalgThreads() noexcept
Requested dense numerical budget, independent of nested BLAS controls.
void configureDistributedFactorization(DistributedFactorization mode)
std::atomic< int > & tileThreadCount() noexcept
Number of threads one rank devotes to independent tile products.
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
bool valid() const noexcept
std::array< int, 9 > descriptor
std::vector< double > values
const std::vector< int > & rank_of
indexed by row * npcol + col