Skip to content

Commit

Permalink
add debug mode for coeus adapter, user can choose turn on debug mode …
Browse files Browse the repository at this point in the history
…in cmakelists
  • Loading branch information
hxu65 committed Feb 4, 2024
1 parent f2650d2 commit db03d35
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(HERMES_ENGINE_SRCS
# Libraries
#------------------------------------------------------------------------------
add_definitions(-DMeta_enabled)
add_definitions(-Ddebug_mode)
add_library(hermes_engine ${HERMES_ENGINE_SRCS} ../include/coeus/MetadataSerializer.h)
add_dependencies(hermes_engine spdlog)
add_dependencies(hermes_engine coeus_mdm)
Expand Down
75 changes: 61 additions & 14 deletions src/hermes_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void HermesEngine::Init_() {
file_sink->set_pattern("%^[Coeus engine] [%!:%# @ %s] [%l] %$ %v");

// File log for metadata collection
#ifdef Meta_enabled
auto file_sink2 = std::make_shared<spdlog::sinks::basic_file_sink_mt>(
"logs/metadataCollect_get.txt", true);
file_sink2->set_level(spdlog::level::trace);
Expand All @@ -82,6 +83,7 @@ void HermesEngine::Init_() {
meta_logger_get = std::make_shared<spdlog::logger>(logger2);
meta_logger_get->info(
"Name, shape, start, Count, Constant Shape, Time, selectionSize, sizeofVariable, ShapeID, steps, stepstart, blockID");

auto file_sink3 = std::make_shared<spdlog::sinks::basic_file_sink_mt>(
"logs/metadataCollect_put.txt", true);
file_sink3->set_level(spdlog::level::trace);
Expand All @@ -91,6 +93,7 @@ void HermesEngine::Init_() {
meta_logger_put = std::make_shared<spdlog::logger>(logger3);
meta_logger_put->info(
"Name, shape, start, Count, Constant Shape, Time, selectionSize, sizeofVariable, ShapeID, steps, stepstart, blockID");
#endif

//Merge Log
spdlog::logger logger("debug_logger", {console_sink, file_sink});
Expand Down Expand Up @@ -180,9 +183,6 @@ void HermesEngine::Init_() {

open = true;




// debug mode

/*
Expand All @@ -199,7 +199,11 @@ void HermesEngine::Init_() {
* Close the Engine.
* */
void HermesEngine::DoClose(const int transportIndex) {
#ifdef debug_mode
TRACE_FUNC("engine close");
#else
TRACE_FUNC();
#endif
open = false;
// mpiComm->free();
}
Expand All @@ -218,11 +222,13 @@ HermesEngine::~HermesEngine() {

adios2::StepStatus HermesEngine::BeginStep(adios2::StepMode mode,
const float timeoutSeconds) {
#ifdef debug_mode
TRACE_FUNC(std::to_string(currentStep));
#else
TRACE_FUNC();
#endif
IncrementCurrentStep();
// debug mode
engine_logger->info("finish IncrementCurrentStep, rank {}", rank);


if (m_OpenMode == adios2::Mode::Read) {
if (total_steps == -1) total_steps = db->GetTotalSteps(uid);

Expand All @@ -240,17 +246,29 @@ adios2::StepStatus HermesEngine::BeginStep(adios2::StepMode mode,
}

void HermesEngine::IncrementCurrentStep() {
TRACE_FUNC(currentStep);
#ifdef debug_mode
TRACE_FUNC(std::to_string(currentStep));
#else
TRACE_FUNC();
#endif
currentStep++;
}

size_t HermesEngine::CurrentStep() const {
TRACE_FUNC(currentStep);
#ifdef debug_mode
TRACE_FUNC(std::to_string(currentStep));
#else
TRACE_FUNC();
#endif
return currentStep;
}

void HermesEngine::EndStep() {
#ifdef debug_mode
TRACE_FUNC(std::to_string(currentStep));
#else
TRACE_FUNC();
#endif
if (m_OpenMode == adios2::Mode::Write) {
if (rank % ppn == 0) {
DbOperation db_op(uid, currentStep);
Expand All @@ -268,7 +286,11 @@ void HermesEngine::EndStep() {
bool HermesEngine::VariableMinMax(const adios2::core::VariableBase &Var,
const size_t Step,
adios2::MinMaxStruct &MinMax) {
#ifdef debug_mode
TRACE_FUNC(Var.m_Name);
#else
TRACE_FUNC();
#endif
// We initialize the min and max values
MinMax.Init(Var.m_Type);

Expand Down Expand Up @@ -330,15 +352,18 @@ void HermesEngine::ApplyElementMinMax(adios2::MinMaxStruct &MinMax,

template<typename T>
T *HermesEngine::SelectUnion(adios2::PrimitiveStdtypeUnion &u) {
TRACE_FUNC();
return reinterpret_cast<T *>(&u);
// debug Mode


}

template<typename T>
void HermesEngine::ElementMinMax(adios2::MinMaxStruct &MinMax, void *element) {
#ifdef debug_mode
TRACE_FUNC("MinMax operation");
#else
TRACE_FUNC();
#endif
T *min = SelectUnion<T>(MinMax.MinUnion);
T *max = SelectUnion<T>(MinMax.MaxUnion);
T *value = static_cast<T *>(element);
Expand All @@ -351,7 +376,11 @@ void HermesEngine::ElementMinMax(adios2::MinMaxStruct &MinMax, void *element) {
}

void HermesEngine::LoadMetadata() {
TRACE_FUNC("loadMetadata");
#ifdef debug_mode
TRACE_FUNC(rank);
#else
TRACE_FUNC();
#endif
auto metadata_vector = db->GetAllVariableMetadata(currentStep, rank);
for (auto &variableMetadata : metadata_vector) {

Expand Down Expand Up @@ -388,7 +417,12 @@ void HermesEngine::DefineVariable(const VariableMetadata &variableMetadata) {
template<typename T>
void HermesEngine::DoGetSync_(const adios2::core::Variable<T> &variable,
T *values) {
TRACE_FUNC(variable.m_Name, adios2::ToString(variable.m_Count));
#ifdef debug_mode
TRACE_FUNC(variable.m_Name, adios2::ToString(variable.m_Count));
#else
TRACE_FUNC();
#endif

auto blob = Hermes->bkt->Get(variable.m_Name);
std::string name = variable.m_Name;
#ifdef Meta_enabled
Expand All @@ -407,7 +441,11 @@ void HermesEngine::DoGetSync_(const adios2::core::Variable<T> &variable,
template<typename T>
void HermesEngine::DoGetDeferred_(
const adios2::core::Variable<T> &variable, T *values) {
TRACE_FUNC(variable.m_Name, adios2::ToString(variable.m_Count));
#ifdef debug_mode
TRACE_FUNC(variable.m_Name, adios2::ToString(variable.m_Count));
#else
TRACE_FUNC();
#endif
auto blob = Hermes->bkt->Get(variable.m_Name);
std::string name = variable.m_Name;
#ifdef Meta_enabled
Expand All @@ -426,7 +464,11 @@ void HermesEngine::DoGetDeferred_(
template<typename T>
void HermesEngine::DoPutSync_(const adios2::core::Variable<T> &variable,
const T *values) {
#ifdef debug_mode
TRACE_FUNC(variable.m_Name, adios2::ToString(variable.m_Count));
#else
TRACE_FUNC();
#endif
std::string name = variable.m_Name;
Hermes->bkt->Put(name, variable.SelectionSize() * sizeof(T), values);

Expand All @@ -450,7 +492,12 @@ void HermesEngine::DoPutSync_(const adios2::core::Variable<T> &variable,
template<typename T>
void HermesEngine::DoPutDeferred_(
const adios2::core::Variable<T> &variable, const T *values) {
TRACE_FUNC(variable.m_Name, adios2::ToString(variable.m_Count));

#ifdef debug_mode
TRACE_FUNC(variable.m_Name, adios2::ToString(variable.m_Count));
#else
TRACE_FUNC();
#endif
std::string name = variable.m_Name;
Hermes->bkt->Put(name, variable.SelectionSize() * sizeof(T), values);

Expand Down

0 comments on commit db03d35

Please sign in to comment.