Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/axom/sidre/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(example_sources

if(AXOM_ENABLE_MPI)
set (example_parallel_sources
sidre_array.cpp
sidre_mcarray.cpp
sidre_createdatastore.cpp
sidre_external_array.cpp
sidre_generateindex.cpp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace sidre = axom::sidre;

int main(int argc, char** argv)
{
//
// Basic MPI setup with global communicator
//
MPI_Init(&argc, &argv);
MPI_Comm problem_comm = MPI_COMM_WORLD;

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

axom::slic::SimpleLogger logger;

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

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

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

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

// STEP 2: save the array data in to a file
// STEP 2: Write out the data store contents to a file.
sidre::IOManager sidre_io(problem_comm);
#if defined(AXOM_USE_HDF5)
sidre_io.write(root1, nranks, "sidre_array_mesh", "sidre_hdf5");
#else
sidre_io.write(root1, nranks, "sidre_array_mesh", "sidre_conduit_json");
#endif

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

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

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

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

// STEP 5: delete the datastores
// STEP 5: Delete both data stores (and associated data).
delete dataStore2;
dataStore2 = nullptr;

Expand Down