|
17 | 17 | #include "SortedArray.hpp" |
18 | 18 | #include "ArrayOfArrays.hpp" |
19 | 19 | #include "CRSMatrix.hpp" |
| 20 | +#include "Macros.hpp" |
| 21 | + |
| 22 | + |
| 23 | +// TPL includes |
| 24 | +#include <RAJA/RAJA.hpp> |
20 | 25 |
|
21 | 26 | // System includes |
22 | 27 | #include <string> |
@@ -191,6 +196,74 @@ std::ostream & operator<< ( std::ostream & stream, CRSMatrixView< T const, COL_T |
191 | 196 | return stream; |
192 | 197 | } |
193 | 198 |
|
| 199 | + |
| 200 | +/** |
| 201 | + * @brief Macro to generate function to output a CRSMatrixView |
| 202 | + * @param COL_TYPE The type of index used to specify the column of the matrix. |
| 203 | + * @param INDEX_TYPE The type of index used to specify the row of the matrix. |
| 204 | + * @param LITOKEN A string literal to give the printf token for the row index type. |
| 205 | + * @param GITOKEN A string literal to give the printf token for the column index type. |
| 206 | + */ |
| 207 | +#define MAKE_PRINT_MATVIEW( COL_TYPE, INDEX_TYPE, LITOKEN, GITOKEN ) \ |
| 208 | +/** @brief Print a CRSMatrixView in a format that can be easily xxdiff'ed on */ \ |
| 209 | +/** the console. */ \ |
| 210 | +/** @tparam POLICY The policy for dummy kernel launch. */ \ |
| 211 | +/** @tparam T The type of the values in @p view. */ \ |
| 212 | +/** @tparam BUFFER_TYPE The type of buffer used by @p view. */ \ |
| 213 | +/** @param view The matrix view object to print. */ \ |
| 214 | + template< typename POLICY, \ |
| 215 | + typename T, \ |
| 216 | + template< typename > class BUFFER_TYPE > \ |
| 217 | + void print( CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > const & view ) \ |
| 218 | + { \ |
| 219 | + INDEX_TYPE const numRows = view.numRows(); \ |
| 220 | + \ |
| 221 | + \ |
| 222 | + printf( "numRows = %4" LITOKEN " \n", numRows ); \ |
| 223 | + RAJA::forall< POLICY >( RAJA::TypedRangeSegment< INDEX_TYPE >( 0, 1 ), [=] LVARRAY_HOST_DEVICE ( INDEX_TYPE const ) \ |
| 224 | + { \ |
| 225 | + INDEX_TYPE const * const ncols = view.getSizes(); \ |
| 226 | + INDEX_TYPE const * const row_indexes = view.getOffsets(); \ |
| 227 | + COL_TYPE const * const cols = view.getColumns(); \ |
| 228 | + T const * const values = view.getEntries(); \ |
| 229 | + \ |
| 230 | + printf( "ncols = { " ); for( INDEX_TYPE i=0; i<numRows; ++i ) \ |
| 231 | + { \ |
| 232 | + printf( "%4" LITOKEN ", ", ncols[i] ); \ |
| 233 | + } \ |
| 234 | + printf( " }\n" ); \ |
| 235 | + printf( "row_indexes = { " ); for( INDEX_TYPE i=0; i<numRows+1; ++i ) \ |
| 236 | + { \ |
| 237 | + printf( "%4" GITOKEN ", ", row_indexes[i] ); \ |
| 238 | + } \ |
| 239 | + printf( " }\n" ); \ |
| 240 | + \ |
| 241 | + \ |
| 242 | + printf( "row col value \n" ); \ |
| 243 | + printf( "---- --------- --------- \n" ); \ |
| 244 | + \ |
| 245 | + for( INDEX_TYPE i=0; i<numRows; ++i ) \ |
| 246 | + { \ |
| 247 | + printf( "%4" LITOKEN "\n", ncols[i] ); \ |
| 248 | + for( INDEX_TYPE j=0; j<ncols[i]; ++j ) \ |
| 249 | + { \ |
| 250 | + printf( "%4" LITOKEN " %9" GITOKEN " %9.2g\n", \ |
| 251 | + i, \ |
| 252 | + cols[row_indexes[i] + j], \ |
| 253 | + values[row_indexes[i] + j] ); \ |
| 254 | + } \ |
| 255 | + } \ |
| 256 | + \ |
| 257 | + } ); \ |
| 258 | + std::cout<<std::endl; \ |
| 259 | + } |
| 260 | + |
| 261 | +MAKE_PRINT_MATVIEW( int, int, "d", "d" ) |
| 262 | +MAKE_PRINT_MATVIEW( int, long long int, "d", "lld" ) |
| 263 | +MAKE_PRINT_MATVIEW( long int, long long int, "ld", "lld" ) |
| 264 | +MAKE_PRINT_MATVIEW( long long int, long long int, "lld", "lld" ) |
| 265 | + |
| 266 | + |
194 | 267 | /** |
195 | 268 | * @brief Output a c-array to a stream. |
196 | 269 | * @tparam T The type contained in the array. |
|
0 commit comments