Skip to content

Commit 6fed1ae

Browse files
committed
Merge branch '71-bugs-of-blacs-context-when-sub-communicator-is-used' into 'master'
Resolve "Bugs of BLACS context when sub-communicator is used" Closes #71 See merge request chase/chase-library/ChASE!98
2 parents e57dac0 + c081686 commit 6fed1ae

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

external/scalapackpp/scalapackpp.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "algorithm/types.hpp"
1212

1313
#ifdef HAS_SCALAPACK
14+
#include <mpi.h>
15+
1416
/**
1517
* @page scalapackpp_namespace chase::linalg::scalapackpp Namespace
1618
* @brief A templated C++ interface to the ScaLAPACK library.
@@ -46,6 +48,12 @@ extern "C" void blacs_gridexit_(int*);
4648
extern "C" void blacs_gridmap_(int*, int*, int*, int*, int*);
4749
extern "C" int numroc_(std::size_t*, std::size_t*, int*, int*, int*);
4850

51+
// C BLACS interface (used to bind BLACS contexts to an MPI_Comm instead of MPI_COMM_WORLD)
52+
extern "C" int Csys2blacs_handle(MPI_Comm);
53+
extern "C" void Cblacs_gridinit(int*, char*, int, int);
54+
extern "C" void Cblacs_gridmap(int*, int*, int, int, int);
55+
extern "C" void Cblacs_gridexit(int);
56+
4957
extern "C" void pdgeqrf_(int*, int*, double*, int*, int*, int*, double*,
5058
double*, int*, int*);
5159
extern "C" void psgeqrf_(int*, int*, float*, int*, int*, int*, float*, float*,

grid/mpiGrid2D.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ class MpiGrid2D : public MpiGrid2DBase
414414
#endif
415415

416416
#ifdef HAS_SCALAPACK
417-
int zero = 0;
418417
int one = 1;
419-
int ictxt;
420-
chase::linalg::scalapackpp::blacs_get_(&zero, &zero, &ictxt);
418+
// Create BLACS contexts bound to the user communicator `comm_`
419+
// instead of relying on the global BLACS system context.
420+
int ictxt = chase::linalg::scalapackpp::Csys2blacs_handle(comm_);
421421
colComm1D_ctxt_ = ictxt;
422422
int userMap[dims_[0]];
423423
if (MajorOrder == GridMajor::ColMajor)
@@ -435,23 +435,24 @@ class MpiGrid2D : public MpiGrid2DBase
435435
}
436436
}
437437

438-
chase::linalg::scalapackpp::blacs_gridmap_(&colComm1D_ctxt_, userMap,
439-
&dims_[0], &dims_[0], &one);
440-
441-
int ictxt_2;
442-
chase::linalg::scalapackpp::blacs_get_(&zero, &zero, &ictxt_2);
438+
// 1D column communicator context (dims_[0] x 1 grid) using C BLACS
439+
chase::linalg::scalapackpp::Cblacs_gridmap(
440+
&colComm1D_ctxt_, userMap, dims_[0], dims_[0], 1);
441+
442+
// 2D BLACS grid context over the same communicator
443+
int ictxt_2 = chase::linalg::scalapackpp::Csys2blacs_handle(comm_);
443444
comm2D_ctxt_ = ictxt_2;
444445
if (MajorOrder == GridMajor::RowMajor)
445446
{
446447
char major = 'R';
447-
chase::linalg::scalapackpp::blacs_gridinit_(&comm2D_ctxt_, &major,
448-
&dims_[0], &dims_[1]);
448+
chase::linalg::scalapackpp::Cblacs_gridinit(&comm2D_ctxt_, &major,
449+
dims_[0], dims_[1]);
449450
}
450451
else
451452
{
452453
char major = 'C';
453-
chase::linalg::scalapackpp::blacs_gridinit_(&comm2D_ctxt_, &major,
454-
&dims_[0], &dims_[1]);
454+
chase::linalg::scalapackpp::Cblacs_gridinit(&comm2D_ctxt_, &major,
455+
dims_[0], dims_[1]);
455456
}
456457
#endif
457458
}

linalg/distMatrix/distMatrix.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,8 +2112,6 @@ class BlockBlockMatrix
21122112
int one = 1;
21132113
int info;
21142114
int comm2D_ctxt = mpi_grid_.get()->get_blacs_comm2D_ctxt();
2115-
int grank;
2116-
MPI_Comm_rank(MPI_COMM_WORLD, &grank);
21172115
if constexpr (std::is_same<Platform, chase::platform::GPU>::value)
21182116
{
21192117
if (local_matrix_.cpu_data() == nullptr)

0 commit comments

Comments
 (0)