MFEM  v4.1.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 "../general/cuda.hpp"
17 #include "../general/hip.hpp"
18 
19 namespace mfem
20 {
21 
22 // Assignment operations
23 
24 struct AssignOp
25 {
26  enum Type
27  {
28  Set, // a = b
29  Add, // a += b
30  Mult, // a *= b
31  Div, // a /= b
32  rDiv // a = b/a
33  };
34 };
35 
36 namespace internal
37 {
38 
39 template <AssignOp::Type Op>
40 struct AssignOp_Impl;
41 
42 template <>
43 struct AssignOp_Impl<AssignOp::Set>
44 {
45  template <typename lvalue_t, typename rvalue_t>
46  MFEM_HOST_DEVICE
47  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
48  {
49  return (a = b);
50  }
51 };
52 
53 template <>
54 struct AssignOp_Impl<AssignOp::Add>
55 {
56  template <typename lvalue_t, typename rvalue_t>
57  MFEM_HOST_DEVICE
58  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
59  {
60  MFEM_FLOPS_ADD(1);
61  return (a += b);
62  }
63 };
64 
65 template <>
66 struct AssignOp_Impl<AssignOp::Mult>
67 {
68  template <typename lvalue_t, typename rvalue_t>
69  MFEM_HOST_DEVICE
70  static inline lvalue_t &Assign(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::Div>
79 {
80  template <typename lvalue_t, typename rvalue_t>
81  MFEM_HOST_DEVICE
82  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
83  {
84  MFEM_FLOPS_ADD(1);
85  return (a /= b);
86  }
87 };
88 
89 template <>
90 struct AssignOp_Impl<AssignOp::rDiv>
91 {
92  template <typename lvalue_t, typename rvalue_t>
93  MFEM_HOST_DEVICE
94  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
95  {
96  MFEM_FLOPS_ADD(1);
97  return (a = b/a);
98  }
99 };
100 
101 } // namespace mfem::internal
102 
103 template <AssignOp::Type Op, typename lvalue_t, typename rvalue_t>
104 MFEM_HOST_DEVICE
105 inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
106 {
108 }
109 
110 } // namespace mfem
111 
112 #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:1926
double b
Definition: lissajous.cpp:42
double a
Definition: lissajous.cpp:41
MFEM_HOST_DEVICE lvalue_t & Assign(lvalue_t &a, const rvalue_t &b)
Definition: tassign.hpp:105