diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 050cf586..8989cfa8 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -52,6 +52,9 @@ if (KOKKOS) add_definitions(-DHAVE_THREADS=1) endif() + add_executable(testsetval test_set_values.cpp) + target_link_libraries(testsetval ${LINKING_LIBRARIES}) + add_executable(mtestkokkos main_kokkos.cpp) target_link_libraries(mtestkokkos ${LINKING_LIBRARIES}) @@ -108,8 +111,10 @@ add_subdirectory(sparsetests) include_directories(test_rocm) add_subdirectory(test_rocm) -include_directories(laplaceMPI) -add_subdirectory(laplaceMPI) +if (MPI) + include_directories(laplaceMPI) + add_subdirectory(laplaceMPI) +endif() #include_directories(phaseField/srcKokkosVerbose) #add_subdirectory(phaseField/srcKokkosVerbose) diff --git a/examples/mtr-kokkos-simple.cpp b/examples/mtr-kokkos-simple.cpp index 4cf79c9f..b6a9d11b 100644 --- a/examples/mtr-kokkos-simple.cpp +++ b/examples/mtr-kokkos-simple.cpp @@ -126,8 +126,12 @@ int main(int argc, char *argv[]) { // Matrix examples following the Fortran index convention, // indicies go from 1 to N, first index varies the fastest - FMatrixDevice matrix1D(10); // declare and allocate a 1D matrix of size 10 - FMatrixDevice matrix2D(10,10); // declare and allocate a 2D matrix with sizes of 10 x 10 + FMatrixDevice matrix1D(10, "1D_FMatrix"); // declare and allocate a 1D matrix of size 10 + FMatrixDevice matrix2D(10,10, "2D_FMatrix"); // declare and allocate a 2D matrix with sizes of 10 x 10 + + std::cout<< "Name of 1D Matrix = "< +#include "matar.h" + +using namespace mtr; // matar namespace + +int main() +{ + // DENSE + int dim0 = 2; + int dim1 = 3; + int dim2 = 2; + + printf("HOST TYPES"); + + FArray testing (dim0,dim1,dim2); + ViewFArray testing2 (&testing(0,0,0),3,2); + testing.set_values(1.3); + testing2.set_values(2.6); + printf("ViewFArray set_values 2.6 writing over FArray set_values 1.3.\n"); + for (int i = 0; i < dim2; i++) { + for (int j = 0; j < dim1; j++) { + for (int k = 0; k < dim0; k++) { + printf("%.1f ", testing(k,j,i)); + } + } + } + printf("\n"); + for (int i = 0; i < dim2; i++) { + for (int j = 0; j < dim1; j++) { + printf("%.1f ", testing2(j,i)); + } + } + printf("\n"); + CArray testing3 (dim0,dim1,dim2); + ViewCArray testing4 (&testing3(0,0,0),3,2); + testing3.set_values(1.3); + testing4.set_values(2.6); + printf("ViewCArray set_values 2.6 writing over CArray set_values 1.3.\n"); + for (int i = 0; i < dim0; i++) { + for (int j = 0; j < dim1; j++) { + for (int k = 0; k < dim2; k++) { + printf("%.1f ", testing3(i,j,k)); + } + } + } + printf("\n"); + for (int i = 0; i < dim1; i++) { + for (int j = 0; j < dim2; j++) { + printf("%.1f ", testing4(i,j)); + } + } + printf("\n"); + CMatrix testing5 (dim0,dim1,dim2); + ViewCMatrix testing6 (&testing5(1,1,1),3,2); + testing5.set_values(1.3); + testing6.set_values(2.6); + printf("ViewCMatrix set_values 2.6 writing over CMatrix set_values 1.3.\n"); + for (int i = 1; i < dim0+1; i++) { + for (int j = 1; j < dim1+1; j++) { + for (int k = 1; k < dim2+1; k++) { + printf("%.1f ", testing5(i,j,k)); + } + } + } + printf("\n"); + for (int i = 1; i < dim1+1; i++) { + for (int j = 1; j < dim2+1; j++) { + printf("%.1f ", testing6(i,j)); + } + } + printf("\n"); + FMatrix testing7 (dim0,dim1,dim2); + ViewFMatrix testing8 (&testing7(1,1,1),3,2); + testing7.set_values(1.3); + testing8.set_values(2.6); + printf("ViewFMatrix set_values 2.6 writing over FMatrix set_values 1.3.\n"); + for (int i = 1; i < dim2+1; i++) { + for (int j = 1; j < dim1+1; j++) { + for (int k = 1; k < dim0+1; k++) { + printf("%.1f ", testing7(k,j,i)); + } + } + } + printf("\n"); + for (int i = 1; i < dim2+1; i++) { + for (int j = 1; j < dim1+1; j++) { + printf("%.1f ", testing8(j,i)); + } + } + printf("\n"); + + // RAGGEDS + CArray stridesright (3); + stridesright(0) = 2; + stridesright(1) = 3; + stridesright(2) = 2; + RaggedRightArray righttest (stridesright); + righttest.set_values(1.35); + printf("RaggedRightArray set to values of 1.35\n"); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < stridesright(i); j++) { + printf("%.2f ", righttest(i,j)); + } + } + printf("\n"); + CArray stridesdown (4); + stridesdown(0) = 2; + stridesdown(1) = 3; + stridesdown(2) = 2; + stridesdown(3) = 1; + RaggedDownArray downtest (stridesdown); + downtest.set_values(2.55); + printf("RaggedDownArray set to values of 2.55\n"); + for (int i = 0; i < 4; i++) { + for (int j = 0; j < stridesdown(i); j++) { + printf("%.2f ", downtest(j,i)); + } + } + printf("\n"); + DynamicRaggedRightArray dynright (3,4); + dynright.stride(0) = 1; + dynright.stride(1) = 3; + dynright.stride(2) = 2; + dynright.set_values(2.14); + dynright.set_values_sparse(1.35); + printf("The values within the populated strides of the DynamicRaggedRight are set to 1.35 and the data in the rest of the array is set to 2.14.\n"); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 4; j++) { + printf("%.2f ", dynright(i,j)); + } + printf("\n"); + } + DynamicRaggedDownArray dyndown (3,4); + dyndown.stride(0) = 1; + dyndown.stride(1) = 3; + dyndown.stride(2) = 2; + dyndown.stride(3) = 1; + dyndown.set_values(2.14); + dyndown.set_values_sparse(1.35); + printf("The values within the populated strides of the DynamicRaggedDown are set to 1.35 and the data in the rest of the array is set to 2.14.\n"); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 4; j++) { + printf("%.2f ", dyndown(i,j)); + } + printf("\n"); + } + printf("Ragged Right Array of Vectors, CSCArray, and CSRArray are not currently tested in this file as of 8/6/24.\n"); + + + printf("DUAL TYPES"); + Kokkos::initialize(); + { + DFArrayKokkos DFAtest (2, 3, 4); + DViewFArrayKokkos DVFAtest (&DFAtest(0, 0, 0), 3, 4); + DFAtest.set_values(1.25); + DVFAtest.set_values(2.34); + printf("DViewFArrayKokkos set_values 2.34 writing over DFArrayKokkos set_values 1.25.\n"); + FOR_ALL(i, 0, 4, + j, 0, 3, + k, 0, 2, { + printf("%.2f ", DFAtest(k,j,i)); + }); + printf("\n"); + FOR_ALL(i, 0, 4, + j, 0, 3,{ + printf("%.2f ", DVFAtest(j,i)); + }); + printf("\n"); + DFMatrixKokkos DFMtest (2, 3, 4); + DViewFMatrixKokkos DVFMtest (&DFMtest(1, 1, 1), 3, 4); + DFMtest.set_values(1.33); + DVFMtest.set_values(3.24); + printf("DViewFMatrixKokkos set_values 3.24 writing over DFMatrixKokkos set_values 1.33.\n"); + FOR_ALL(i, 1, 5, + j, 1, 4, + k, 1, 3, { + printf("%.2f ", DFMtest(k,j,i)); + }); + printf("\n"); + FOR_ALL(i, 1, 5, + j, 1, 4,{ + printf("%.2f ", DVFMtest(j,i)); + }); + printf("\n"); + DCArrayKokkos DCAtest (2, 3, 4); + DViewCArrayKokkos DVCAtest (&DCAtest(0, 0, 0), 3, 4); + DCAtest.set_values(1.53); + DVCAtest.set_values(2.33); + printf("DViewCArrayKokkos set_values 2.33 writing over DCArrayKokkos set_values 1.53.\n"); + FOR_ALL(i, 0, 4, + j, 0, 3, + k, 0, 2, { + printf("%.2f ", DCAtest(k,j,i)); + }); + printf("\n"); + FOR_ALL(i, 0, 4, + j, 0, 3,{ + printf("%.2f ", DVCAtest(j,i)); + }); + printf("\n"); + DCMatrixKokkos DCMtest (2, 3, 4); + DViewCMatrixKokkos DVCMtest (&DCMtest(1, 1, 1), 3, 4); + DCMtest.set_values(1.77); + DVCMtest.set_values(2.17); + printf("DViewCMatrixKokkos set_values 2.17 writing over DCMatrixKokkos set_values 1.77.\n"); + FOR_ALL(i, 1, 5, + j, 1, 4, + k, 1, 3, { + printf("%.2f ", DCMtest(k,j,i)); + }); + printf("\n"); + FOR_ALL(i, 1, 5, + j, 1, 4,{ + printf("%.2f ", DVCMtest(j,i)); + }); + printf("\n"); + + DynamicRaggedRightArrayKokkos dynrightK (3,4); + dynrightK.stride(0) = 1; + dynrightK.stride(1) = 3; + dynrightK.stride(2) = 2; + dynrightK.set_values(2.14); + dynrightK.set_values_sparse(1.35); + printf("The values within the populated strides of the DynamicRaggedRight are set to 1.35 and the data in the rest of the array is set to 2.14.\n"); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 4; j++) { + printf("%.2f ", dynrightK(i,j)); + } + printf("\n"); + } + DynamicRaggedDownArrayKokkos dyndownK (3,4); + dyndownK.stride(0) = 1; + dyndownK.stride(1) = 3; + dyndownK.stride(2) = 2; + dyndownK.stride(3) = 1; + dyndownK.set_values(2.14); + dyndownK.set_values_sparse(1.35); + printf("The values within the populated strides of the DynamicRaggedDown are set to 1.35 and the data in the rest of the array is set to 2.14.\n"); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 4; j++) { + printf("%.2f ", dyndownK(i,j)); + } + printf("\n"); + } + + } + Kokkos::finalize(); +} diff --git a/examples/test_set_values.cpp:Zone.Identifier b/examples/test_set_values.cpp:Zone.Identifier new file mode 100644 index 00000000..a45e1ac4 --- /dev/null +++ b/examples/test_set_values.cpp:Zone.Identifier @@ -0,0 +1,2 @@ +[ZoneTransfer] +ZoneId=3 diff --git a/src/include/host_types.h b/src/include/host_types.h index 296e31eb..3a15a589 100644 --- a/src/include/host_types.h +++ b/src/include/host_types.h @@ -156,6 +156,9 @@ class FArray { //return pointer T* pointer() const; + + // set values to input + void set_values(T val); // deconstructor ~FArray (); @@ -469,6 +472,15 @@ inline T* FArray::pointer() const { return array_.get(); } + +template +void FArray::set_values(T val) { + for(int i = 0; i < length_; i++) { + array_[i] = val; + } +} + + //delete FArray template FArray::~FArray(){} @@ -583,6 +595,9 @@ class ViewFArray { // return array order (rank) size_t order() const; + // set values to input + void set_values(T val); + // return pointer T* pointer() const; @@ -874,6 +889,13 @@ inline T* ViewFArray::pointer() const { return array_; } +template +void ViewFArray::set_values(T val) { + for(int i = 0; i < length_; i++) { + array_[i] = val; + } +} + //---end of ViewFArray class definitions--- @@ -980,6 +1002,9 @@ class FMatrix { //return pointer T* pointer() const; + // set values to input + void set_values(T val); + // Deconstructor ~FMatrix (); @@ -1291,6 +1316,13 @@ inline T* FMatrix::pointer() const{ return matrix_.get(); } +template +void FMatrix::set_values(T val) { + for(int i = 0; i < length_; i++) { + matrix_[i] = val; + } +} + template FMatrix::~FMatrix() {} @@ -1405,6 +1437,9 @@ class ViewFMatrix { // return matrix order (rank) size_t order() const; + // set values to input + void set_values(T val); + // return pointer T* pointer() const; @@ -1694,6 +1729,14 @@ template inline T* ViewFMatrix::pointer() const { return matrix_; } + +template +void ViewFMatrix::set_values(T val) { + for(int i = 0; i < length_; i++) { + matrix_[i] = val; + } +} + //-----end ViewFMatrix----- @@ -1802,6 +1845,9 @@ class CArray { //return pointer T* pointer() const; + // set values to input + void set_values(T val); + // Deconstructor ~CArray (); @@ -2125,6 +2171,13 @@ inline T* CArray::pointer() const{ return array_.get(); } +template +void CArray::set_values(T val) { + for(int i = 0; i < length_; i++) { + array_[i] = val; + } +} + //destructor template CArray::~CArray() {} @@ -2238,6 +2291,9 @@ class ViewCArray { // return array order (rank) size_t order() const; + // set values to input + void set_values(T val); + // return pointer T* pointer() const; @@ -2549,6 +2605,13 @@ inline T* ViewCArray::pointer() const { return array_; } +template +void ViewCArray::set_values(T val) { + for(int i = 0; i < length_; i++) { + array_[i] = val; + } +} + //---end of ViewCArray class definitions---- @@ -2655,6 +2718,9 @@ class CMatrix { //return pointer T* pointer() const; + // set values to input + void set_values(T val); + // deconstructor ~CMatrix( ); @@ -2973,6 +3039,13 @@ inline T* CMatrix::pointer() const{ return matrix_.get(); } +template +void CMatrix::set_values(T val) { + for(int i = 0; i < length_; i++) { + matrix_[i] = val; + } +} + // Destructor template CMatrix::~CMatrix(){} @@ -3088,6 +3161,9 @@ class ViewCMatrix { // return array order (rank) size_t order() const; + // set values to input + void set_values(T val); + // return pointer T* pointer() const; @@ -3383,6 +3459,13 @@ inline T* ViewCMatrix::pointer() const { return matrix_; } +template +void ViewCMatrix::set_values(T val) { + for(int i = 0; i < length_; i++) { + matrix_[i] = val; + } +} + //----end of ViewCMatrix class definitions---- @@ -3444,6 +3527,9 @@ class RaggedRightArray { RaggedRightArray& operator= (const RaggedRightArray &temp); + // set values to input + void set_values(T val); + // Destructor ~RaggedRightArray ( ); }; // End of RaggedRightArray @@ -3629,6 +3715,13 @@ inline size_t* RaggedRightArray::get_starts() const{ return start_index_.get(); } +template +void RaggedRightArray::set_values(T val) { + for(int i = 0; i < length_; i++) { + array_[i] = val; + } +} + // Destructor template RaggedRightArray::~RaggedRightArray () {} @@ -3696,6 +3789,9 @@ class RaggedRightArrayofVectors { RaggedRightArrayofVectors& operator= (const RaggedRightArrayofVectors &temp); + // set values to input + void set_values(T val); + // Destructor ~RaggedRightArrayofVectors ( ); }; // End of RaggedRightArray @@ -3887,6 +3983,13 @@ inline size_t* RaggedRightArrayofVectors::get_starts() const{ return start_index_.get(); } +template +void RaggedRightArrayofVectors::set_values(T val) { + for(int i = 0; i < length_; i++) { + array_[i] = val; + } +} + // Destructor template RaggedRightArrayofVectors::~RaggedRightArrayofVectors () {} @@ -3949,6 +4052,9 @@ class RaggedDownArray { //overload = operator RaggedDownArray& operator= (const RaggedDownArray &temp); + // set values to input + void set_values(T val); + //destructor ~RaggedDownArray(); @@ -3966,7 +4072,7 @@ RaggedDownArray::RaggedDownArray() { template RaggedDownArray::RaggedDownArray( CArray &strides_array) { // Length of stride array - //dim2_ = strides_array.size(); + dim2_ = strides_array.size(); // Create and initialize startding indices start_index_ = std::shared_ptr (new size_t[(dim2_ + 1)]); // note the dim2+1 @@ -4131,6 +4237,13 @@ inline size_t* RaggedDownArray::get_starts() const{ return start_index_.get(); } +template +void RaggedDownArray::set_values(T val) { + for(int i = 0; i < length_; i++) { + array_[i] = val; + } +} + // Destructor template RaggedDownArray::~RaggedDownArray() {} @@ -4180,6 +4293,12 @@ class DynamicRaggedRightArray { // Overload copy assignment operator DynamicRaggedRightArray& operator= (const DynamicRaggedRightArray &temp); + // set values of array indices + void set_values(T val); + + // set values to only previously non-empty indices based upon stride value + void set_values_sparse(T val); + // Destructor ~DynamicRaggedRightArray (); }; @@ -4275,6 +4394,22 @@ inline T* DynamicRaggedRightArray::pointer() const{ return array_.get(); } +template +void DynamicRaggedRightArray::set_values(T val) { + for(int i = 0; i < length_; i++) { + array_[i] = val; + } +} + +template +void DynamicRaggedRightArray::set_values_sparse(T val) { + for(int i = 0; i < dim1_; i++) { + for(int j = 0; j < stride_[i]; j++) { + array_[dim2_*i+j] = val; + } + } +} + // Destructor template DynamicRaggedRightArray::~DynamicRaggedRightArray() {} @@ -4324,6 +4459,12 @@ class DynamicRaggedDownArray { //return pointer T* pointer() const; + + // set values of indices + void set_values(T val); + + // set values to input + void set_values_sparse(T val); // Destructor ~DynamicRaggedDownArray (); @@ -4422,6 +4563,22 @@ inline T* DynamicRaggedDownArray::pointer() const{ return array_.get(); } +template +void DynamicRaggedDownArray::set_values(T val) { + for(int i = 0; i < length_; i++) { + array_[i] = val; + } +} + +template +void DynamicRaggedDownArray::set_values_sparse(T val) { + for(int j = 0; j < dim2_; j++) { + for(int i = 0; i < stride_[j]; i++) { + array_[dim1_*j+i] = val; + } + } +} + // Destructor template DynamicRaggedDownArray::~DynamicRaggedDownArray() {} @@ -4572,6 +4729,10 @@ class CSRArray { int toCSC(CArray &array, CArray &start_index, CArray &row_index); void to_dense(CArray& A); + + // set values to input + void set_values(T val); + //destructor ~CSRArray(); @@ -4850,6 +5011,13 @@ int CSRArray::toCSC(CArray &data, CArray &col_ptrs, CArray return 0; } +template +void CSRArray::set_values(T val) { + for(int i = 0; i < nnz_; i++) { + array_[i] = val; + } +} + template CSRArray::~CSRArray() {} @@ -4987,6 +5155,10 @@ class CSCArray // Convertor int toCSR(CArray &data, CArray &row_ptrs, CArray &col_ptrs); void to_dense(FArray &A); + + // set values to input + void set_values(T val); + // destructor ~CSCArray(); }; @@ -5204,6 +5376,13 @@ int CSCArray::toCSR(CArray &data, CArray &col_ptrs, CArray return 0; } +template +void CSCArray::set_values(T val) { + for(int i = 0; i < nnz_; i++) { + array_[i] = val; + } +} + template CSCArray::~CSCArray() {} diff --git a/src/include/kokkos_types.h b/src/include/kokkos_types.h index e7bf319b..ff70bcfa 100644 --- a/src/include/kokkos_types.h +++ b/src/include/kokkos_types.h @@ -238,6 +238,10 @@ class FArrayKokkos { KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + // Destructor KOKKOS_INLINE_FUNCTION ~FArrayKokkos(); @@ -529,6 +533,14 @@ Kokkos::View FArrayKokkos +KOKKOS_INLINE_FUNCTION +const std::string FArrayKokkos::get_name() const{ + return this_array_.label(); +} + + // set values of array template KOKKOS_INLINE_FUNCTION @@ -629,6 +641,10 @@ class ViewFArrayKokkos { KOKKOS_INLINE_FUNCTION T* pointer() const; + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + KOKKOS_INLINE_FUNCTION ~ViewFArrayKokkos(); @@ -878,6 +894,14 @@ T* ViewFArrayKokkos::pointer() const { return this_array_; } +template +KOKKOS_INLINE_FUNCTION +void ViewFArrayKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_array_(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::~ViewFArrayKokkos() {} @@ -972,6 +996,10 @@ class FMatrixKokkos { KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + KOKKOS_INLINE_FUNCTION ~FMatrixKokkos(); @@ -1246,6 +1274,14 @@ Kokkos::View FMatrixKokkos +KOKKOS_INLINE_FUNCTION +const std::string FMatrixKokkos::get_name() const{ + return this_matrix_.label(); +} + + // set values of array template KOKKOS_INLINE_FUNCTION @@ -1347,6 +1383,10 @@ class ViewFMatrixKokkos { KOKKOS_INLINE_FUNCTION T* pointer() const; + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + KOKKOS_INLINE_FUNCTION ~ViewFMatrixKokkos(); @@ -1599,6 +1639,14 @@ T* ViewFMatrixKokkos::pointer() const { return this_matrix_; } +template +KOKKOS_INLINE_FUNCTION +void ViewFMatrixKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_matrix_(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::~ViewFMatrixKokkos() {} @@ -1704,6 +1752,16 @@ class DFArrayKokkos { // Method that update device view void update_device(); + + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Deconstructor KOKKOS_INLINE_FUNCTION ~DFArrayKokkos (); @@ -1995,6 +2053,21 @@ void DFArrayKokkos::update_device() { this_array_.template sync(); } +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DFArrayKokkos::get_name() const{ + return this_array_.view_host().label(); +} + +template +KOKKOS_INLINE_FUNCTION +void DFArrayKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_array_.h_view(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION DFArrayKokkos::~DFArrayKokkos() {} @@ -2107,6 +2180,16 @@ class DViewFArrayKokkos { // Method that update device view void update_device(); + + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Deconstructor KOKKOS_INLINE_FUNCTION ~DViewFArrayKokkos (); @@ -2445,6 +2528,21 @@ void DViewFArrayKokkos::update_device() { deep_copy(this_array_, this_array_host_); } +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DViewFArrayKokkos::get_name() const{ + return this_array_.label(); +} + +template +KOKKOS_INLINE_FUNCTION +void DViewFArrayKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_array_host_(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION DViewFArrayKokkos::~DViewFArrayKokkos() {} @@ -2547,6 +2645,16 @@ class DFMatrixKokkos { // Method that update device view void update_device(); + + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Deconstructor KOKKOS_INLINE_FUNCTION ~DFMatrixKokkos (); @@ -2838,6 +2946,21 @@ void DFMatrixKokkos::update_device() { this_matrix_.template sync(); } +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DFMatrixKokkos::get_name() const{ + return this_matrix_.view_host().label(); +} + +template +KOKKOS_INLINE_FUNCTION +void DFMatrixKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_matrix_.h_view(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION DFMatrixKokkos::~DFMatrixKokkos() {} @@ -2945,6 +3068,16 @@ class DViewFMatrixKokkos { // Method that update device view void update_device(); + + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Deconstructor KOKKOS_INLINE_FUNCTION ~DViewFMatrixKokkos (); @@ -3273,6 +3406,22 @@ void DViewFMatrixKokkos::update_device() { deep_copy(this_matrix_, this_matrix_host_); } +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DViewFMatrixKokkos::get_name() const{ + return this_matrix_.label(); +} + + +template +KOKKOS_INLINE_FUNCTION +void DViewFMatrixKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_matrix_host_(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION DViewFMatrixKokkos::~DViewFMatrixKokkos() {} @@ -3369,6 +3518,10 @@ class CArrayKokkos { KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + // Deconstructor KOKKOS_INLINE_FUNCTION ~CArrayKokkos (); @@ -3640,6 +3793,13 @@ Kokkos::View CArrayKokkos +KOKKOS_INLINE_FUNCTION +const std::string CArrayKokkos::get_name() const{ + return this_array_.label(); +} + // set values of array template KOKKOS_INLINE_FUNCTION @@ -3739,6 +3899,10 @@ class ViewCArrayKokkos { KOKKOS_INLINE_FUNCTION T* pointer() const; + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + KOKKOS_INLINE_FUNCTION ~ViewCArrayKokkos(); @@ -3986,6 +4150,14 @@ T* ViewCArrayKokkos::pointer() const { return this_array_; } +template +KOKKOS_INLINE_FUNCTION +void ViewCArrayKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_array_(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::~ViewCArrayKokkos() {} @@ -4079,6 +4251,10 @@ class CMatrixKokkos { KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + KOKKOS_INLINE_FUNCTION ~CMatrixKokkos(); @@ -4356,6 +4532,13 @@ Kokkos::View CMatrixKokkos +KOKKOS_INLINE_FUNCTION +const std::string CMatrixKokkos::get_name() const{ + return this_matrix_.label(); +} + // set values of array template KOKKOS_INLINE_FUNCTION @@ -4451,6 +4634,10 @@ class ViewCMatrixKokkos { KOKKOS_INLINE_FUNCTION T* pointer() const; + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + KOKKOS_INLINE_FUNCTION ~ViewCMatrixKokkos(); @@ -4695,6 +4882,14 @@ T* ViewCMatrixKokkos::pointer() const { return this_matrix_; } +template +KOKKOS_INLINE_FUNCTION +void ViewCMatrixKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_matrix_(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::~ViewCMatrixKokkos() {} @@ -4797,12 +4992,20 @@ class DCArrayKokkos { KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_dual_view() const; + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + // Method that update host view void update_host(); // Method that update device view void update_device(); + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + // Deconstructor KOKKOS_INLINE_FUNCTION ~DCArrayKokkos (); @@ -5086,6 +5289,13 @@ Kokkos::DualView DCArrayKokkos +KOKKOS_INLINE_FUNCTION +const std::string DCArrayKokkos::get_name() const{ + return this_array_.view_host().label(); +} + template void DCArrayKokkos::update_host() { @@ -5100,6 +5310,14 @@ void DCArrayKokkos::update_device() { this_array_.template sync(); } +template +KOKKOS_INLINE_FUNCTION +void DCArrayKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_array_.h_view(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION DCArrayKokkos::~DCArrayKokkos() {} @@ -5208,6 +5426,16 @@ class DViewCArrayKokkos { // Method that update device view void update_device(); + + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Deconstructor KOKKOS_INLINE_FUNCTION ~DViewCArrayKokkos (); @@ -5553,6 +5781,20 @@ void DViewCArrayKokkos::update_device() { deep_copy(this_array_, this_array_host_); } +template +KOKKOS_INLINE_FUNCTION +void DViewCArrayKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_array_host_(i) = val; + }); +} + +template +KOKKOS_INLINE_FUNCTION +const std::string DViewCArrayKokkos::get_name() const{ + return this_array_.label(); +} + template KOKKOS_INLINE_FUNCTION DViewCArrayKokkos::~DViewCArrayKokkos() {} @@ -5655,6 +5897,14 @@ class DCMatrixKokkos { // Method that update device view void update_device(); + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + // Deconstructor KOKKOS_INLINE_FUNCTION ~DCMatrixKokkos (); @@ -5947,6 +6197,21 @@ void DCMatrixKokkos::update_device() { this_matrix_.template sync(); } +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DCMatrixKokkos::get_name() const{ + return this_matrix_.view_host().label(); +} + +template +KOKKOS_INLINE_FUNCTION +void DCMatrixKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_matrix_.h_view(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION DCMatrixKokkos::~DCMatrixKokkos() {} @@ -6054,6 +6319,14 @@ class DViewCMatrixKokkos { // Method that update device view void update_device(); + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + // Deconstructor KOKKOS_INLINE_FUNCTION ~DViewCMatrixKokkos (); @@ -6382,6 +6655,21 @@ void DViewCMatrixKokkos::update_device() { deep_copy(this_matrix_, this_matrix_host_); } +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DViewCMatrixKokkos::get_name() const{ + return this_matrix_.label(); +} + +template +KOKKOS_INLINE_FUNCTION +void DViewCMatrixKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + this_matrix_host_(i) = val; + }); +} + template KOKKOS_INLINE_FUNCTION DViewCMatrixKokkos::~DViewCMatrixKokkos() {} @@ -6454,12 +6742,24 @@ class RaggedRightArrayKokkos { //setup start indices void data_setup(const std::string& tag_string); + //return pointer KOKKOS_INLINE_FUNCTION T* pointer(); //return the view KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); + + //print values + void print() const; + + //set values to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; // Kokkos views of strides and start indices Strides1D mystrides_; @@ -6780,6 +7080,22 @@ Kokkos::View RaggedRightArrayKokkos +KOKKOS_INLINE_FUNCTION +void RaggedRightArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_RaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { + array_(i) = val; + }); +} + +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string RaggedRightArrayKokkos::get_name() const{ + return array_.label(); +} + // Destructor template KOKKOS_INLINE_FUNCTION @@ -6856,6 +7172,10 @@ class RaggedRightArrayofVectorsKokkos { KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + // Kokkos views of strides and start indices Strides1D mystrides_; SArray1D start_index_; @@ -6936,6 +7256,10 @@ class RaggedRightArrayofVectorsKokkos { } }; + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + // Destructor KOKKOS_INLINE_FUNCTION ~RaggedRightArrayofVectorsKokkos ( ); @@ -7126,6 +7450,22 @@ Kokkos::View RaggedRightArrayofVectorsKokko return array_; } + +template +KOKKOS_INLINE_FUNCTION +void RaggedRightArrayofVectorsKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ + array_(i) = val; + }); +} + +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string RaggedRightArrayofVectorsKokkos::get_name() const{ + return array_.label(); +} + // Destructor template KOKKOS_INLINE_FUNCTION @@ -7179,15 +7519,27 @@ class RaggedDownArrayKokkos { KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; + //return pointer KOKKOS_INLINE_FUNCTION T* pointer(); //return the view KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; KOKKOS_INLINE_FUNCTION RaggedDownArrayKokkos& operator= (const RaggedDownArrayKokkos &temp); + + //print values + void print() const; + + //set values to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); // Kokkos views of strides and start indices Strides1D mystrides_; @@ -7243,6 +7595,10 @@ class RaggedDownArrayKokkos { } }; + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + // Destructor KOKKOS_INLINE_FUNCTION ~RaggedDownArrayKokkos ( ); @@ -7473,6 +7829,22 @@ Kokkos::View RaggedDownArrayKokkos +KOKKOS_INLINE_FUNCTION +void RaggedDownArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_RaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { + array_(i) = val; + }); +} + +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string RaggedDownArrayKokkos::get_name() const{ + return array_.label(); +} + // Destructor template KOKKOS_INLINE_FUNCTION @@ -7518,6 +7890,14 @@ class DynamicRaggedRightArrayKokkos { //return the view KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // set values to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); // Overload operator() to access data as array(i,j), // where i=[0:N-1], j=[stride(i)] @@ -7545,6 +7925,14 @@ class DynamicRaggedRightArrayKokkos { } }; + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // set values to only previously non-empty indices based upon stride value + KOKKOS_INLINE_FUNCTION + void set_values_sparse(T val); + // Destructor KOKKOS_INLINE_FUNCTION ~DynamicRaggedRightArrayKokkos (); @@ -7648,6 +8036,32 @@ Kokkos::View DynamicRaggedRightArrayKokkos< return array_; } +//set values to input +template +KOKKOS_INLINE_FUNCTION +void DynamicRaggedRightArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { + array_(i) = val; + }); +} + +template +KOKKOS_INLINE_FUNCTION +void DynamicRaggedRightArrayKokkos::set_values_sparse(T val) { + Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim1_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { + const int i_i = teamMember.league_rank(); + Kokkos::parallel_for( Kokkos::TeamThreadRange( teamMember, 0, stride_(i_i) ), [&] ( const int (j_j) ) { + array_(dim2_*i_i+j_j) = val; + }); + }); +} +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DynamicRaggedRightArrayKokkos::get_name() const{ + return array_.label(); +} + // Destructor template KOKKOS_INLINE_FUNCTION @@ -7696,6 +8110,14 @@ class DynamicRaggedDownArrayKokkos { //return the view KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + //set values to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); // Overload operator() to access data as array(i,j), // where i=[stride(j)], j=[0:N-1] @@ -7721,6 +8143,14 @@ class DynamicRaggedDownArrayKokkos { functor_strides_(index) = init_stride_; } }; + + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // set values to only previously non-empty indices based upon stride value + KOKKOS_INLINE_FUNCTION + void set_values_sparse(T val); // Destructor KOKKOS_INLINE_FUNCTION @@ -7826,6 +8256,32 @@ Kokkos::View DynamicRaggedDownArrayKokkos +KOKKOS_INLINE_FUNCTION +void DynamicRaggedDownArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicRaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { + array_(i) = val; + }); +} + +template +KOKKOS_INLINE_FUNCTION +void DynamicRaggedDownArrayKokkos::set_values_sparse(T val) { + Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim2_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { + const int j_j = teamMember.league_rank(); + Kokkos::parallel_for( Kokkos::TeamThreadRange( teamMember, 0, stride_(j_j) ), [&] ( const int (i_i) ) { + array_(dim1_*j_j+i_i) = val; + }); + }); +} +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DynamicRaggedDownArrayKokkos::get_name() const{ + return array_.label(); +} + // Destructor template KOKKOS_INLINE_FUNCTION @@ -7857,7 +8313,7 @@ class CSRArrayKokkos { CSRArrayKokkos(); //CSRArray(CArray data, CArray col_ptrs, CArray row_ptrs, size_t rows, size_t cols); - CSRArrayKokkos( + CSRArrayKokkos( CArrayKokkos &array, CArrayKokkos &start_index, CArrayKokkos &colum_index, @@ -8001,6 +8457,10 @@ class CSRArrayKokkos { // int toCSC(CArray &data, CArray &col_ptrs, CArray &row_ptrs); void to_dense(CArrayKokkos& A); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; class init_start_indices_functor{ public: @@ -8012,6 +8472,11 @@ class CSRArrayKokkos { mystart_index_(index) = 0; } }; + + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + //destructor KOKKOS_INLINE_FUNCTION ~CSRArrayKokkos(); @@ -8240,6 +8705,13 @@ T& CSRArrayKokkos::get_val_flat(size_t k) cons return array_.data()[k]; } +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string CSRArrayKokkos::get_name() const{ + return array_.label(); +} + template KOKKOS_INLINE_FUNCTION size_t CSRArrayKokkos::get_col_flat(size_t k) const{ @@ -8261,6 +8733,8 @@ int CSRArrayKokkos::flat_index(size_t i, size return -1; } + + //template //void CSRArrrayKokkos::from_dense(CArrayKokkos &starts, // CArrayKokkos &columns, @@ -8309,6 +8783,14 @@ int CSRArray::toCSC(CArray &data, CArray &col_ptrs, CArray } */ +template +KOKKOS_INLINE_FUNCTION +void CSRArrayKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, nnz_), KOKKOS_CLASS_LAMBDA(const int i){ + array_(i) = val; + }); +} + template CSRArrayKokkos::~CSRArrayKokkos() {} @@ -8329,159 +8811,168 @@ class CSCArrayKokkos public: - /** - * @brief Construct a new empty Sparse Col Array object - * - */ - CSCArrayKokkos(); - - /** - * @brief Construct a new Sparse Col Array object - * - * @param array: 1d array of data values in order as read top to bottom, left to right - * @param row_index: 1d array that marks what row each element is in - * @param start_index: 1d array that marks where the first element of each column starts - * @param dim1: number of rows the matrix should have - * @param dim2: number of columns the matrix should have - */ - CSCArrayKokkos( - CArrayKokkos &array, - CArrayKokkos &start_index, - CArrayKokkos &row_index, - size_t dim1, size_t dim2, const std::string & tag_string = DEFAULTSTRINGARRAY); + /** + * @brief Construct a new empty Sparse Col Array object + * + */ + CSCArrayKokkos(); + /** + * @brief Construct a new Sparse Col Array object + * + * @param array: 1d array of data values in order as read top to bottom, left to right + * @param row_index: 1d array that marks what row each element is in + * @param start_index: 1d array that marks where the first element of each column starts + * @param dim1: number of rows the matrix should have + * @param dim2: number of columns the matrix should have + */ + CSCArrayKokkos( + CArrayKokkos &array, + CArrayKokkos &start_index, + CArrayKokkos &row_index, + size_t dim1, size_t dim2, const std::string & tag_string = DEFAULTSTRINGARRAY); - /** - * @brief Access A(i,j). Returns a dummy address with value 0 if A(i,j) is not allocated - * - * @param i : row - * @param j : column - * @return T& : address of array_ that corresponds to A(i,j) - */ - KOKKOS_INLINE_FUNCTION - T &operator()(size_t i, size_t j) const; - - /** - * @brief Overloaded copy operator - * - * @param temp : Array to copy - * @return CSCArray& - */ - KOKKOS_INLINE_FUNCTION - CSCArrayKokkos &operator=(const CSCArrayKokkos &temp); - - /** - * @brief returns pointer to array_ - * - */ - KOKKOS_INLINE_FUNCTION - T *pointer() const; - - /** - * @brief Same functionality as nnz(i) included for compatibility with the rest of matar - * - * @param i : row - * @return size_t - */ - KOKKOS_INLINE_FUNCTION - size_t stride(size_t i) const; - - /** - * @brief Same functionality as operator() included for compatibility with the rest of matar - * - * @param i: row - * @param j: column - * @return T& - */ - KOKKOS_INLINE_FUNCTION - T &value(size_t i, size_t j) const; - - /** - * @brief Get the start_index array - * - * @return size_t* : returns start_index_ - */ - KOKKOS_INLINE_FUNCTION - size_t *get_starts() const; - - /** - * @brief Get number of rows - * - * @return size_t number of rows - */ - KOKKOS_INLINE_FUNCTION - size_t dim1() const; - - /** - * @brief Get number of columns - * - * @return size_t number of columns - */ - KOKKOS_INLINE_FUNCTION - size_t dim2() const; - - /** - * @brief iterator notation for iterating through the non zeros values of row i. - * - * @param i : row - * @return T* - */ - KOKKOS_INLINE_FUNCTION - T *begin(size_t i); - - /** - * @brief iterator notation for iterating through the non zeros values of row i. - * - * @param i : row - * @return T* - */ - KOKKOS_INLINE_FUNCTION - T *end(size_t i); - - // iterator for the raw data at row i - // i.e. return the index each element is the index in the 1 array - // This as the use of providing a reasonable way to get the column - // index and data value in the case you need both - KOKKOS_INLINE_FUNCTION - size_t begin_index(size_t i); - - KOKKOS_INLINE_FUNCTION - size_t end_index(size_t i); - - /** - * @brief Get the number of non zero elements in row i - * - * @param i : row to get - * @return size_t : size of row - */ - KOKKOS_INLINE_FUNCTION - size_t nnz(size_t i); - - /** - * @brief Get number of non zero elements total in array - * - * @return size_t - */ - KOKKOS_INLINE_FUNCTION - size_t nnz() const; - - // Use the index into the 1d array to get what value is stored there and what is the corresponding row - KOKKOS_INLINE_FUNCTION - T &get_val_flat(size_t k); - - KOKKOS_INLINE_FUNCTION - size_t get_row_flat(size_t k); - - // reverse map function from A(i,j) to what element of data/col_pt_ it corersponds to - KOKKOS_INLINE_FUNCTION - int flat_index(size_t i, size_t j); - - // Convertor - //int toCSR(CArray &data, CArray &row_ptrs, CArray &col_ptrs); - //void to_dense(FArray &A); - // destructor - KOKKOS_INLINE_FUNCTION - ~CSCArrayKokkos(); + + /** + * @brief Access A(i,j). Returns a dummy address with value 0 if A(i,j) is not allocated + * + * @param i : row + * @param j : column + * @return T& : address of array_ that corresponds to A(i,j) + */ + KOKKOS_INLINE_FUNCTION + T &operator()(size_t i, size_t j) const; + + /** + * @brief Overloaded copy operator + * + * @param temp : Array to copy + * @return CSCArray& + */ + KOKKOS_INLINE_FUNCTION + CSCArrayKokkos &operator=(const CSCArrayKokkos &temp); + + /** + * @brief returns pointer to array_ + * + */ + KOKKOS_INLINE_FUNCTION + T *pointer() const; + + /** + * @brief Same functionality as nnz(i) included for compatibility with the rest of matar + * + * @param i : row + * @return size_t + */ + KOKKOS_INLINE_FUNCTION + size_t stride(size_t i) const; + + /** + * @brief Same functionality as operator() included for compatibility with the rest of matar + * + * @param i: row + * @param j: column + * @return T& + */ + KOKKOS_INLINE_FUNCTION + T &value(size_t i, size_t j) const; + + /** + * @brief Get the start_index array + * + * @return size_t* : returns start_index_ + */ + KOKKOS_INLINE_FUNCTION + size_t *get_starts() const; + + /** + * @brief Get number of rows + * + * @return size_t number of rows + */ + KOKKOS_INLINE_FUNCTION + size_t dim1() const; + + /** + * @brief Get number of columns + * + * @return size_t number of columns + */ + KOKKOS_INLINE_FUNCTION + size_t dim2() const; + + /** + * @brief iterator notation for iterating through the non zeros values of row i. + * + * @param i : row + * @return T* + */ + KOKKOS_INLINE_FUNCTION + T *begin(size_t i); + + /** + * @brief iterator notation for iterating through the non zeros values of row i. + * + * @param i : row + * @return T* + */ + KOKKOS_INLINE_FUNCTION + T *end(size_t i); + + // iterator for the raw data at row i + // i.e. return the index each element is the index in the 1 array + // This as the use of providing a reasonable way to get the column + // index and data value in the case you need both + KOKKOS_INLINE_FUNCTION + size_t begin_index(size_t i); + + KOKKOS_INLINE_FUNCTION + size_t end_index(size_t i); + + /** + * @brief Get the number of non zero elements in row i + * + * @param i : row to get + * @return size_t : size of row + */ + KOKKOS_INLINE_FUNCTION + size_t nnz(size_t i); + + /** + * @brief Get number of non zero elements total in array + * + * @return size_t + */ + KOKKOS_INLINE_FUNCTION + size_t nnz() const; + + // Use the index into the 1d array to get what value is stored there and what is the corresponding row + KOKKOS_INLINE_FUNCTION + T &get_val_flat(size_t k); + + KOKKOS_INLINE_FUNCTION + size_t get_row_flat(size_t k); + + // reverse map function from A(i,j) to what element of data/col_pt_ it corersponds to + KOKKOS_INLINE_FUNCTION + int flat_index(size_t i, size_t j); + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Convertor + //int toCSR(CArray &data, CArray &row_ptrs, CArray &col_ptrs); + //void to_dense(FArray &A); + + // set values on host to input + KOKKOS_INLINE_FUNCTION + void set_values(T val); + + // destructor + KOKKOS_INLINE_FUNCTION + ~CSCArrayKokkos(); }; template @@ -8634,6 +9125,13 @@ T& CSCArrayKokkos::get_val_flat(size_t k){ return array_.data()[k]; } +template +KOKKOS_INLINE_FUNCTION +const std::string CSCArrayKokkos::get_name() const{ + return array_.label(); +} + + template KOKKOS_INLINE_FUNCTION size_t CSCArrayKokkos::get_row_flat(size_t k){ @@ -8655,6 +9153,14 @@ int CSCArrayKokkos::flat_index(size_t i, size return -1; } +template +KOKKOS_INLINE_FUNCTION +void CSCArrayKokkos::set_values(T val) { + Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, nnz_), KOKKOS_CLASS_LAMBDA(const int i){ + array_(i) = val; + }); +} + // Assumes that data, col_ptrs, and row_ptrs // have been allocated size already before this call // Returns the data in this csr format but as represented as the appropriatte vectors diff --git a/test/test_cases/CMakeLists.txt b/test/test_cases/CMakeLists.txt index 74feb6b4..6174042d 100644 --- a/test/test_cases/CMakeLists.txt +++ b/test/test_cases/CMakeLists.txt @@ -18,6 +18,9 @@ target_link_libraries(${This} add_executable(test_CArrayKokkos test_CArrayKokkos.cpp) target_link_libraries(test_CArrayKokkos matar gtest_main) +add_executable(test_DCArrayKokkos test_DCArrayKokkos.cpp) +target_link_libraries(test_DCArrayKokkos matar gtest_main) + if (KOKKOKS) target_link_libraries(${This} Kokkos::kokkos) diff --git a/test/test_cases/test_CArrayKokkos.cpp b/test/test_cases/test_CArrayKokkos.cpp index 845c8465..9f9e88bb 100644 --- a/test/test_cases/test_CArrayKokkos.cpp +++ b/test/test_cases/test_CArrayKokkos.cpp @@ -25,7 +25,7 @@ CArrayKokkos return_CArrayKokkos(int dims, std::vector sizes) A = CArrayKokkos(sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], "A_5D_CArrayKokkos"); } else if(dims == 6){ - A = CArrayKokkos(sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5], "A_7D_CArrayKokkos"); + A = CArrayKokkos(sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5], "A_6D_CArrayKokkos"); } else if(dims == 7){ A = CArrayKokkos(sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5], sizes[6], "A_7D_CArrayKokkos"); @@ -108,7 +108,7 @@ TEST(Test_CArrayKokkos, order) } -// Test order function +// Test pointer function TEST(Test_CArrayKokkos, pointer) { std::vector sizes; @@ -123,6 +123,29 @@ TEST(Test_CArrayKokkos, pointer) } } +// Test get name function +TEST(Test_CArrayKokkos, names) +{ + std::vector sizes; + std::vector names = { + "A_1D_CArrayKokkos", + "A_2D_CArrayKokkos", + "A_3D_CArrayKokkos", + "A_4D_CArrayKokkos", + "A_5D_CArrayKokkos", + "A_6D_CArrayKokkos", + "A_7D_CArrayKokkos" + }; + + for(int i = 0; i < 7; i++){ + + int dims = i+1; + sizes.push_back(dims*2); + CArrayKokkos A = return_CArrayKokkos(dims, sizes); + EXPECT_EQ(names[i], A.get_name()); + } +} + // Add test for late initialization TEST(Test_CArrayKokkos, late_init) { diff --git a/test/test_cases/test_DCArrayKokkos.cpp b/test/test_cases/test_DCArrayKokkos.cpp new file mode 100644 index 00000000..d919194b --- /dev/null +++ b/test/test_cases/test_DCArrayKokkos.cpp @@ -0,0 +1,192 @@ +#include "matar.h" +#include "gtest/gtest.h" +#include + +using namespace mtr; // matar namespace + +DCArrayKokkos return_DCArrayKokkos(int dims, std::vector sizes) +{ + + DCArrayKokkos A; + + if(dims == 1){ + A = DCArrayKokkos(sizes[0], "A_1D_DCArrayKokkos"); + } + else if(dims == 2){ + A = DCArrayKokkos(sizes[0], sizes[1], "A_2D_DCArrayKokkos"); + } + else if(dims == 3){ + A = DCArrayKokkos(sizes[0], sizes[1], sizes[2], "A_3D_DCArrayKokkos"); + } + else if(dims == 4){ + A = DCArrayKokkos(sizes[0], sizes[1], sizes[2], sizes[3], "A_4D_DCArrayKokkos"); + } + else if(dims == 5){ + A = DCArrayKokkos(sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], "A_5D_DCArrayKokkos"); + } + else if(dims == 6){ + A = DCArrayKokkos(sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5], "A_6D_DCArrayKokkos"); + } + else if(dims == 7){ + A = DCArrayKokkos(sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5], sizes[6], "A_7D_DCArrayKokkos"); + } + else{ + std::cout<<"Dims must be between 1 and 7 for DCArrayKokkos" << std::endl; + } + return A; +} + + +// Test size function +TEST(Test_DCArrayKokkos, size) +{ + std::vector sizes; // Size of each dimension + int val = 1; // Expected total length of data + + for(int i = 0; i < 7; i++){ + + int dims = i+1; + + sizes.push_back(dims*2); + + DCArrayKokkos A = return_DCArrayKokkos(dims, sizes); + val*= dims*2; + + EXPECT_EQ(val, A.size()); + } +} + + +// Test extent function +TEST(Test_DCArrayKokkos, extent) +{ + std::vector sizes; // Size of each dimension + int val = 1; // Expected total length of data + + for(int i = 0; i < 7; i++){ + + int dims = i+1; + + sizes.push_back(dims*2); + + DCArrayKokkos A = return_DCArrayKokkos(dims, sizes); + val*= dims*2; + + EXPECT_EQ(val, A.extent()); + } +} + +// Test dims function +TEST(Test_DCArrayKokkos, dims) +{ + + // Note: extend to other dims when initialized to zero + + std::vector sizes; + for(int i = 0; i < 7; i++){ + + int dims = i+1; + + sizes.push_back(dims*2); + + DCArrayKokkos A = return_DCArrayKokkos(dims, sizes); + + EXPECT_EQ(sizes[i], A.dims(i)); + } +} + +// Test order function +TEST(Test_DCArrayKokkos, order) +{ + std::vector sizes; + for(int i = 0; i < 7; i++){ + + int dims = i+1; + sizes.push_back(dims*2); + DCArrayKokkos A = return_DCArrayKokkos(dims, sizes); + EXPECT_EQ(dims, A.order()); + } +} + + +// Test get name function +TEST(Test_DCArrayKokkos, names) +{ + std::vector sizes; + std::vector names = { + "A_1D_DCArrayKokkos", + "A_2D_DCArrayKokkos", + "A_3D_DCArrayKokkos", + "A_4D_DCArrayKokkos", + "A_5D_DCArrayKokkos", + "A_6D_DCArrayKokkos", + "A_7D_DCArrayKokkos" + }; + + for(int i = 0; i < 7; i++){ + + int dims = i+1; + sizes.push_back(dims*2); + DCArrayKokkos A = return_DCArrayKokkos(dims, sizes); + EXPECT_EQ(names[i], A.get_name()); + } +} + +// Add test for late initialization +TEST(Test_DCArrayKokkos, late_init) +{ + std::vector sizes; // Size of each dimension + int val = 1; // Expected total length of data + + DCArrayKokkos A; + + for(int i = 0; i < 7; i++){ + + int dims = i+1; + + sizes.push_back(dims*2); + + A = return_DCArrayKokkos(dims, sizes); + val*= dims*2; + + EXPECT_EQ(val, A.size()); + } +} + + +// Add test for operator = overload +TEST(Test_DCArrayKokkos, eq_overload) +{ + const int size = 100; + DCArrayKokkos A(size, size); + + DCArrayKokkos B(size, size); + + for(int i = 0; i < size; i++){ + for(int j = 0; j < size; j++){ + A(i,j) = (double)i + (double)j; + } + } + + B = A; + + for(int i = 0; i < size; i++){ + for(int j = 0; j < size; j++){ + + EXPECT_EQ(B(i,j), (double)i + (double)j); + } + } +} + + +int main(int argc, char* argv[]) +{ + Kokkos::initialize(argc, argv); + { + int result = 0; + testing::InitGoogleTest(&argc, argv); + result = RUN_ALL_TESTS(); + return result; + } + Kokkos::finalize(); +} \ No newline at end of file