Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
DistributedCoarseningRuntime.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* DistributedCoarseningRuntime.h (C) 2000-2026 */
9/* */
10/* Runtime wrapper for distributed coarsening schemes. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_MPI_DISTRIBUTEDCOARSENINGRUNTIME_H
13#define ARCCORE_ALINA_MPI_DISTRIBUTEDCOARSENINGRUNTIME_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16/*
17 * This file is based on the work on AMGCL library (version march 2026)
18 * which can be found at https://github.com/ddemidov/amgcl.
19 *
20 * Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
21 * SPDX-License-Identifier: MIT
22 */
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26#include "arccore/alina/DistributedMatrix.h"
27#include "arccore/alina/DistributedCoarsening.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane::Alina
33{
34
35enum class eDistributedCoarseningType
36{
37 aggregation,
38 smoothed_aggregation
39};
40
41inline std::ostream& operator<<(std::ostream& os, eDistributedCoarseningType s)
42{
43 switch (s) {
44 case eDistributedCoarseningType::aggregation:
45 return os << "aggregation";
46 case eDistributedCoarseningType::smoothed_aggregation:
47 return os << "smoothed_aggregation";
48 default:
49 return os << "???";
50 }
51}
52
53inline std::istream& operator>>(std::istream& in, eDistributedCoarseningType& s)
54{
55 std::string val;
56 in >> val;
57
58 if (val == "aggregation")
59 s = eDistributedCoarseningType::aggregation;
60 else if (val == "smoothed_aggregation")
61 s = eDistributedCoarseningType::smoothed_aggregation;
62 else
63 throw std::invalid_argument("Invalid coarsening value. Valid choices are: "
64 "aggregation, smoothed_aggregation.");
65
66 return in;
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72template <class Backend>
73struct DistributedCoarseningRuntime
74{
75 typedef DistributedMatrix<Backend> matrix;
76 typedef PropertyTree params;
77
78 eDistributedCoarseningType c;
79 void* handle = nullptr;
80
81 explicit DistributedCoarseningRuntime(params prm = params())
82 : c(prm.get("type", eDistributedCoarseningType::smoothed_aggregation))
83 {
84 if (!prm.erase("type"))
85 ARCCORE_ALINA_PARAM_MISSING("type");
86
87 switch (c) {
88 case eDistributedCoarseningType::aggregation: {
90 handle = static_cast<void*>(new C(prm));
91 } break;
92 case eDistributedCoarseningType::smoothed_aggregation: {
94 handle = static_cast<void*>(new C(prm));
95 } break;
96 default:
97 throw std::invalid_argument("Unsupported coarsening type");
98 }
99 }
100
101 ~DistributedCoarseningRuntime()
102 {
103 switch (c) {
104 case eDistributedCoarseningType::aggregation: {
106 delete static_cast<C*>(handle);
107 } break;
108 case eDistributedCoarseningType::smoothed_aggregation: {
110 delete static_cast<C*>(handle);
111 } break;
112 default:
113 break;
114 }
115 }
116
117 std::tuple<std::shared_ptr<matrix>, std::shared_ptr<matrix>>
118 transfer_operators(const matrix& A)
119 {
120 switch (c) {
121 case eDistributedCoarseningType::aggregation: {
123 return static_cast<C*>(handle)->transfer_operators(A);
124 }
125 case eDistributedCoarseningType::smoothed_aggregation: {
127 return static_cast<C*>(handle)->transfer_operators(A);
128 }
129 default:
130 throw std::invalid_argument("Unsupported partition type");
131 }
132 }
133
134 std::shared_ptr<matrix>
135 coarse_operator(const matrix& A, const matrix& P, const matrix& R) const
136 {
137 switch (c) {
138 case eDistributedCoarseningType::aggregation: {
140 return static_cast<C*>(handle)->coarse_operator(A, P, R);
141 }
142 case eDistributedCoarseningType::smoothed_aggregation: {
144 return static_cast<C*>(handle)->coarse_operator(A, P, R);
145 }
146 default:
147 throw std::invalid_argument("Unsupported partition type");
148 }
149 }
150 friend std::ostream& operator<<(std::ostream& os, const DistributedCoarseningRuntime& w)
151 {
152 os << "Coarsening: " << w.c << "\n";
153 return os;
154 }
155};
156
157template <class Backend>
158unsigned block_size(const DistributedCoarseningRuntime<Backend>& w)
159{
160 switch (w.c) {
161 case eDistributedCoarseningType::aggregation: {
163 return block_size(*static_cast<const C*>(w.handle));
164 }
165 case eDistributedCoarseningType::smoothed_aggregation: {
166 typedef DistributedSmoothedAggregationCoarsening<Backend> C;
167 return block_size(*static_cast<const C*>(w.handle));
168 }
169 default:
170 throw std::invalid_argument("Unsupported coarsening type");
171 }
172}
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177} // namespace Arcane::Alina
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182#endif
Distributed Matrix using message passing.
Distributed non-smoothed aggregation coarsening scheme.
Distributed smoothed aggregation coarsening scheme.