Skip to content

Commit 2f102d4

Browse files
authored
Merge pull request #1590 from LLNL/task/rhornung67/mv-sidre_array-example
Task/rhornung67/mv sidre array example
2 parents 939cdfd + c0938f4 commit 2f102d4

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/axom/sidre/examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set(example_sources
1717

1818
if(AXOM_ENABLE_MPI)
1919
set (example_parallel_sources
20-
sidre_array.cpp
20+
sidre_mcarray.cpp
2121
sidre_createdatastore.cpp
2222
sidre_external_array.cpp
2323
sidre_generateindex.cpp)
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ namespace sidre = axom::sidre;
2121

2222
int main(int argc, char** argv)
2323
{
24+
//
25+
// Basic MPI setup with global communicator
26+
//
2427
MPI_Init(&argc, &argv);
2528
MPI_Comm problem_comm = MPI_COMM_WORLD;
2629

@@ -31,15 +34,18 @@ int main(int argc, char** argv)
3134

3235
axom::slic::SimpleLogger logger;
3336

34-
// STEP 0: create the data store
37+
// STEP 0: create a data store instance, with one child group of root
3538
sidre::DataStore* dataStore1 = new sidre::DataStore();
3639
sidre::Group* root1 = dataStore1->getRoot();
3740

38-
// STEP 1: create an array with some data
41+
// STEP 1: Create a sidre::MCArray with data held in a Sidre View.
42+
// A sidre::MCArray is similar to axom::Array, except that
43+
// the array data can be accessed using a Sidre View.
3944
constexpr axom::IndexType NUM_NODES = 10;
4045
constexpr axom::IndexType DIMENSION = 4;
4146
sidre::MCArray<int> nodes_1(root1->createView("nodes_1/data"), NUM_NODES, DIMENSION);
4247

48+
// STEP 1a: Initialize array data values
4349
int value = 0;
4450
for(axom::IndexType i = 0; i < NUM_NODES; ++i)
4551
{
@@ -51,35 +57,43 @@ int main(int argc, char** argv)
5157
} // END for all nodes
5258

5359
// DEBUG
60+
// STEP 1b: Print contents of data store showing that array data is in View
5461
SLIC_INFO("Here is the array data in DataStore_1:\n");
5562
root1->print();
5663
std::cout << std::endl;
5764
// END DEBUG
5865

59-
// STEP 2: save the array data in to a file
66+
// STEP 2: Write out the data store contents to a file.
6067
sidre::IOManager sidre_io(problem_comm);
6168
#if defined(AXOM_USE_HDF5)
6269
sidre_io.write(root1, nranks, "sidre_array_mesh", "sidre_hdf5");
6370
#else
6471
sidre_io.write(root1, nranks, "sidre_array_mesh", "sidre_conduit_json");
6572
#endif
6673

67-
// STEP 3: read the data from the file into a new DataStore
74+
// STEP 3: Create a new data store object and read the data from the
75+
// file into it.
6876
sidre::DataStore* dataStore2 = new sidre::DataStore();
6977
sidre::Group* root2 = dataStore2->getRoot();
7078
sidre_io.read(root2, "sidre_array_mesh.root");
7179

7280
// DEBUG
81+
// STEP 3a: Print contents of data store showing that array data was
82+
// read into a View
7383
SLIC_INFO("Here is the array data in DataStore_2:\n");
7484
root2->print();
7585
std::cout << std::endl;
7686
// END DEBUG
7787

88+
// STEP 3b: Create a new sidre::MCArray with data held in a View in the
89+
// new data store. Verify that the shape and size of the data is
90+
// what it is expected to be.
7891
sidre::MCArray<int> nodes_2(root2->getView("nodes_1/data"));
7992
SLIC_ASSERT(nodes_2.shape()[0] == NUM_NODES);
8093
SLIC_ASSERT(nodes_2.shape()[1] == DIMENSION);
8194

82-
// STEP 4: ensure the data is correct
95+
// STEP 4: Check the values are correct when accessed through the
96+
// sidre::MCArray
8397
int expected_value = 0;
8498
for(axom::IndexType i = 0; i < NUM_NODES; ++i)
8599
{
@@ -90,7 +104,7 @@ int main(int argc, char** argv)
90104
} // END for all components
91105
} // END for all nodes
92106

93-
// STEP 5: delete the datastores
107+
// STEP 5: Delete both data stores (and associated data).
94108
delete dataStore2;
95109
dataStore2 = nullptr;
96110

0 commit comments

Comments
 (0)