Kokkos Core Kernels Package  Version of the Day
Kokkos_StaticCrsGraph.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_STATICCRSGRAPH_HPP
45 #define KOKKOS_STATICCRSGRAPH_HPP
46 
47 #include <string>
48 #include <vector>
49 
50 #include <Kokkos_Core.hpp>
51 
52 namespace Kokkos {
53 
84 template< class DataType,
85  class Arg1Type,
86  class Arg2Type = void,
87  typename SizeType = typename ViewTraits<DataType*, Arg1Type, Arg2Type, void >::size_type>
89 private:
91 
92 public:
93  typedef DataType data_type;
94  typedef typename traits::array_layout array_layout;
95  typedef typename traits::execution_space execution_space;
96  typedef typename traits::device_type device_type;
97  typedef SizeType size_type;
98 
103 
104  entries_type entries;
105  row_map_type row_map;
106 
108  StaticCrsGraph () : entries(), row_map() {}
109 
111  StaticCrsGraph (const StaticCrsGraph& rhs) : entries (rhs.entries), row_map (rhs.row_map)
112  {}
113 
114  template<class EntriesType, class RowMapType>
115  StaticCrsGraph (const EntriesType& entries_,const RowMapType& row_map_) : entries (entries_), row_map (row_map_)
116  {}
117 
123  entries = rhs.entries;
124  row_map = rhs.row_map;
125  return *this;
126  }
127 
132 
133  KOKKOS_INLINE_FUNCTION
134  size_type numRows() const {
135  return (row_map.dimension_0 () != 0) ?
136  row_map.dimension_0 () - static_cast<size_type> (1) :
137  static_cast<size_type> (0);
138  }
139 };
140 
141 //----------------------------------------------------------------------------
142 
143 template< class StaticCrsGraphType , class InputSizeType >
144 typename StaticCrsGraphType::staticcrsgraph_type
145 create_staticcrsgraph( const std::string & label ,
146  const std::vector< InputSizeType > & input );
147 
148 template< class StaticCrsGraphType , class InputSizeType >
149 typename StaticCrsGraphType::staticcrsgraph_type
150 create_staticcrsgraph( const std::string & label ,
151  const std::vector< std::vector< InputSizeType > > & input );
152 
153 //----------------------------------------------------------------------------
154 
155 template< class DataType ,
156  class Arg1Type ,
157  class Arg2Type ,
158  typename SizeType >
159 typename StaticCrsGraph< DataType , Arg1Type , Arg2Type , SizeType >::HostMirror
160 create_mirror_view( const StaticCrsGraph<DataType,Arg1Type,Arg2Type,SizeType > & input );
161 
162 template< class DataType ,
163  class Arg1Type ,
164  class Arg2Type ,
165  typename SizeType >
166 typename StaticCrsGraph< DataType , Arg1Type , Arg2Type , SizeType >::HostMirror
167 create_mirror( const StaticCrsGraph<DataType,Arg1Type,Arg2Type,SizeType > & input );
168 
169 } // namespace Kokkos
170 
171 //----------------------------------------------------------------------------
172 //----------------------------------------------------------------------------
173 
174 #include <impl/Kokkos_StaticCrsGraph_factory.hpp>
175 
176 //----------------------------------------------------------------------------
177 //----------------------------------------------------------------------------
178 
179 namespace Kokkos {
180 namespace Impl {
181 
182 template< class GraphType >
183 struct StaticCrsGraphMaximumEntry {
184 
185  typedef typename GraphType::execution_space execution_space ;
186  typedef typename GraphType::data_type value_type ;
187 
188  const typename GraphType::entries_type entries ;
189 
190  StaticCrsGraphMaximumEntry( const GraphType & graph ) : entries( graph.entries ) {}
191 
192  KOKKOS_INLINE_FUNCTION
193  void operator()( const unsigned i , value_type & update ) const
194  { if ( update < entries(i) ) update = entries(i); }
195 
196  KOKKOS_INLINE_FUNCTION
197  void init( value_type & update ) const
198  { update = 0 ; }
199 
200  KOKKOS_INLINE_FUNCTION
201  void join( volatile value_type & update ,
202  volatile const value_type & input ) const
203  { if ( update < input ) update = input ; }
204 };
205 
206 }
207 
208 template< class DataType, class Arg1Type, class Arg2Type, typename SizeType >
209 DataType maximum_entry( const StaticCrsGraph< DataType , Arg1Type , Arg2Type , SizeType > & graph )
210 {
211  typedef StaticCrsGraph<DataType,Arg1Type,Arg2Type,SizeType> GraphType ;
212  typedef Impl::StaticCrsGraphMaximumEntry< GraphType > FunctorType ;
213 
214  DataType result = 0 ;
215  Kokkos::parallel_reduce( graph.entries.dimension_0(),
216  FunctorType(graph), result );
217  return result ;
218 }
219 
220 } // namespace Kokkos
221 
222 //----------------------------------------------------------------------------
223 //----------------------------------------------------------------------------
224 
225 #endif /* #ifndef KOKKOS_CRSARRAY_HPP */
226 
void parallel_reduce(const std::string &label, const PolicyType &policy, const FunctorType &functor, ReturnType &return_value, typename Impl::enable_if< Kokkos::Impl::is_execution_policy< PolicyType >::value >::type *=0)
Parallel reduction.
~StaticCrsGraph()
Destroy this view of the array. If the last view then allocated memory is deallocated.
StaticCrsGraph(const StaticCrsGraph &rhs)
Copy constructor (shallow copy).
Memory space for main process and CPU execution spaces.
void update(double alpha, const BlockedMultiVector &x, double beta, BlockedMultiVector &y)
StaticCrsGraph & operator=(const StaticCrsGraph &rhs)
Assign to a view of the rhs array. If the old view is the last view then allocated memory is dealloca...
Compressed row storage array.
Traits class for accessing attributes of a View.
StaticCrsGraph()
Construct an empty view.