Compadre  1.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Compadre_Functors.hpp
Go to the documentation of this file.
1 #ifndef _COMPADRE_FUNCTORS_HPP_
2 #define _COMPADRE_FUNCTORS_HPP_
3 
4 #include "Compadre_Operators.hpp"
6 
7 namespace Compadre {
8 
9 struct DefaultTag{
10  DefaultTag() {};
11  // intentionally empty
12 };
13 
15  int _rows, _cols;
18 
19  // Constructor
20  ConvertLayoutLeftToRight(const ParallelManager &pm, int rows, int cols, double* mat_ptr):
21  _rows(rows), _cols(cols), _permanent_mat_ptr(mat_ptr), _pm(pm) {};
22 
23  KOKKOS_INLINE_FUNCTION
24  void operator() (const member_type& teamMember) const {
25  // Create team member
26  const int local_index = teamMember.league_rank();
27  // Create a view for the left matrix type
29 
30  // Create a matrix data of layout right view living on the scratch memory
31  scratch_matrix_right_type local_mat_view(teamMember.team_scratch(_pm.getTeamScratchLevel(1)), _rows, _cols);
32 
33  // Create 1D array view of the memory
34  scratch_vector_type local_mat_view_flat(local_mat_view.data(), _rows*_cols);
35  scratch_vector_type permanent_mat_view_flat(permanent_mat_view.data(), _rows*_cols);
36 
37  // Copy and transpose the matrix from permanent memory into scratch memory
38  Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember, _rows), [=] (const int i) {
39  for (int j=0; j<_cols; j++) {
40  // Transpose the matrix
41  local_mat_view(i, j) = permanent_mat_view(i, j);
42  }
43  });
44  teamMember.team_barrier();
45 
46  // Now copy the flat 1D memory over
47  Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember, _rows*_cols), [=] (const int i) {
48  permanent_mat_view_flat(i) = local_mat_view_flat(i);
49  });
50  teamMember.team_barrier();
51  }
52 };
53 
55  int _rows, _cols;
58 
59  // Constructor
60  ConvertLayoutRightToLeft(const ParallelManager &pm, int rows, int cols, double* mat_ptr):
61  _rows(rows), _cols(cols), _permanent_mat_ptr(mat_ptr), _pm(pm) {};
62 
63  KOKKOS_INLINE_FUNCTION
64  void operator() (const member_type& teamMember) const {
65  // Create team member
66  const int local_index = teamMember.league_rank();
67  // Create a view for the right matrix type
69 
70  // Create a matrix data of layout left living on the scratch memory
71  scratch_matrix_left_type local_mat_view(teamMember.team_scratch(_pm.getTeamScratchLevel(1)), _rows, _cols);
72 
73  // Create 1D array view of the memory
74  scratch_vector_type local_mat_view_flat(local_mat_view.data(), _rows*_cols);
75  scratch_vector_type permanent_mat_view_flat(permanent_mat_view.data(), _rows*_cols);
76 
77  // Copy and transpose the matrix from permanent memory into scratch memory
78  Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember, _rows), [=] (const int i) {
79  for (int j=0; j<_cols; j++) {
80  // Transpose the matrix
81  local_mat_view(i, j) = permanent_mat_view(i, j);
82  }
83  });
84  teamMember.team_barrier();
85 
86  // Now copy the flat 1D memory over
87  Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember, _rows*_cols), [=] (const int i) {
88  permanent_mat_view_flat(i) = local_mat_view_flat(i);
89  });
90  teamMember.team_barrier();
91  }
92 };
93 
94 } // Compadre
95 
96 #endif
KOKKOS_INLINE_FUNCTION int getTeamScratchLevel(const int level) const
team_policy::member_type member_type
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
#define TO_GLOBAL(variable)
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
Kokkos::View< double **, layout_right, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_right_type
Kokkos::View< double *, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_vector_type
Kokkos::View< double **, layout_left, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_left_type
ConvertLayoutLeftToRight(const ParallelManager &pm, int rows, int cols, double *mat_ptr)
ConvertLayoutRightToLeft(const ParallelManager &pm, int rows, int cols, double *mat_ptr)