Advanced Multi-Physics (AMP)
On-Line Documentation
CSRConstruct.h
Go to the documentation of this file.
1#ifndef included_AMP_CSRVisit
2#define included_AMP_CSRVisit
3
4#include "AMP/AMP_TPLs.h"
5#include "AMP/matrices/AMPCSRMatrixParameters.h"
6#include "AMP/matrices/CSRConfig.h"
7#include "AMP/matrices/CSRMatrix.h"
8#include "AMP/matrices/RawCSRMatrixParameters.h"
9#include "AMP/matrices/data/CSRMatrixData.h"
10
11#include "AMP/matrices/operations/MatrixOperations.h"
12#include "AMP/matrices/operations/default/CSRMatrixOperationsDefault.h"
13#ifdef AMP_USE_DEVICE
14 #include "AMP/matrices/operations/device/CSRMatrixOperationsDevice.h"
15#endif
16#ifdef AMP_USE_KOKKOS
17 #include "AMP/matrices/operations/kokkos/CSRMatrixOperationsKokkos.h"
18#endif
19
20namespace AMP::LinearAlgebra {
21
22template<typename T>
25
26 std::shared_ptr<T>
27 operator()( int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type )
28 {
29 switch ( get_alloc( mode ) ) {
30 case alloc::host:
31 return check_lidx<alloc::host>( fid, manager, class_type );
32 case alloc::device:
33 return check_lidx<alloc::device>( fid, manager, class_type );
34 case alloc::managed:
35 return check_lidx<alloc::managed>( fid, manager, class_type );
36 }
37 AMP_ERROR( "csr_visitor: mode not found!" );
38 }
39
40private:
41 template<alloc a, index l, index g, scalar s>
42 std::shared_ptr<T>
43 construct( int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type )
44 {
45 using config_t = CSRConfig<a, l, g, s>;
46 if constexpr ( is_config_built<config_t> ) { // avoid linker errors for missing
47 // instantiations
48 if constexpr ( std::is_same_v<Matrix, T> ) {
49 return std::make_shared<CSRMatrix<config_t>>( fid, manager );
50 } else if constexpr ( std::is_same_v<MatrixData, T> ) {
51 return std::make_shared<CSRMatrixData<config_t>>( fid, manager );
52 } else if constexpr ( std::is_same_v<MatrixOperations, T> ) {
53 if ( class_type == "CSRMatrixOperationsDefault" ) {
54 return std::make_shared<CSRMatrixOperationsDefault<config_t>>( fid, manager );
55 } else if ( class_type == "CSRMatrixOperationsDevice" ) {
56#if defined( AMP_USE_DEVICE )
57 return std::make_shared<CSRMatrixOperationsDevice<config_t>>( fid, manager );
58#else
59 AMP_ERROR( "AMP not configured for device" );
60 return nullptr;
61#endif
62 } else if ( class_type == "CSRMatrixOperationsKokkos" ) {
63#if defined( AMP_USE_KOKKOS )
64 return std::make_shared<CSRMatrixOperationsKokkos<config_t>>( fid, manager );
65#else
66 AMP_ERROR( "AMP not configured with Kokkos" );
67 return nullptr;
68#endif
69 } else {
70 AMP_ERROR( "Unknown MatrixOperations type" );
71 return nullptr;
72 }
73 } else if constexpr ( std::is_same_v<MatrixParametersBase, T> ) {
74 // hack to differentiate the two types
75 return std::make_shared<RawCSRMatrixParameters<config_t>>( fid, manager );
76 } else if constexpr ( std::is_same_v<MatrixParameters, T> ) {
77 return std::make_shared<AMPCSRMatrixParameters<config_t>>( fid, manager );
78 } else {
79 AMP_ERROR( "Can only construct CSRMatrix and CSRData at present" );
80 return nullptr;
81 }
82 }
83 AMP_ERROR( "csr_construct: mode not found!" );
84 }
85 template<alloc a, index l, index g>
86 std::shared_ptr<T>
87 check_scalar( int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type )
88 {
89 switch ( get_scalar( mode ) ) {
90 case scalar::f32:
91 return construct<a, l, g, scalar::f32>( fid, manager, class_type );
92 case scalar::f64:
93 return construct<a, l, g, scalar::f64>( fid, manager, class_type );
94 case scalar::fld:
95 return construct<a, l, g, scalar::fld>( fid, manager, class_type );
96 }
97 AMP_ERROR( "csr_visitor: mode not found!" );
98 }
99 template<alloc a, index l>
100 std::shared_ptr<T>
101 check_gidx( int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type )
102 {
103 switch ( get_gidx( mode ) ) {
104 case index::i32:
105 return check_scalar<a, l, index::i32>( fid, manager, class_type );
106 case index::i64:
107 return check_scalar<a, l, index::i64>( fid, manager, class_type );
108 case index::ill:
109 return check_scalar<a, l, index::ill>( fid, manager, class_type );
110 }
111 AMP_ERROR( "csr_visitor: mode not found!" );
112 }
113 template<alloc a>
114 std::shared_ptr<T>
115 check_lidx( int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type )
116 {
117 switch ( get_lidx( mode ) ) {
118 case index::i32:
119 return check_gidx<a, index::i32>( fid, manager, class_type );
120 case index::i64:
121 return check_gidx<a, index::i64>( fid, manager, class_type );
122 case index::ill:
123 return check_gidx<a, index::ill>( fid, manager, class_type );
124 }
125 AMP_ERROR( "csr_visitor: mode not found!" );
126 }
127};
128
129template<typename T>
131 int64_t fid,
133 const std::string &class_type = "" )
134{
135 csr_construct<T> constructCSR{ mode };
136 return constructCSR( fid, manager, class_type );
137}
138
139} // namespace AMP::LinearAlgebra
140#endif
Class to manage reading/writing restart data.
#define AMP_ERROR(MSG)
Throw error.
auto get_gidx(csr_mode mode)
Definition CSRConfig.h:347
auto csrConstruct(csr_mode mode, int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type="")
auto get_lidx(csr_mode mode)
Definition CSRConfig.h:346
auto get_alloc(csr_mode mode)
Definition CSRConfig.h:345
auto get_scalar(csr_mode mode)
Definition CSRConfig.h:348
std::shared_ptr< T > check_gidx(int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type)
std::shared_ptr< T > operator()(int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type)
std::shared_ptr< T > construct(int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type)
std::shared_ptr< T > check_scalar(int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type)
std::shared_ptr< T > check_lidx(int64_t fid, AMP::IO::RestartManager *manager, const std::string &class_type)



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:40.
Comments on this page