177 static constexpr IT ZERO{0}, ONE{1}, NEGONE{-1};
178 static constexpr char SCOPE =
'A', TOP =
' ';
185 blacs_get(&NEGONE, &ZERO, &context);
186 blacs_gridinit(&context, &layout, &n_rows, &n_cols);
187 blacs_pinfo(&rank, &size);
188 blacs_gridinfo(&context, &n_rows, &n_cols, &my_row, &my_col);
192 if(context >= 0) blacs_gridexit(&context);
211 template<data_t DT>
auto copy_to(
const DT* A,
const IT* desc_a, DT* B,
const IT* desc_b) {
213 if(std::is_same_v<DT, double>) {
215 pdgemr2d(desc_a + 2, desc_a + 3, (E*)A, &ONE, &ONE, desc_a, (E*)B, &ONE, &ONE, desc_b, &context);
217 else if(std::is_same_v<DT, float>) {
219 psgemr2d(desc_a + 2, desc_a + 3, (E*)A, &ONE, &ONE, desc_a, (E*)B, &ONE, &ONE, desc_b, &context);
221 else if(std::is_same_v<DT, complex16>) {
223 pzgemr2d(desc_a + 2, desc_a + 3, (E*)A, &ONE, &ONE, desc_a, (E*)B, &ONE, &ONE, desc_b, &context);
225 else if(std::is_same_v<DT, complex8>) {
227 pcgemr2d(desc_a + 2, desc_a + 3, (E*)A, &ONE, &ONE, desc_a, (E*)B, &ONE, &ONE, desc_b, &context);
233 IT n_rows, n_cols, context{-1}, rank{-1}, size{-1}, my_row{-1}, my_col{-1};
242 const auto& env = get_env<IT>();
243 n_rows = std::max(IT{1},
static_cast<IT
>(std::sqrt(env.size())));
244 n_cols = env.size() / n_rows;
251 , n_cols(
cols) { init(); }
254 : layout(other.layout)
255 , n_rows(other.n_rows)
256 , n_cols(other.n_cols) { init(); }
275 auto desc_g(
const IT num_rows,
const IT num_cols) {
278 descinit(desc_t.data(), &num_rows, &num_cols, &num_rows, &num_cols, &ZERO, &ZERO, &context, &num_rows, &info);
300 const auto loc_lead = std::max(IT{1}, lead);
301 descinit(desc_t.data(), &num_rows, &num_cols, &
row_block, &
col_block, &ZERO, &ZERO, &context, &loc_lead, &info);
306 auto desc_l(
const IT num_rows,
const IT num_cols,
const IT block,
const IT lead) {
return desc_l(num_rows, num_cols, block, block, lead); }
308 template<data_t DT>
auto scatter(
const full_mat<DT, IT>& A,
const desc<IT>& desc_a, std::vector<DT>& B,
const desc<IT>& desc_b) {
309 if(!A.distributed)
return copy_to(A.data, desc_a.data(), B.data(), desc_b.data());
311 for(
auto i = 0u; i < B.size(); ++i) B[i] = A.data[i];
314 template<data_t DT>
auto gather(
const std::vector<DT>& A,
const desc<IT>& desc_a,
const full_mat<DT, IT>& B,
const desc<IT>& desc_b) {
315 if(!B.distributed)
return copy_to(A.data(), desc_a.data(), B.data, desc_b.data());
317 for(
auto i = 0u; i < A.size(); ++i) B.data[i] = A[i];
320 auto copy_to(
const IT* A,
const IT* desc_a, IT* B,
const IT* desc_b) { pigemr2d(desc_a + 2, desc_a + 3, A, &ONE, &ONE, desc_a, B, &ONE, &ONE, desc_b, &context); }
322 [[nodiscard]]
bool is_valid()
const {
return my_row >= 0 && my_col >= 0; }
327 auto row_block(
const IT n)
const {
return std::max(IT{1}, n / n_rows); }
332 auto col_block(
const IT n)
const {
return std::max(IT{1}, n / n_cols); }
344 auto rows(
const IT n,
const IT nb)
const {
return numroc(&n, &nb, &my_row, &ZERO, &n_rows); }
356 auto cols(
const IT n,
const IT nb)
const {
return numroc(&n, &nb, &my_col, &ZERO, &n_cols); }
372 igamx2d(&context, &SCOPE, &TOP, &ONE, &ONE, &number, &ONE,
nullptr,
nullptr, &NEGONE, &NEGONE, &NEGONE);
390 igamn2d(&context, &SCOPE, &TOP, &ONE, &ONE, &number, &ONE,
nullptr,
nullptr, &NEGONE, &NEGONE, &NEGONE);
Definition traits.hpp:176
IT amn(IT number) const
Perform the global amn operation.
Definition traits.hpp:389
auto desc_l(const IT num_rows, const IT num_cols, const IT row_block, const IT col_block, const IT lead)
Generates a descriptor for a local matrix.
Definition traits.hpp:297
auto rows(const IT n, const IT nb) const
Computes the number of local rows of the current process.
Definition traits.hpp:344
auto col_block(const IT n) const
Computes the column block size.
Definition traits.hpp:332
auto row_block(const IT n) const
Computes the row block size.
Definition traits.hpp:327
IT amx(IT number) const
Perform the global amx operation.
Definition traits.hpp:371
auto cols(const IT n, const IT nb) const
Computes the number of local columns of the current process.
Definition traits.hpp:356
auto desc_g(const IT num_rows, const IT num_cols)
Generates a descriptor for a global matrix.
Definition traits.hpp:275