Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
NumaVector.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/* NumaVector.h (C) 2000-2026 */
9/* */
10/* NUMA-aware vector container. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_NUMAVECTOR_H
13#define ARCCORE_ALINA_NUMAVECTOR_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/AlinaUtils.h"
27#include "arccore/alina/ValueTypeInterface.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane::Alina
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
40template <class T>
41class numa_vector
42{
43 public:
44
45 typedef T value_type;
46
47 numa_vector()
48 : n(0)
49 , p(0)
50 {}
51
52 explicit numa_vector(size_t n, bool init = true)
53 : n(n)
54 , p(new T[n])
55 {
56 if (init) {
57 arccoreParallelFor(0, n, ForLoopRunInfo{}, [&](Int32 begin, Int32 size) {
58 for (ptrdiff_t i = begin; i < (begin + size); ++i) {
59 p[i] = math::zero<T>();
60 }
61 });
62 }
63 }
64
65 void resize(size_t size, bool init = true)
66 {
67 delete[] p;
68 p = 0;
69
70 n = size;
71 p = new T[n];
72
73 if (init) {
74 arccoreParallelFor(0, n, ForLoopRunInfo{}, [&](Int32 begin, Int32 size) {
75 for (ptrdiff_t i = begin; i < (begin + size); ++i) {
76 p[i] = math::zero<T>();
77 }
78 });
79 }
80 }
81
82 template <class Vector>
83 numa_vector(const Vector& other,
84 typename std::enable_if<!std::is_integral<Vector>::value, int>::type = 0)
85 : n(other.size())
86 , p(new T[n])
87 {
88 arccoreParallelFor(0, n, ForLoopRunInfo{}, [&](Int32 begin, Int32 size) {
89 for (ptrdiff_t i = begin; i < (begin + size); ++i) {
90 p[i] = other[i];
91 }
92 });
93 }
94
95 template <class Iterator>
96 numa_vector(Iterator beg, Iterator end)
97 : n(std::distance(beg, end))
98 , p(new T[n])
99 {
100 static_assert(std::is_same<std::random_access_iterator_tag,
101 typename std::iterator_traits<Iterator>::iterator_category>::value,
102 "Iterator has to be random access");
103
104 arccoreParallelFor(0, n, ForLoopRunInfo{}, [&](Int32 begin, Int32 size) {
105 for (ptrdiff_t i = begin; i < (begin + size); ++i) {
106 p[i] = beg[i];
107 }
108 });
109 }
110
111 ~numa_vector()
112 {
113 delete[] p;
114 p = 0;
115 }
116
117 size_t size() const
118 {
119 return n;
120 }
121
122 const T& operator[](size_t i) const
123 {
124 return p[i];
125 }
126
127 T& operator[](size_t i)
128 {
129 return p[i];
130 }
131
132 const T* data() const
133 {
134 return p;
135 }
136
137 T* data()
138 {
139 return p;
140 }
141
142 void swap(numa_vector& other)
143 {
144 std::swap(n, other.n);
145 std::swap(p, other.p);
146 }
147
148 private:
149
150 size_t n = 0;
151 T* p = nullptr;
152};
153
154/*---------------------------------------------------------------------------*/
155/*---------------------------------------------------------------------------*/
156
157} // namespace Arcane::Alina
158
159/*---------------------------------------------------------------------------*/
160/*---------------------------------------------------------------------------*/
161
162#endif
Informations d'exécution d'une boucle.
Vector class, to be used by user.
void arccoreParallelFor(const ComplexForLoopRanges< RankValue > &loop_ranges, const ForLoopRunInfo &run_info, const LambdaType &lambda_function, const ReducerArgs &... reducer_args)
Applique en concurrence la fonction lambda lambda_function sur l'intervalle d'itération donné par loo...
Definition ParallelFor.h:85
std::int32_t Int32
Type entier signé sur 32 bits.