MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
tassign.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_TEMPLATE_ASSIGN
13 #define MFEM_TEMPLATE_ASSIGN
14 
15 #include "../config/tconfig.hpp"
16 #include "backends.hpp"
17 
18 namespace mfem
19 {
20 
21 // Assignment operations
22 
23 struct AssignOp
24 {
25  enum Type
26  {
27  Set, // a = b
28  Add, // a += b
29  Mult, // a *= b
30  Div, // a /= b
31  rDiv // a = b/a
32  };
33 };
34 
35 namespace internal
36 {
37 
38 template <AssignOp::Type Op>
39 struct AssignOp_Impl;
40 
41 template <>
42 struct AssignOp_Impl<AssignOp::Set>
43 {
44  template <typename lvalue_t, typename rvalue_t>
45  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
46  {
47  return (a = b);
48  }
49 
50  template <typename lvalue_t, typename rvalue_t>
51  MFEM_HOST_DEVICE
52  static inline lvalue_t &AssignHD(lvalue_t &a, const rvalue_t &b)
53  {
54  return (a = b);
55  }
56 };
57 
58 template <>
59 struct AssignOp_Impl<AssignOp::Add>
60 {
61  template <typename lvalue_t, typename rvalue_t>
62  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
63  {
64  MFEM_FLOPS_ADD(1);
65  return (a += b);
66  }
67 
68  template <typename lvalue_t, typename rvalue_t>
69  MFEM_HOST_DEVICE
70  static inline lvalue_t &AssignHD(lvalue_t &a, const rvalue_t &b)
71  {
72  MFEM_FLOPS_ADD(1);
73  return (a += b);
74  }
75 };
76 
77 template <>
78 struct AssignOp_Impl<AssignOp::Mult>
79 {
80  template <typename lvalue_t, typename rvalue_t>
81  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
82  {
83  MFEM_FLOPS_ADD(1);
84  return (a *= b);
85  }
86 
87  template <typename lvalue_t, typename rvalue_t>
88  MFEM_HOST_DEVICE
89  static inline lvalue_t &AssignHD(lvalue_t &a, const rvalue_t &b)
90  {
91  MFEM_FLOPS_ADD(1);
92  return (a *= b);
93  }
94 };
95 
96 template <>
97 struct AssignOp_Impl<AssignOp::Div>
98 {
99  template <typename lvalue_t, typename rvalue_t>
100  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
101  {
102  MFEM_FLOPS_ADD(1);
103  return (a /= b);
104  }
105 
106  template <typename lvalue_t, typename rvalue_t>
107  MFEM_HOST_DEVICE
108  static inline lvalue_t &AssignHD(lvalue_t &a, const rvalue_t &b)
109  {
110  MFEM_FLOPS_ADD(1);
111  return (a /= b);
112  }
113 };
114 
115 template <>
116 struct AssignOp_Impl<AssignOp::rDiv>
117 {
118  template <typename lvalue_t, typename rvalue_t>
119  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
120  {
121  MFEM_FLOPS_ADD(1);
122  return (a = b/a);
123  }
124 
125  template <typename lvalue_t, typename rvalue_t>
126  MFEM_HOST_DEVICE
127  static inline lvalue_t &AssignHD(lvalue_t &a, const rvalue_t &b)
128  {
129  MFEM_FLOPS_ADD(1);
130  return (a = b/a);
131  }
132 };
133 
134 } // namespace mfem::internal
135 
136 template <AssignOp::Type Op, typename lvalue_t, typename rvalue_t>
137 inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
138 {
140 }
141 
142 template <AssignOp::Type Op, typename lvalue_t, typename rvalue_t>
143 MFEM_HOST_DEVICE
144 inline lvalue_t &AssignHD(lvalue_t &a, const rvalue_t &b)
145 {
147 }
148 
149 } // namespace mfem
150 
151 #endif // MFEM_TEMPLATE_ASSIGN
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
Definition: table.cpp:476
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
Definition: densemat.cpp:1928
double b
Definition: lissajous.cpp:42
MFEM_HOST_DEVICE lvalue_t & AssignHD(lvalue_t &a, const rvalue_t &b)
Definition: tassign.hpp:144
lvalue_t & Assign(lvalue_t &a, const rvalue_t &b)
Definition: tassign.hpp:137
double a
Definition: lissajous.cpp:41