Loading...
Searching...
No Matches
MpiCommunicator.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3
4#include "MpiCommunicator.h"
5
6#include <stdexcept>
7
8namespace gpr::linalg {
9
11{
12#if defined(GPR_HAVE_MPI) || defined(GPR_LINALG_SCALAPACK)
13 if (source == MPI_COMM_NULL)
14 throw std::invalid_argument("cannot own a null MPI communicator");
15 view_ = MpiContext::fromCommunicator(source);
16 if (MPI_Comm_dup(source, &view_.comm) != MPI_SUCCESS)
17 throw std::runtime_error("could not duplicate MPI communicator");
18#else
19 (void)source;
20 throw std::logic_error("MPI communicator requires an MPI build");
21#endif
22}
23
25{
26#if defined(GPR_HAVE_MPI) || defined(GPR_LINALG_SCALAPACK)
27 int finalized = 0;
28 MPI_Finalized(&finalized);
29 if (!finalized && view_.comm != MPI_COMM_NULL) MPI_Comm_free(&view_.comm);
30#endif
31}
32
33} // namespace gpr::linalg
MpiCommunicator(MpiCommType source)
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
int MpiCommType
Definition MpiContext.h:55