Template Class CsrMatrix
Defined in File CsrMatrix.hpp
Class Documentation
-
template<typename RealT, typename IdxT>
class CsrMatrix Public Functions
-
CsrMatrix(IdxT n, IdxT m, IdxT nnz)
basic constructor. It DOES NOT allocate any memory!
- Parameters:
n – [in] - number of rows
m – [in] - number of columns
nnz – [in] - number of non-zeros
-
CsrMatrix(IdxT n, IdxT m, IdxT nnz, IdxT **rows, IdxT **cols, RealT **vals, memory::MemorySpace memspace_src = memory::HOST, memory::MemorySpace memspace_dst = memory::HOST)
Hijacking constructor.
- Parameters:
n – [in]
m – [in]
nnz – [in]
rows – [inout]
cols – [inout]
vals – [inout]
memspace_src – [in]
memspace_dst – [in]
-
void setNnz(IdxT nnz_new)
Set number of non-zeros.
- Parameters:
nnz_new – [in] - new number of non-zeros
-
int setUpdated(memory::MemorySpace what)
Tags
memspaceas updated.The method sets the boolean flag indicating that the
memspaceis updated. It automatically sets the other data mirror to non-updated. You would use this function if you update matrix data by accessing its raw pointers. In such case, the matrix has no way of knowing which data is most recent, so you have to tell it.Note
If you want to set both DEVICE and HOST memory to the same value use syncData function.
Warning
This is an expert-level function. Use only if you know what you are doing.
- Parameters:
memspace – [in] - memory space (HOST or DEVICE) to set to “updated”
- Returns:
0 if successful, -1 if not.
-
int setDataPointers(IdxT *row_data, IdxT *col_data, RealT *val_data, memory::MemorySpace memspace)
Set the pointers for matrix row, column, value data.
Useful if interfacing with other codes - this function only assigns pointers, but it does not allocate nor copy anything. The data ownership flags would be set to false (default).
- Parameters:
row_data – [in] - pointer to row data (array of integers)
col_data – [in] - pointer to column data (array of integers)
val_data – [in] - pointer to value data (array of real numbers)
memspace – [in] - memory space (HOST or DEVICE) of incoming data
- Returns:
0 if successful, 1 if not.
-
int destroyMatrixData(memory::MemorySpace memspace)
destroy matrix data (HOST or DEVICE) if the matrix owns it (will attempt to destroy all three arrays).
- Parameters:
memspace – [in] - memory space (HOST or DEVICE) of incoming data
- Returns:
0 if successful, -1 if not.
-
void print(std::ostream &file_out = std::cout, IdxT indexing_base = 0)
Prints matrix data.
- Parameters:
out – - Output stream where the matrix data is printed
-
int syncData(memory::MemorySpace memspace_out)
Sync data in memspace with the updated memory space.
See also
- Parameters:
memspace – - memory space to be synced up (HOST or DEVICE)
- Returns:
int - 0 if successful, error code otherwise
- Pre:
The memory space other than
memspacemust be up-to-date. Otherwise, this function will return an error.
-
int copyValues(const RealT *new_vals, memory::MemorySpace memspace_in, memory::MemorySpace memspace_out)
updata matrix values using the new_values provided either as HOST or as DEVICE array.
This function will copy the data (not just assign a pointer) and allocate if needed. It also sets ownership and update flags.
- Parameters:
new_vals – [in] - pointer to new values data (array of real numbers)
memspace_in – [in] - memory space (HOST or DEVICE) of new_vals
memspace_out – [in] - memory space (HOST or DEVICE) of matrix values to be updated.
- Returns:
0 if successful, -1 if not.
-
int setValuesPointer(RealT *new_vals, memory::MemorySpace memspace)
updata matrix values using the new_values provided either as HOST or as DEVICE array.
This function only assigns a pointer, but does not copy. It sets update flags.
- Parameters:
new_vals – [in] - pointer to new values data (array of real numbers)
memspace – [in] - memory space (HOST or DEVICE) of new_vals
- Returns:
0 if successful, -1 if not.
-
CsrMatrix(IdxT n, IdxT m, IdxT nnz)