Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
DistributedInnerProduct.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/* DistributedInnerProduct.h (C) 2000-2026 */
9/* */
10/* Distributed inner products of two vectors. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_MPI_DISTRIBUTEDINNERPRODUCT_H
13#define ARCCORE_ALINA_MPI_DISTRIBUTEDINNERPRODUCT_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/BuiltinBackend.h"
27#include "arccore/alina/ValueTypeInterface.h"
28#include "arccore/alina/MessagePassingUtils.h"
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane::Alina
34{
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
41struct DistributedInnerProduct
42{
44
45 explicit DistributedInnerProduct(mpi_communicator comm)
46 : comm(comm)
47 {}
48
49 template <class Vec1, class Vec2>
51 operator()(const Vec1& x, const Vec2& y) const
52 {
53 typedef typename backend::value_type<Vec1>::type value_type;
54 typedef typename math::inner_product_impl<value_type>::return_type coef_type;
55
56 ARCCORE_ALINA_TIC("inner product");
57 coef_type sum = comm.reduceSum(backend::inner_product(x, y));
58 ARCCORE_ALINA_TOC("inner product");
59
60 return sum;
61 }
62
63 int rank() const
64 {
65 return comm.rank;
66 }
67};
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72} // namespace Arcane::Alina
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77#endif
Default implementation for inner product.
Convenience wrapper around MPI_Comm.