Arcane  4.1.15.0
Developer documentation
Loading...
Searching...
No Matches
TestSequentialFor.cc
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#include <gtest/gtest.h>
9
10#include "arccore/base/ForLoopRanges.h"
11#include "arccore/base/MDSpan.h"
12
13#include "arccore/common/SequentialFor.h"
14#include "arccore/common/Array.h"
15#include "arccore/common/NumArray.h"
16
17using namespace Arcane;
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22template <typename IndexType_>
24{
25 public:
26
27 using IndexType = IndexType_;
28
29 public:
30
31 void doTest()
32 {
33 IndexType nb_dim1 = 20;
35 UniqueArray<IndexType> sum_array;
37 sum_array2.resize(nb_dim1);
38 IndexType ref_sum = {};
39 IndexType numarray_index = {};
40 auto f = [&](MDIndex<1, IndexType> index) {
41 IndexType i = index;
42 sum_array.add(i);
43 sum_array2[numarray_index] = i;
44 ++numarray_index;
45 ref_sum += i;
46 };
47 arccoreSequentialFor(loop1, f);
48 IndexType sum1 = {};
49 for (IndexType x : sum_array) {
50 sum1 += x;
51 }
52 IndexType sum2 = {};
53 for (IndexType x : sum_array2) {
54 sum2 += x;
55 }
56 ASSERT_EQ(ref_sum,sum2);
57 }
58};
59
60TEST(SequentialFor, Misc)
61{
62 LoopTester<Int32> int32_tester;
63 int32_tester.doTest();
64
65 LoopTester<Int64> int64_tester;
66 int64_tester.doTest();
67
68 LoopTester<size_t> size_t_tester;
69 size_t_tester.doTest();
70}
Types and functions associated with the MDSpan class.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Multi-dimensional arrays for numerical types accessible on accelerators.
void resize(ExtentIndexType dim1_size)
Resizes the array without keeping current values.
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
void arccoreSequentialFor(LoopBoundType< 1, IndexType > bounds, Lambda func, RemainingArgs... remaining_args)
Applies the functor func over a 1D loop.