1 /* ----------------------------------------------------------------------
2    SPARTA - Stochastic PArallel Rarefied-gas Time-accurate Analyzer
3    http://sparta.sandia.gov
4    Steve Plimpton, sjplimp@sandia.gov, Michael Gallis, magalli@sandia.gov
5    Sandia National Laboratories
6 
7    Copyright (2014) Sandia Corporation.  Under the terms of Contract
8    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
9    certain rights in this software.  This software is distributed under
10    the GNU General Public License.
11 
12    See the README file in the top-level SPARTA directory.
13 ------------------------------------------------------------------------- */
14 
15 #ifndef SPARTA_KK_COPY_H
16 #define SPARTA_KK_COPY_H
17 
18 #include "grid_kokkos.h"
19 #include "domain_kokkos.h"
20 
21 // Need a copy of classes instantiated on the stack at the class level scope.
22 // However, this isn't directly possible due to issues with pointers.h
23 //  and Kokkos allocation tracking.
24 // This class is a workaround, using low-level memory operations.
25 
26 namespace SPARTA_NS {
27 
28 template <class ClassStyle>
29 class KKCopy {
30  public:
31   ClassStyle obj;
32 
KKCopy(SPARTA * sparta)33   KKCopy(SPARTA *sparta):
34   obj(sparta) {
35     ptr_temp = NULL;
36     obj.copy = 1;
37     save();
38   }
39 
~KKCopy()40   ~KKCopy() {}
41 
copy(ClassStyle * orig)42   void copy(ClassStyle* orig) {
43     memcpy(&obj, orig, sizeof(ClassStyle));
44     obj.copy = 1;
45   }
46 
uncopy()47   void uncopy() {
48     if (ptr_temp != NULL) {
49       memcpy(&obj, ptr_temp, sizeof(ClassStyle));
50       free(ptr_temp);
51       ptr_temp = NULL;
52     }
53     obj.copy = 0;
54     obj.copymode = 0;
55   }
56 
57  private:
58   ClassStyle* ptr_temp;
59 
save()60   void save() {
61     ptr_temp = (ClassStyle*) malloc(sizeof(ClassStyle));
62     memcpy(ptr_temp, &obj, sizeof(ClassStyle));
63   }
64 
65 };
66 
67 }
68 
69 #endif
70 
71 /* ERROR/WARNING messages:
72 
73 */
74