Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_transform.hpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Tpetra: Templated Linear Algebra Services Package
6 // Copyright (2008) 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 Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 // @HEADER
42 */
43 
44 #ifndef TPETRA_TRANSFORM_HPP
45 #define TPETRA_TRANSFORM_HPP
46 
47 #include "TpetraCore_config.h"
48 
52 
53 namespace Tpetra {
54 
73  template<class ExecutionSpace,
74  class GlobalDataStructure,
75  class UnaryFunctionType>
76  void
77  transform (const char kernelLabel[],
78  ExecutionSpace execSpace,
79  GlobalDataStructure& input,
80  GlobalDataStructure& output,
81  UnaryFunctionType f);
82 
99  template<class GlobalDataStructure,
100  class UnaryFunctionType>
101  void
102  transform (const char kernelLabel[],
103  GlobalDataStructure& input,
104  GlobalDataStructure& output,
105  UnaryFunctionType f);
106 
107  namespace Details {
108 
111  template<class ExecutionSpace,
112  class GlobalDataStructure>
113  struct Transform {
115  template<class UnaryFunctionType>
116  static void
117  transform (const char kernelLabel[],
118  ExecutionSpace execSpace,
119  GlobalDataStructure& input,
120  GlobalDataStructure& output,
121  UnaryFunctionType f);
122 
124  template<class BinaryFunctionType>
125  static void
126  transform (const char kernelLabel[],
127  ExecutionSpace execSpace,
128  GlobalDataStructure& input1,
129  GlobalDataStructure& input2,
130  GlobalDataStructure& output,
131  BinaryFunctionType f);
132  };
133 
134  } // namespace Details
135 
138  template<class ExecutionSpace,
139  class GlobalDataStructure,
140  class UnaryFunctionType>
141  void
142  transform (const char kernelLabel[],
143  ExecutionSpace execSpace,
144  GlobalDataStructure& input,
145  GlobalDataStructure& output,
146  UnaryFunctionType f)
147  {
148  using impl_type =
150  using UFT = UnaryFunctionType;
151 
152  impl_type::template transform<UFT> (kernelLabel, execSpace,
153  input, output, f);
154  }
155 
158  template<class GlobalDataStructure,
159  class UnaryFunctionType>
160  void
161  transform (const char kernelLabel[],
162  GlobalDataStructure& input,
163  GlobalDataStructure& output,
164  UnaryFunctionType f)
165  {
166  using execution_space =
167  typename GlobalDataStructure::device_type::execution_space;
168  using impl_type =
170  using UFT = UnaryFunctionType;
171 
172  execution_space execSpace;
173  impl_type::template transform<UFT> (kernelLabel, execSpace,
174  input, output, f);
175  }
176 
179  template<class ExecutionSpace,
180  class GlobalDataStructure,
181  class BinaryFunctionType>
182  void
183  transform (const char kernelLabel[],
184  ExecutionSpace execSpace,
185  GlobalDataStructure& input1,
186  GlobalDataStructure& input2,
187  GlobalDataStructure& output,
188  BinaryFunctionType f)
189  {
190  using impl_type =
192  using BFT = BinaryFunctionType;
193 
194  impl_type::template transform<BFT> (kernelLabel, execSpace,
195  input1, input2, output, f);
196  }
197 
198 } // namespace Tpetra
199 
200 #endif // TPETRA_TRANSFORM_HPP
Specialize this class to implement Tpetra::transform for specific GlobalDataStructure types...
void transform(const char kernelLabel[], ExecutionSpace execSpace, GlobalDataStructure &input, GlobalDataStructure &output, UnaryFunctionType f)
For each local entry input_i of input, assign f(input_i) to the corresponding local entry output_i of...
static void transform(const char kernelLabel[], ExecutionSpace execSpace, GlobalDataStructure &input, GlobalDataStructure &output, UnaryFunctionType f)
Unary transform: output_i = f(input_i).