Skip to content

Commit

Permalink
integrated AXOM
Browse files Browse the repository at this point in the history
code compiles; does nothing
  • Loading branch information
cnpetra committed Aug 28, 2024
1 parent 0e428f5 commit 354b82b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/Interface/hiop_defs.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@
Expand Down
44 changes: 34 additions & 10 deletions src/Optimization/hiopAlgFilterIPM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@

#include "hiopCppStdUtils.hpp"

#ifdef HIOP_USE_AXOM
#include <axom/sidre/core/DataStore.hpp>
#include <axom/sidre/core/Group.hpp>
#include <axom/sidre/core/View.hpp>
#include <axom/sidre/spio/IOManager.hpp>
using namespace axom;
#endif

#include <cmath>
#include <cstring>
#include <cassert>
Expand All @@ -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),
Expand Down Expand Up @@ -1485,21 +1496,23 @@ 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[];

void hiopAlgFilterIPMQuasiNewton::save_state_to_file(const ::std::string& path_in)
{
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;
}
Expand All @@ -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; i<size; ++i) {
dest_ptr[i*stride] = x[i];
}
}
}

void hiopAlgFilterIPMQuasiNewton::load_state_from_data_store(const void* ds)
void hiopAlgFilterIPMQuasiNewton::load_state_from_data_store(const sidre::DataStore* ds)
{
//Group* nlp_group = ds->getRoot()->createGroup("hiop solver");

Expand All @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/Optimization/hiopAlgFilterIPM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@
#include "hiopPDPerturbation.hpp"
#include "hiopFactAcceptor.hpp"

#ifdef HIOP_USE_AXOM
#include <axom/sidre/core/DataStore.hpp>
#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:
Expand Down Expand Up @@ -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";

Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/Utils/hiopOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,8 @@ void hiopOptionsNLP::register_options()
"");
}

// checkpointing and restarting

}

void hiopOptionsNLP::ensure_consistence()
Expand Down

0 comments on commit 354b82b

Please sign in to comment.