Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified logging infrastructure #1426

Merged
merged 15 commits into from
Dec 17, 2024
22 changes: 15 additions & 7 deletions src/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
# Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
# other details. No copyright assignment is required to contribute to Ascent.


################################
# Add flow
################################
add_subdirectory(flow)


#######################################
# display info about optional features
#######################################
if(ENABLE_APCOMP)
message(STATUS "Building APComp (ENABLE_APCOMP=ON)")
else()
Expand All @@ -29,10 +24,23 @@ else()
endif()


################################
# ascent_png_utils object lib
# shared for testing of all libs
################################
add_subdirectory(png_utils)

################################
# ascent_logging lib
# shared logging for all libs
################################
add_subdirectory(logging)

################################
# Add flow
################################
add_subdirectory(flow)

################################
# Add ap comp
################################
Expand Down
9 changes: 4 additions & 5 deletions src/libs/ascent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,14 @@ set(ascent_headers
# utils
utils/ascent_actions_utils.hpp
utils/ascent_data_logger.hpp
utils/ascent_logging.hpp
utils/ascent_logging_old.hpp
utils/ascent_block_timer.hpp
utils/ascent_mpi_utils.hpp
utils/ascent_string_utils.hpp
utils/ascent_web_interface.hpp
utils/ascent_resources.hpp
utils/ascent_resources_cinema_web.hpp
utils/ascent_resources_ascent_web.hpp
utils/ascent_annotations.hpp
# hola
hola/ascent_hola.hpp)

Expand Down Expand Up @@ -238,12 +237,11 @@ set(ascent_sources
utils/ascent_actions_utils.cpp
utils/ascent_data_logger.cpp
utils/ascent_block_timer.cpp
utils/ascent_logging.cpp
utils/ascent_logging_old.cpp
utils/ascent_mpi_utils.cpp
utils/ascent_string_utils.cpp
utils/ascent_web_interface.cpp
utils/ascent_resources.cpp
utils/ascent_annotations.cpp
# hola
hola/ascent_hola.cpp)

Expand Down Expand Up @@ -371,7 +369,8 @@ set(ascent_thirdparty_libs
conduit::conduit
ascent_flow
ascent_lodepng
ascent_png_utils)
ascent_png_utils
ascent_logging)

##################
# optional libs
Expand Down
168 changes: 160 additions & 8 deletions src/libs/ascent/ascent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <ascent_empty_runtime.hpp>
#include <ascent_flow_runtime.hpp>
#include <ascent_logging.hpp>
#include <ascent_logging_old.hpp>
#include <runtimes/ascent_main_runtime.hpp>
#include <utils/ascent_string_utils.hpp>
#include <flow.hpp>
Expand All @@ -36,6 +38,50 @@ using namespace conduit;
namespace ascent
{

//-----------------------------------------------------------------------------
namespace detail
{

//-----------------------------------------------------------------------------
int
ParRank(int comm_id)
{
int rank = 0;

#if defined(ASCENT_MPI_ENABLED)
if(comm_id == -1)
{
// do nothing, an error will be thrown later
// so we can respect the exception handling
return 0;
}
MPI_Comm mpi_comm = MPI_Comm_f2c(comm_id);
MPI_Comm_rank(mpi_comm, &rank);
#endif

return rank;
}

//-----------------------------------------------------------------------------
int
ParSize(int comm_id)
{
int comm_size=1;

#if defined(ASCENT_MPI_ENABLED)
if(comm_id == -1)
{
// do nothing, an error will be thrown later
// so we can respect the exception handling
return 1;
}
MPI_Comm mpi_comm = MPI_Comm_f2c(comm_id);
MPI_Comm_size(mpi_comm, &comm_size);
#endif

return comm_size;
}

//-----------------------------------------------------------------------------
void
quiet_handler(const std::string &,
Expand All @@ -44,6 +90,10 @@ quiet_handler(const std::string &,
{
}

}



//-----------------------------------------------------------------------------
Ascent::Ascent()
: m_runtime(NULL),
Expand Down Expand Up @@ -187,6 +237,9 @@ Ascent::open(const conduit::Node &options)
comm_id = options["mpi_comm"].to_int32();
}

int par_rank = detail::ParRank(comm_id);
int par_size = detail::ParSize(comm_id);

CheckForSettingsFile(opts_file,
processed_opts,
true,
Expand All @@ -201,20 +254,115 @@ Ascent::open(const conduit::Node &options)
m_options["mpi_comm"] = options["mpi_comm"];
}

if(m_options.has_path("messages") &&
m_options["messages"].dtype().is_string() )
Node echo_opts;
echo_opts["echo_threshold"] = "info";
echo_opts["ranks"] = "root";

// messages echoed to std out
if(m_options.has_path("messages"))
{
if(m_options["messages"].dtype().is_string())
{
std::string msgs_opt = m_options["messages"].as_string();
if( msgs_opt == "verbose")
{
m_verbose_msgs = true;
echo_opts["echo_threshold"] = "all";
}
else if(msgs_opt == "quiet")
{
m_verbose_msgs = false;
echo_opts["echo_threshold"] = "error";
cyrush marked this conversation as resolved.
Show resolved Hide resolved
}
}
else if(m_options["messages"].dtype().is_object())
{
const Node &msg_ops = m_options["messages"];
echo_opts.update(msg_ops);
if(msg_ops.has_child("echo_threshold") &&
msg_ops["echo_threshold"].dtype().is_string() )
{
std::string echo_thresh = msg_ops["echo_threshold"].as_string();
if(echo_thresh == "none" ||
echo_thresh == "error" ||
echo_thresh == "warn" )
{
m_verbose_msgs = false;
}
else
{
m_verbose_msgs = true;
}
}
}
}

ascent::Logger &logger = ascent::Logger::instance();

// setup echo
logger.set_echo_threshold(echo_opts["echo_threshold"].as_string());

// control for mpi case
// if ranks == "root"
// rank 0 is what is specified, echo_threshold = "none" for all others
// if ranks == "all"
// echo_threshold = specified option used for all ranks (alreay handled above)
std::string log_ranks_str = echo_opts["ranks"].as_string();

if(log_ranks_str == "root")
{
if(par_rank != 0)
{
logger.set_echo_threshold("none");
}
}

// logging options
//
// logging: true
//
// logging:
// file_pattern: zzzz
// log_threshold: info
//

Node logging_opts;
logging_opts["enabled"] = 0;
#if defined(ASCENT_MPI_ENABLED)
logging_opts["file_pattern"] = "ascent_log_output_rank_{rank:05d}.yaml";
#else
logging_opts["file_pattern"] = "ascent_log_output.yaml";
#endif
logging_opts["log_threshold"] = "debug";

if(m_options.has_path("logging"))
{
std::string msgs_opt = m_options["messages"].as_string();
if( msgs_opt == "verbose")
if(m_options["logging"].dtype().is_string() &&
m_options["logging"].as_string() == "true")
{
m_verbose_msgs = true;
logging_opts["enabled"] = 1;
}
else if(msgs_opt == "quiet")
else if(m_options["logging"].dtype().is_object())
{
m_verbose_msgs = false;
logging_opts["enabled"] = 1;
// pull over options
logging_opts.update(m_options["logging"]);
}
}

if(logging_opts["enabled"].to_int() == 1)
{
std::string file_pattern = logging_opts["file_pattern"].as_string();
#if defined(ASCENT_MPI_ENABLED)
ASCENT_LOG_OPEN( file_pattern ) // serial
#else
ASCENT_LOG_OPEN_RANK( file_pattern, par_rank ) // mpi par
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch?


        #if defined(ASCENT_MPI_ENABLED)
            ASCENT_LOG_OPEN_RANK( file_pattern, par_rank ) // mpi par   
        #else
            ASCENT_LOG_OPEN( file_pattern ) // serial 
        #endif

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for finding this, I am working on tests right now

logger.set_log_threshold(logging_opts["log_threshold"].as_string());
}


// exception controls
if(m_options.has_path("exceptions") &&
m_options["exceptions"].dtype().is_string() )
{
Expand Down Expand Up @@ -300,7 +448,7 @@ Ascent::open(const conduit::Node &options)
// make sure to do this after.
if(!m_verbose_msgs)
{
conduit::utils::set_info_handler(quiet_handler);
conduit::utils::set_info_handler(detail::quiet_handler);
}

set_status("Ascent::open completed");
Expand Down Expand Up @@ -549,6 +697,7 @@ Ascent::close()
}

set_status("Ascent::close completed");
ASCENT_LOG_CLOSE();
}
catch(conduit::Error &e)
{
Expand All @@ -574,6 +723,7 @@ Ascent::close()
<< e.message() << std::endl;
}
}
ASCENT_LOG_CLOSE();
}
}

Expand All @@ -585,6 +735,7 @@ Ascent::set_status(const std::string &msg)
std::ostringstream oss;
oss << msg << " at " << timestamp();
m_status["message"] = oss.str();
ASCENT_LOG_DEBUG(msg);
}

//---------------------------------------------------------------------------//
Expand All @@ -597,6 +748,7 @@ Ascent::set_status(const std::string &msg,
oss << msg << " at " << timestamp();
m_status["message"] = oss.str();
m_status["details"] = details;
ASCENT_LOG_DEBUG(msg + " " + details);
}

//---------------------------------------------------------------------------//
Expand Down
1 change: 1 addition & 0 deletions src/libs/ascent/ascent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


#include <ascent_logging.hpp>
#include <ascent_logging_old.hpp>
#include <ascent_block_timer.hpp>

#include <conduit.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/libs/ascent/hola/ascent_hola.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// ascent includes
//-----------------------------------------------------------------------------
#include <ascent_logging.hpp>
#include <ascent_logging_old.hpp>

#include <fstream>

Expand Down
9 changes: 9 additions & 0 deletions src/libs/ascent/runtimes/ascent_main_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ AscentRuntime::~AscentRuntime()
void
AscentRuntime::Initialize(const conduit::Node &options)
{

// handle logging first
#if defined(ASCENT_MPI_ENABLED)

#else

#endif


#if ASCENT_MPI_ENABLED
if(!options.has_child("mpi_comm") ||
!options["mpi_comm"].dtype().is_integer())
Expand Down
1 change: 1 addition & 0 deletions src/libs/ascent/runtimes/ascent_mfem_data_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ascent_mfem_data_adapter.hpp"

#include <ascent_logging.hpp>
#include <ascent_logging_old.hpp>

// standard lib includes
#include <iostream>
Expand Down
1 change: 1 addition & 0 deletions src/libs/ascent/runtimes/ascent_transmogrifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ascent_mfem_data_adapter.hpp"
#endif
#include "ascent_logging.hpp"
#include "ascent_logging_old.hpp"
#include <conduit_blueprint.hpp>
#include <algorithm>

Expand Down
1 change: 1 addition & 0 deletions src/libs/ascent/runtimes/ascent_vtkh_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ascent_vtkh_collection.hpp"
#include "ascent_mpi_utils.hpp"
#include "ascent_logging.hpp"
#include "ascent_logging_old.hpp"

#if defined(ASCENT_MPI_ENABLED)
#include <mpi.h>
Expand Down
3 changes: 3 additions & 0 deletions src/libs/ascent/runtimes/ascent_vtkh_data_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <mpi.h>
#endif

#include <ascent_logging.hpp>
#include <ascent_logging_old.hpp>

// VTKm includes
#define VTKM_USE_DOUBLE_PRECISION
#include <vtkm/cont/DataSet.h>
Expand Down
Loading
Loading