GEOS
SolutionCheckKernelsHelpers.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPERS_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPERS_HPP
22 
23 #include "common/DataTypes.hpp"
24 
25 namespace geos
26 {
27 
28 class ElementsReporterBuffer;
29 
31 {
37 };
38 
46 {
47  friend class ElementsReporterBuffer;
48 public:
49 
50  using ElementCount = int32_t;
51 
57 
59  ElementsReporterCollector( ElementsReporterCollector const & other ) = default;
60 
62 
63  ElementsReporterCollector & operator=( ElementsReporterCollector const & other ) = default;
64 
65  ElementsReporterCollector & operator=( ElementsReporterCollector && other ) = default;
66 
69 
70  static ElementsReporterCollector disabled()
71  {
75  }
76 
83  template< typename CollectorAtomicPolicy >
85  void collectElement( CollectorAtomicPolicy, ElementReport const & report ) const
86  {
87  if( !m_elementsCounter.empty() )
88  {
89  ElementCount const outputStart = RAJA::atomicInc< CollectorAtomicPolicy >( &m_elementsCounter[0] );
90 
91  if( outputStart < m_elementsBuffer.size() )
92  {
93  m_elementsBuffer[outputStart].m_id = m_localToGlobalId[report.m_id];
94  m_elementsBuffer[outputStart].m_value = report.m_value;
95  }
96  }
97  }
98 
99  // // currently unused version for adding multiple ids from a given kernel
100  // template< typename AddedArray, typename ElementCount >
101  // GEOS_HOST_DEVICE
102  // void collectIds( AddedArray const & newIds, ElementCount newIdsCount )
103  // {
104  // ElementCount const outputStart = RAJA::atomicAdd< CollectorAtomicPolicy >( &m_elementsCounter[0], newIdsCount );
105  // ElementCount const maxNbIdToAdd = ElementCount( m_elementsBuffer.size() - outputStart );
106  // newIdsCount = LvArray::math::min( newIdsCount, maxNbIdToAdd );
107  // for( ElementCount i = 0; i < newIdsCount; ++i )
108  // {
109  // m_elementsBuffer[outputStart + i] = newIds[i];
110  // }
111  // }
112 
113 private:
114 
116  arrayView1d< ElementCount > m_elementsCounter;
117 
119  arrayView1d< ElementReport > m_elementsBuffer;
120 
122  arrayView1d< globalIndex const > m_localToGlobalId;
123 
125  arrayView1d< ElementReport > const & elementsBuffer,
126  arrayView1d< globalIndex const > const & localToGlobalId ):
127  m_elementsCounter( elementsCounter ),
128  m_elementsBuffer( elementsBuffer ),
129  m_localToGlobalId( localToGlobalId )
130  {}
131 
132 };
133 
134 } // namespace geos
135 
136 
137 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPERS_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
A buffer to count and store element ids during kernel execution. This facilitates the reporting mecha...
Collects and reports elements ids and data using an atomic counter. This class provides functionality...
GEOS_HOST_DEVICE void collectElement(CollectorAtomicPolicy, ElementReport const &report) const
Collects a single element report and adds its ID to the output buffer if not disabled and there are a...
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:87
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
globalIndex m_id
the global id of the reported element