| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2018 - 2025 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_trilinos_tpetra_communication_pattern_h |
| 16 |
#define dealii_trilinos_tpetra_communication_pattern_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/memory_space.h> |
| 22 |
|
| 23 |
#include <deal.II/lac/trilinos_tpetra_types.h> |
| 24 |
|
| 25 |
#ifdef DEAL_II_TRILINOS_WITH_TPETRA |
| 26 |
|
| 27 |
# include <deal.II/base/communication_pattern_base.h> |
| 28 |
# include <deal.II/base/memory_space.h> |
| 29 |
|
| 30 |
# include <Tpetra_Export.hpp> |
| 31 |
# include <Tpetra_Import.hpp> |
| 32 |
|
| 33 |
# include <memory> |
| 34 |
|
| 35 |
DEAL_II_NAMESPACE_OPEN |
| 36 |
|
| 37 |
namespace LinearAlgebra |
| 38 |
{ |
| 39 |
namespace TpetraWrappers |
| 40 |
{ |
| 41 |
/** |
| 42 |
* This class implements a wrapper to Tpetra::Import and Tpetra::Export. |
| 43 |
*/ |
| 44 |
template <typename MemorySpace = dealii::MemorySpace::Host> |
| 45 |
class CommunicationPattern : public Utilities::MPI::CommunicationPatternBase |
| 46 |
{ |
| 47 |
static_assert(std::is_same_v<MemorySpace, dealii::MemorySpace::Default> || |
| 48 |
std::is_same_v<MemorySpace, dealii::MemorySpace::Host>); |
| 49 |
|
| 50 |
public: |
| 51 |
/** |
| 52 |
* Initialize the communication pattern. |
| 53 |
* |
| 54 |
* @param[in] locally_owned_indices The set of indices of elements |
| 55 |
* in the array mentioned in the class documentation that are |
| 56 |
* stored on the current process. |
| 57 |
* @param[in] ghost_indices The set of indices of elements in the |
| 58 |
* array mentioned in the class documentation that the current |
| 59 |
* process will need to be able to import. |
| 60 |
* @param[in] communicator The MPI communicator used to describe the |
| 61 |
* entire set of processes that participate in the storage and |
| 62 |
* access to elements of the array. |
| 63 |
*/ |
| 64 |
CommunicationPattern(const IndexSet &locally_owned_indices, |
| 65 |
const IndexSet &ghost_indices, |
| 66 |
const MPI_Comm communicator); |
| 67 |
|
| 68 |
/** |
| 69 |
* Reinitialize the communication pattern. |
| 70 |
* |
| 71 |
* @param[in] locally_owned_indices The set of indices of elements |
| 72 |
* in the array mentioned in the class documentation that are |
| 73 |
* stored on the current process. |
| 74 |
* @param[in] ghost_indices The set of indices of elements in the |
| 75 |
* array mentioned in the class documentation that the current |
| 76 |
* process will need to be able to import. |
| 77 |
* @param[in] communicator The MPI communicator used to describe the |
| 78 |
* entire set of processes that participate in the storage and |
| 79 |
* access to elements of the array. |
| 80 |
*/ |
| 81 |
virtual void |
| 82 |
reinit(const IndexSet &locally_owned_indices, |
| 83 |
const IndexSet &ghost_indices, |
| 84 |
const MPI_Comm communicator) override; |
| 85 |
|
| 86 |
/** |
| 87 |
* Return the underlying MPI communicator. |
| 88 |
*/ |
| 89 |
virtual MPI_Comm |
| 90 |
get_mpi_communicator() const override; |
| 91 |
|
| 92 |
/** |
| 93 |
* Return the underlying Tpetra::Import object. |
| 94 |
*/ |
| 95 |
const TpetraTypes::ImportType<MemorySpace> & |
| 96 |
get_tpetra_import() const; |
| 97 |
|
| 98 |
/** |
| 99 |
* Return a Teuchos::RCP to the underlying Tpetra::Import object. |
| 100 |
*/ |
| 101 |
Teuchos::RCP<TpetraTypes::ImportType<MemorySpace>> |
| 102 |
get_tpetra_import_rcp() const; |
| 103 |
|
| 104 |
/** |
| 105 |
* Return the underlying Tpetra::Export object. |
| 106 |
*/ |
| 107 |
const TpetraTypes::ExportType<MemorySpace> & |
| 108 |
get_tpetra_export() const; |
| 109 |
|
| 110 |
/** |
| 111 |
* Return a Teuchos::RCP to the underlying Tpetra::Export object. |
| 112 |
*/ |
| 113 |
Teuchos::RCP<TpetraTypes::ExportType<MemorySpace>> |
| 114 |
get_tpetra_export_rcp() const; |
| 115 |
|
| 116 |
private: |
| 117 |
/** |
| 118 |
* Teuchos::RCP to the MPI communicator used. |
| 119 |
*/ |
| 120 |
Teuchos::RCP<const MPI_Comm> comm; |
| 121 |
|
| 122 |
/** |
| 123 |
* Teuchos::RCP to the Tpetra::Import object used. |
| 124 |
*/ |
| 125 |
Teuchos::RCP<TpetraTypes::ImportType<MemorySpace>> tpetra_import; |
| 126 |
|
| 127 |
/** |
| 128 |
* Teuchos::RCP to the Tpetra::Export object used. |
| 129 |
*/ |
| 130 |
Teuchos::RCP<TpetraTypes::ExportType<MemorySpace>> tpetra_export; |
| 131 |
}; |
| 132 |
} // end of namespace TpetraWrappers |
| 133 |
} // end of namespace LinearAlgebra |
| 134 |
|
| 135 |
DEAL_II_NAMESPACE_CLOSE |
| 136 |
|
| 137 |
#else |
| 138 |
|
| 139 |
// Make sure the scripts that create the C++20 module input files have |
| 140 |
// something to latch on if the preprocessor #ifdef above would |
| 141 |
// otherwise lead to an empty content of the file. |
| 142 |
DEAL_II_NAMESPACE_OPEN |
| 143 |
DEAL_II_NAMESPACE_CLOSE |
| 144 |
|
| 145 |
#endif |
| 146 |
|
| 147 |
#endif |