From 354b82be87d067595160a605b768553391a55d96 Mon Sep 17 00:00:00 2001 From: Cosmin G Petra Date: Wed, 28 Aug 2024 14:08:28 -0700 Subject: [PATCH] integrated AXOM code compiles; does nothing --- src/Interface/hiop_defs.hpp.in | 1 + src/Optimization/hiopAlgFilterIPM.cpp | 44 +++++++++++++++++++++------ src/Optimization/hiopAlgFilterIPM.hpp | 16 ++++++---- src/Utils/hiopOptions.cpp | 2 ++ 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/Interface/hiop_defs.hpp.in b/src/Interface/hiop_defs.hpp.in index 0af21826d..68570c8b2 100644 --- a/src/Interface/hiop_defs.hpp.in +++ b/src/Interface/hiop_defs.hpp.in @@ -12,6 +12,7 @@ #cmakedefine HIOP_USE_PARDISO #cmakedefine HIOP_USE_RESOLVE #cmakedefine HIOP_USE_GINKGO +#cmakedefine HIOP_USE_AXOM #define HIOP_VERSION "@PROJECT_VERSION@" #define HIOP_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ #define HIOP_VERSION_MINOR @PROJECT_VERSION_MINOR@ diff --git a/src/Optimization/hiopAlgFilterIPM.cpp b/src/Optimization/hiopAlgFilterIPM.cpp index 3af3107cb..a179341a8 100644 --- a/src/Optimization/hiopAlgFilterIPM.cpp +++ b/src/Optimization/hiopAlgFilterIPM.cpp @@ -66,6 +66,14 @@ #include "hiopCppStdUtils.hpp" +#ifdef HIOP_USE_AXOM +#include +#include +#include +#include +using namespace axom; +#endif + #include #include #include @@ -74,6 +82,9 @@ namespace hiop { +//#ifdef HIOP_USE_AXOM + +//#ifdef HIOP_USE_AXOM hiopAlgFilterIPMBase::hiopAlgFilterIPMBase(hiopNlpFormulation* nlp_in, const bool within_FR) : soc_dir(nullptr), @@ -1485,6 +1496,8 @@ void hiopAlgFilterIPMQuasiNewton::outputIteration(int lsStatus, int lsNum, int u } } +#ifdef HIOP_USE_AXOM + //declaration required by C++14, not anymore by C++17 or after constexpr char hiopAlgFilterIPMQuasiNewton::default_state_filename[]; @@ -1492,14 +1505,14 @@ void hiopAlgFilterIPMQuasiNewton::save_state_to_file(const ::std::string& path_i { auto path = path_in=="" ? default_state_filename : path_in; - axom_sidre_DataStore* ds = new axom_sidre_DataStore(0); + sidre::DataStore* ds = new sidre::DataStore(); this->save_state_to_data_store(ds); - //::axom::sidre::IOManager writer(this->get_nlp()->get_comm()); - //int num_files; - //MPI_Comm_size(this->get_nlp()->get_comm(), &num_files); - //writer.write(ds_->getRoot(), num_files, path.str(), ::axom::sidre::Group::getDefaultIOProtocol()); + sidre::IOManager writer(this->get_nlp()->get_comm()); + int n_files; + MPI_Comm_size(this->get_nlp()->get_comm(), &n_files); + writer.write(ds->getRoot(), n_files, path.c_str(), sidre::Group::getDefaultIOProtocol()); delete ds; } @@ -1510,17 +1523,28 @@ void hiopAlgFilterIPMQuasiNewton::load_state_from_file(const ::std::string& path //todo } -void hiopAlgFilterIPMQuasiNewton::save_state_to_data_store(void* ds) +void hiopAlgFilterIPMQuasiNewton::save_state_to_data_store(::axom::sidre::DataStore* ds) { - //Group* nlp_group = ds->getRoot()->createGroup("hiop solver"); + using IndType = sidre::IndexType; + sidre::Group* nlp_group = ds->getRoot()->createGroup("hiop solver"); //create views for each member that needs to be saved const double* x = it_curr->get_x()->local_data_host(); - //destination = nlp_group->createViewAndAllocate("x", ::axom::sidre::DOUBLE_ID, size); + const IndType size = it_curr->get_x()->get_local_size(); + sidre::View* dest = nlp_group->createViewAndAllocate("x", axom::sidre::DOUBLE_ID, size); + double *const dest_ptr(dest->getArray()); + const auto stride(dest->getStride()); + if(1==stride) { + ::std::copy(x, x+size, dest_ptr); + } else { + for(IndType i=0; igetRoot()->createGroup("hiop solver"); @@ -1529,7 +1553,7 @@ void hiopAlgFilterIPMQuasiNewton::load_state_from_data_store(const void* ds) const double* x = it_curr->get_x()->local_data_host(); //destination = nlp_group->createViewAndAllocate("x", ::axom::sidre::DOUBLE_ID, size); } - +#endif // HIOP_USE_AXOM /****************************************************************************************************** * FULL NEWTON IPM diff --git a/src/Optimization/hiopAlgFilterIPM.hpp b/src/Optimization/hiopAlgFilterIPM.hpp index 4be268855..a44208b65 100644 --- a/src/Optimization/hiopAlgFilterIPM.hpp +++ b/src/Optimization/hiopAlgFilterIPM.hpp @@ -67,12 +67,14 @@ #include "hiopPDPerturbation.hpp" #include "hiopFactAcceptor.hpp" +#ifdef HIOP_USE_AXOM +#include +#endif + #include "hiopTimer.hpp" namespace hiop { -//temporary dummy definition for axom::sidre::DataStore until axom is going to be included -using axom_sidre_DataStore=double; class hiopAlgFilterIPMBase { public: @@ -344,9 +346,11 @@ class hiopAlgFilterIPMQuasiNewton : public hiopAlgFilterIPMBase virtual hiopSolveStatus run(); - //work in progress - virtual void save_state_to_data_store(void* sidre_data_store); - virtual void load_state_from_data_store(const void* sidre_data_store); + // note that checkpointing is only available with a axom-enabled build +#ifdef HIOP_USE_AXOM + + virtual void save_state_to_data_store(::axom::sidre::DataStore* data_store); + virtual void load_state_from_data_store(const ::axom::sidre::DataStore* data_store); static constexpr char default_state_filename[] = "hiop_qn_state.sidre"; @@ -372,7 +376,7 @@ class hiopAlgFilterIPMQuasiNewton : public hiopAlgFilterIPMBase * */ void load_state_from_file(const ::std::string& path=""); - +#endif // HIOP_USE_AXOM private: virtual void outputIteration(int lsStatus, int lsNum, int use_soc = 0, int use_fr = 0); private: diff --git a/src/Utils/hiopOptions.cpp b/src/Utils/hiopOptions.cpp index c85296457..f2d1cbb7b 100644 --- a/src/Utils/hiopOptions.cpp +++ b/src/Utils/hiopOptions.cpp @@ -1289,6 +1289,8 @@ void hiopOptionsNLP::register_options() ""); } + // checkpointing and restarting + } void hiopOptionsNLP::ensure_consistence()