Skip to content

Commit

Permalink
Merge branch 'main' into Sarah
Browse files Browse the repository at this point in the history
  • Loading branch information
shankinsMechEng authored Sep 16, 2024
2 parents c2ad438 + 4f504bb commit 3d20a79
Show file tree
Hide file tree
Showing 12 changed files with 1,293 additions and 234 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
install-*
benchmark/benchmark*
build-matar-*
install/*
install/*
heffte/
Binary file added MATAR-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# MATAR
<p align="center"><img src="https://github.com/lanl/MATAR/blob/main/MATAR_Logo.png" width="350">
<p align="center"><img src="https://github.com/lanl/MATAR/blob/main/MATAR-logo.png" width="350">

MATAR is a C++ library that addresses the need for simple, fast, and memory-efficient multi-dimensional data representations for dense and sparse storage that arise with numerical methods and in software applications. The data representations are designed to perform well across multiple computer architectures, including CPUs and GPUs. MATAR allows users to easily create and use intricate data representations that are also portable across disparate architectures using Kokkos. The performance aspect is achieved by forcing contiguous memory layout (or as close to contiguous as possible) for multi-dimensional and multi-size dense or sparse MATrix and ARray (hence, MATAR) types. Results show that MATAR has the capability to improve memory utilization, performance, and programmer productivity in scientific computing. This is achieved by fitting more work into the available memory, minimizing memory loads required, and by loading memory in the most efficient order.

Expand Down
6 changes: 4 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,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)
Expand Down
8 changes: 6 additions & 2 deletions examples/mtr-kokkos-simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <real_t> matrix1D(10); // declare and allocate a 1D matrix of size 10
FMatrixDevice <real_t> matrix2D(10,10); // declare and allocate a 2D matrix with sizes of 10 x 10
FMatrixDevice <real_t> matrix1D(10, "1D_FMatrix"); // declare and allocate a 1D matrix of size 10
FMatrixDevice <real_t> matrix2D(10,10, "2D_FMatrix"); // declare and allocate a 2D matrix with sizes of 10 x 10

std::cout<< "Name of 1D Matrix = "<<matrix1D.get_name()<<std::endl;
std::cout<< "Name of 2D Matrix = "<<matrix2D.get_name()<<std::endl;


FMatrixDevice <real_t> matrix3D; // declare variable and allocate sizes and dimensions later
matrix3D = FMatrixDevice <real_t> (10,10,10); // allocate dimensions and sizes
Expand Down
268 changes: 233 additions & 35 deletions examples/test_set_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,246 @@

using namespace mtr; // matar namespace

int main(int argc, char* argv[])
int main()
{
// Test RaggedRightArrayKokkos
Kokkos::initialize(argc, argv);
{
// Create a CArrayKokkos for strides
CArrayKokkos<size_t, Kokkos::LayoutRight, Kokkos::DefaultExecutionSpace, Kokkos::MemoryTraits<0>> strides(3);

// Set up strides (this is just an example, adjust as needed)
Kokkos::parallel_for("SetStrides", 1, KOKKOS_LAMBDA(const int&) {
strides(0) = 3; // dim0
strides(1) = 9; // total elements in dim1
strides(2) = 18; // total elements overall
});
// DENSE
int dim0 = 2;
int dim1 = 3;
int dim2 = 2;

// Create RaggedRightArrayKokkos using the new constructor
RaggedRightArrayKokkos<double, Kokkos::LayoutRight, Kokkos::DefaultExecutionSpace, Kokkos::MemoryTraits<0>, Kokkos::LayoutRight> ragged_array(strides, "MyRaggedArray");
printf("HOST TYPES");

// Use the ragged array...
ragged_array.set_values(3.14);
ragged_array.print();
FArray <double> testing (dim0,dim1,dim2);
ViewFArray <double> 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 <double> testing3 (dim0,dim1,dim2);
ViewCArray <double> 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 <double> testing5 (dim0,dim1,dim2);
ViewCMatrix <double> 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 <double> testing7 (dim0,dim1,dim2);
ViewFMatrix <double> 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 <size_t> stridesright (3);
stridesright(0) = 2;
stridesright(1) = 3;
stridesright(2) = 2;
RaggedRightArray <double> 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 <size_t> stridesdown (4);
stridesdown(0) = 2;
stridesdown(1) = 3;
stridesdown(2) = 2;
stridesdown(3) = 1;
RaggedDownArray <double> 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 <double> 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");
}

// Test RaggedDownArrayKokkos
DynamicRaggedDownArray <double> 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();
{
// Create a CArrayKokkos for strides
CArrayKokkos<size_t, Kokkos::LayoutRight, Kokkos::DefaultExecutionSpace, Kokkos::MemoryTraits<0>> strides(3);

// Set up strides (this is just an example, adjust as needed)
Kokkos::parallel_for("SetStrides", 1, KOKKOS_LAMBDA(const int&) {
strides(0) = 2; // dim0
strides(1) = 6; // total elements in dim1
strides(2) = 12; // total elements overall
DFArrayKokkos <double> DFAtest (2, 3, 4);
DViewFArrayKokkos <double> 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 <double> DFMtest (2, 3, 4);
DViewFMatrixKokkos <double> 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 <double> DCAtest (2, 3, 4);
DViewCArrayKokkos <double> 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 <double> DCMtest (2, 3, 4);
DViewCMatrixKokkos <double> 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");

// Create RaggedRightArrayKokkos using the new constructor
RaggedDownArrayKokkos<double, Kokkos::LayoutRight, Kokkos::DefaultExecutionSpace, Kokkos::MemoryTraits<0>, Kokkos::LayoutRight> ragged_array(strides, "MyRaggedArray");
DynamicRaggedRightArrayKokkos <double> 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 <double> 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");
}

// Use the ragged array...
ragged_array.set_values(5.67);
ragged_array.print();
}
Kokkos::finalize();
return 0;
Kokkos::finalize();
}
2 changes: 2 additions & 0 deletions examples/test_set_values.cpp:Zone.Identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ZoneTransfer]
ZoneId=3
Loading

0 comments on commit 3d20a79

Please sign in to comment.