Advanced Multi-Physics (AMP)
On-Line Documentation
CSRVisit.h
Go to the documentation of this file.
1#ifndef included_AMP_CSRVisit
2#define included_AMP_CSRVisit
3
4#include "AMP/IO/RestartManager.h"
5#include "AMP/matrices/CSRConfig.h"
6#include "AMP/matrices/CSRMatrix.h"
7
8namespace AMP::LinearAlgebra {
9
10namespace detail {
11template<class C>
13template<class Head, class... Rest>
14struct list_begin<config_list<Head, Rest...>> {
15 using type = Head;
16};
17} // namespace detail
18
19template<class F>
22 std::shared_ptr<LinearAlgebra::Matrix> mat;
23 std::decay_t<F> f;
24
25 // use first built config to determing return type
27 using ret_t = std::invoke_result_t<std::decay_t<F>, std::shared_ptr<CSRMatrix<first_config>>>;
28
30 {
31 switch ( get_alloc( mode ) ) {
32 case alloc::host:
33 return check_lidx<alloc::host>();
34 case alloc::device:
35 return check_lidx<alloc::device>();
36 case alloc::managed:
37 return check_lidx<alloc::managed>();
38 }
39 AMP_ERROR( "csr_visitor: mode not found!" );
40 }
41
42private:
43 template<alloc a, index l, index g, scalar s>
45 {
46 using config_t = CSRConfig<a, l, g, s>;
47 if constexpr ( is_config_built<config_t> ) { // avoid linker errors for missing
48 // instantiations
49 auto ptr = std::dynamic_pointer_cast<CSRMatrix<config_t>>( mat );
50 AMP_DEBUG_ASSERT( ptr );
51 return std::forward<F>( f )( ptr );
52 }
53 AMP_ERROR( "csr_visitor: mode not found!" );
54 }
55 template<alloc a, index l, index g>
57 {
58 switch ( get_scalar( mode ) ) {
59 case scalar::f32:
60 return visit<a, l, g, scalar::f32>();
61 case scalar::f64:
62 return visit<a, l, g, scalar::f64>();
63 case scalar::fld:
64 return visit<a, l, g, scalar::fld>();
65 }
66 AMP_ERROR( "csr_visitor: mode not found!" );
67 }
68 template<alloc a, index l>
70 {
71 switch ( get_gidx( mode ) ) {
72 case index::i32:
73 return check_scalar<a, l, index::i32>();
74 case index::i64:
75 return check_scalar<a, l, index::i64>();
76 case index::ill:
77 return check_scalar<a, l, index::ill>();
78 }
79 AMP_ERROR( "csr_visitor: mode not found!" );
80 }
81 template<alloc a>
83 {
84 switch ( get_lidx( mode ) ) {
85 case index::i32:
86 return check_gidx<a, index::i32>();
87 case index::i64:
88 return check_gidx<a, index::i64>();
89 case index::ill:
90 return check_gidx<a, index::ill>();
91 }
92 AMP_ERROR( "csr_visitor: mode not found!" );
93 }
94};
95
96template<class F>
97csr_visitor( csr_mode, std::shared_ptr<Matrix>, F ) -> csr_visitor<F>;
98
105template<class F>
106auto csrVisit( std::shared_ptr<Matrix> mat, F &&f )
107{
108 auto mode = static_cast<csr_mode>( mat->mode() );
109 csr_visitor visit{ mode, mat, std::forward<F>( f ) };
110 return visit();
111}
112
113} // namespace AMP::LinearAlgebra
114#endif
#define AMP_DEBUG_ASSERT(EXP)
Assert error (debug only)
#define AMP_ERROR(MSG)
Throw error.
auto csrVisit(std::shared_ptr< Matrix > mat, F &&f)
Definition CSRVisit.h:106
auto get_gidx(csr_mode mode)
Definition CSRConfig.h:347
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< LinearAlgebra::Matrix > mat
Definition CSRVisit.h:22
std::invoke_result_t< std::decay_t< F >, std::shared_ptr< CSRMatrix< first_config > > > ret_t
Definition CSRVisit.h:27
typename detail::list_begin< built_configs >::type first_config
Definition CSRVisit.h:26



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