Skip to content

Commit

Permalink
parsing rom config option to Control.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer2368 committed May 2, 2024
1 parent c752f1d commit ee3a03d
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/Control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,10 @@ void Control::setOptions(const boost::program_options::variables_map& vm)

// synchronize all processors
sync();

#ifdef MGMOL_HAS_LIBROM
setROMOptions(vm);
#endif
}

int Control::checkOptions()
Expand Down Expand Up @@ -2051,3 +2055,66 @@ void Control::printPoissonOptions(std::ostream& os)
}
os << std::endl;
}

void Control::setROMOptions(const boost::program_options::variables_map& vm)
{
printWithTimeStamp("Control::setROMOptions()...", std::cout);

if (onpe0)
{
std::string str = vm["ROM.stage"].as<std::string>();
if (str.compare("offline") == 0)
rom_pri_option.rom_stage = ROMStage::OFFLINE;
else if (str.compare("online") == 0)
rom_pri_option.rom_stage = ROMStage::ONLINE;
else if (str.compare("build") == 0)
rom_pri_option.rom_stage = ROMStage::BUILD;
else if (str.compare("none") == 0)
rom_pri_option.rom_stage = ROMStage::UNSUPPORTED;

rom_pri_option.restart_file_fmt = vm["ROM.offline.restart_filefmt"].as<std::string>();
rom_pri_option.restart_file_minidx = vm["ROM.offline.restart_min_idx"].as<int>();
rom_pri_option.restart_file_maxidx = vm["ROM.offline.restart_max_idx"].as<int>();
rom_pri_option.basis_file = vm["ROM.offline.basis_file"].as<std::string>();

rom_pri_option.save_librom_snapshot = vm["ROM.offline.save_librom_snapshot"].as<bool>();
} // onpe0

// synchronize all processors
syncROMOptions();
}

void Control::syncROMOptions()
{
if (onpe0 && verbose > 0)
(*MPIdata::sout) << "Control::syncROMOptions()" << std::endl;

MGmol_MPI& mmpi = *(MGmol_MPI::instance());

mmpi.bcast(rom_pri_option.restart_file_fmt, comm_global_);
mmpi.bcast(rom_pri_option.basis_file, comm_global_);

auto bcast_check = [](int mpirc) {
if (mpirc != MPI_SUCCESS)
{
(*MPIdata::sout) << "MPI Bcast of Control failed!!!" << std::endl;
MPI_Abort(comm_global_, 2);
}
};

short rom_stage = (short)static_cast<int>(rom_pri_option.rom_stage);
int mpirc;
mpirc = MPI_Bcast(&rom_stage, 1, MPI_SHORT, 0, comm_global_);
bcast_check(mpirc);

mpirc = MPI_Bcast(&rom_pri_option.restart_file_minidx, 1, MPI_INT, 0, comm_global_);
bcast_check(mpirc);

mpirc = MPI_Bcast(&rom_pri_option.restart_file_maxidx, 1, MPI_INT, 0, comm_global_);
bcast_check(mpirc);

mpirc = MPI_Bcast(&rom_pri_option.save_librom_snapshot, 1, MPI_C_BOOL, 0, comm_global_);
bcast_check(mpirc);

rom_pri_option.rom_stage = static_cast<ROMStage>(rom_stage);
}
12 changes: 12 additions & 0 deletions src/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "Species.h"
#include "Timeout.h"

/* enumeration and option variables for libROM */
#include "mgmol_config.h"
#include "rom_Control.h"

#include <cassert>
#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -220,6 +224,9 @@ class Control

void printRestartLink();

/* libROM related options */
ROMPrivateOptions rom_pri_option;

public:
static Control* instance()
{
Expand Down Expand Up @@ -707,6 +714,11 @@ class Control
}

bool AtomsMove() { return (atoms_dyn_ != 0); }

/* ROM-related options */
void setROMOptions(const boost::program_options::variables_map& vm);
void syncROMOptions();
const ROMPrivateOptions getROMOptions() { return rom_pri_option; }
};

#endif
42 changes: 42 additions & 0 deletions src/rom_Control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2017, Lawrence Livermore National Security, LLC and
// UT-Battelle, LLC.
// Produced at the Lawrence Livermore National Laboratory and the Oak Ridge
// National Laboratory.
// LLNL-CODE-743438
// All rights reserved.
// This file is part of MGmol. For details, see https://github.com/llnl/mgmol.
// Please also read this link https://github.com/llnl/mgmol/LICENSE

#ifndef ROM_CONTROL_H
#define ROM_CONTROL_H

#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

enum class ROMStage
{
OFFLINE,
ONLINE,
RESTORE, // TODO(kevin): what stage is this?
BUILD,
UNSUPPORTED
};

/* Stored as a private member variable of Control class */
struct ROMPrivateOptions
{
ROMStage rom_stage = ROMStage::UNSUPPORTED;

std::string restart_file_fmt = "";
int restart_file_minidx = -1;
int restart_file_maxidx = -1;
std::string basis_file = "";

/* save librom snapshot matrix at FOM simulation. */
bool save_librom_snapshot = false;
};

#endif // ROM_CONTROL_H

0 comments on commit ee3a03d

Please sign in to comment.