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

Statistics/additional random access #507

Merged
merged 4 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/adiar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ set(SOURCES

# adiar/internal/data_structures
internal/data_structures/levelized_priority_queue.cpp

# adiar/internal/io
internal/io/arc_file.cpp
internal/io/node_file.cpp
)

# ============================================================================ #
Expand All @@ -147,14 +151,14 @@ else()
add_library(${PROJECT_NAME} STATIC ${HEADERS} ${SOURCES})
endif()

if (ADIAR_STATS_EXTRA OR ADIAR_STATS)
target_compile_definitions(${PROJECT_NAME} PRIVATE ADIAR_STATS)
if (ADIAR_STATS)
target_compile_definitions(${PROJECT_NAME} PUBLIC ADIAR_STATS)
endif()

# ============================================================================ #
# Link dependencies
target_link_libraries(${PROJECT_NAME} tpie)
target_link_libraries(${PROJECT_NAME} Cnl)
target_link_libraries(${PROJECT_NAME} PUBLIC tpie)
target_link_libraries(${PROJECT_NAME} PUBLIC Cnl)

# ============================================================================ #
# Setup as library
Expand Down
6 changes: 6 additions & 0 deletions src/adiar/internal/io/arc_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "arc_file.h"

namespace adiar::internal
{
stats_t::arc_file_t stats_arc_file;
}
6 changes: 6 additions & 0 deletions src/adiar/internal/io/arc_file.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#ifndef ADIAR_INTERNAL_IO_ARC_FILE_H
#define ADIAR_INTERNAL_IO_ARC_FILE_H

#include <adiar/statistics.h>
#include <adiar/internal/data_types/node.h>
#include <adiar/internal/data_types/arc.h>
#include <adiar/internal/io/file.h>
#include <adiar/internal/io/shared_file_ptr.h>

namespace adiar::internal
{
//////////////////////////////////////////////////////////////////////////////
/// \brief Struct holding statistics on arc files
//////////////////////////////////////////////////////////////////////////////
extern stats_t::arc_file_t stats_arc_file;

// TODO (ADD):
// TODO (QMDD):
// Generalize the arc type and the arc_file based on a given node.
Expand Down
24 changes: 21 additions & 3 deletions src/adiar/internal/io/arc_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ namespace adiar::internal
void detach() {
if (!attached()) return;

#ifdef ADIAR_STATS
if (_elem_writers[IDX__TERMINALS__OUT_OF_ORDER].size() != 0u) {
stats_arc_file.sort_out_of_order += 1;
}
#endif
_elem_writers[IDX__TERMINALS__OUT_OF_ORDER].sort<arc_source_lt>();
return levelized_file_writer::detach();
levelized_file_writer::detach();
}

//////////////////////////////////////////////////////////////////////////////
Expand All @@ -118,7 +123,12 @@ namespace adiar::internal
/// \pre `attached() == true`.
//////////////////////////////////////////////////////////////////////////////
void push(const level_info &li)
{ levelized_file_writer::push(li); }
{
#ifdef ADIAR_STATS
stats_arc_file.push_level += 1;
#endif
levelized_file_writer::push(li);
}

////////////////////////////////////////////////////////////////////////////
/// \brief Write directly to the level_info file.
Expand Down Expand Up @@ -172,7 +182,9 @@ namespace adiar::internal
{
adiar_precondition(attached());
adiar_precondition(a.target().is_node());

#ifdef ADIAR_STATS
stats_arc_file.push_internal += 1;
#endif
levelized_file_writer::template push<IDX__INTERNAL>(a);
}

Expand All @@ -190,9 +202,15 @@ namespace adiar::internal
// Given arc is 'in-order' compared to latest 'in-order' pushed
__has_latest_terminal = true;
__latest_terminal = a;
#ifdef ADIAR_STATS
stats_arc_file.push_in_order += 1;
#endif
levelized_file_writer::template push<IDX__TERMINALS__IN_ORDER>(a);
} else {
// Given arc is 'out-of-order' compared to latest 'in-order' pushed
#ifdef ADIAR_STATS
stats_arc_file.push_out_of_order += 1;
#endif
levelized_file_writer::template push<IDX__TERMINALS__OUT_OF_ORDER>(a);
}

Expand Down
6 changes: 6 additions & 0 deletions src/adiar/internal/io/node_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "node_file.h"

namespace adiar::internal
{
stats_t::node_file_t stats_node_file;
}
6 changes: 6 additions & 0 deletions src/adiar/internal/io/node_file.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#ifndef ADIAR_INTERNAL_IO_NODE_FILE_H
#define ADIAR_INTERNAL_IO_NODE_FILE_H

#include <adiar/statistics.h>
#include <adiar/internal/data_types/node.h>
#include <adiar/internal/io/file.h>
#include <adiar/internal/io/levelized_file.h>
#include <adiar/internal/io/shared_file_ptr.h>

namespace adiar::internal
{
//////////////////////////////////////////////////////////////////////////////
/// \brief Struct holding statistics on node files
//////////////////////////////////////////////////////////////////////////////
extern stats_t::node_file_t stats_node_file;

//////////////////////////////////////////////////////////////////////////////
/// \brief A reduced Decision Diagram.
//////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 6 additions & 1 deletion src/adiar/internal/io/node_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,10 @@ namespace adiar::internal
////////////////////////////////////////////////////////////////////////////
void unsafe_push(const level_info &m)
{
#ifdef ADIAR_STATS
stats_node_file.push_level += 1;
#endif
_file_ptr->width = std::max<size_t>(_file_ptr->width, m.width());

levelized_file_writer::push(m);
}

Expand All @@ -269,6 +271,9 @@ namespace adiar::internal
////////////////////////////////////////////////////////////////////////////
void unsafe_push(const node &n)
{
#ifdef ADIAR_STATS
stats_node_file.push_node += 1;
#endif
if (n.low().is_terminal()) { _file_ptr->number_of_terminals[n.low().value()]++; }
if (n.high().is_terminal()) { _file_ptr->number_of_terminals[n.high().value()]++; }

Expand Down
104 changes: 97 additions & 7 deletions src/adiar/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <adiar/internal/algorithms/quantify.h>
#include <adiar/internal/algorithms/substitution.h>
#include <adiar/internal/data_structures/levelized_priority_queue.h>
#include <adiar/internal/io/arc_file.h>
#include <adiar/internal/io/node_file.h>

namespace adiar
{
Expand All @@ -21,29 +23,47 @@ namespace adiar
#endif

return {
// i/o
internal::stats_arc_file,
internal::stats_node_file,

// data structures
internal::stats_levelized_priority_queue,

// top-down sweeps
internal::stats_count,
internal::stats_equality,
internal::stats_intercut,
internal::stats_prod2,
stats_prod3,
internal::stats_quantify,
internal::stats_reduce,
internal::stats_substitute
internal::stats_substitute,

// bottom-up sweeps
internal::stats_reduce
};
}

void adiar_statsreset()
{
// i/o
internal::stats_arc_file = {};
internal::stats_node_file = {};

// data structures
internal::stats_levelized_priority_queue = {};

// top-down sweeps
internal::stats_count = {};
internal::stats_equality = {};
internal::stats_intercut = {};
internal::stats_levelized_priority_queue = {};
internal::stats_prod2 = {};
stats_prod3 = {};
internal::stats_quantify = {};
internal::stats_reduce = {};
internal::stats_substitute = {};

// bottom-up sweeps
internal::stats_reduce = {};
}

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -77,6 +97,62 @@ namespace adiar
return os << to_string(s);
}

void __printstat_arc_file(std::ostream &o)
{
o << indent << bold_on << "Arc Files" << bold_off << endl;

indent_level++;

uintwide_t total_pushes = internal::stats_arc_file.push_internal
+ internal::stats_arc_file.push_in_order
+ internal::stats_arc_file.push_out_of_order;

if (total_pushes == 0u) {
o << indent << "No writes" << endl;
indent_level--;
return;
}

o << indent << bold_on << label << "unsafe_push(arc ...)" << bold_off << total_pushes << endl;

indent_level++;
o << indent << label << "internal" << internal::stats_arc_file.push_internal
<< " = " << percent_frac(internal::stats_arc_file.push_internal, total_pushes) << percent << endl;
o << indent << label << "terminals (in-order)" << internal::stats_arc_file.push_in_order
<< " = " << percent_frac(internal::stats_arc_file.push_in_order, total_pushes) << percent << endl;
o << indent << label << "terminals (out-of-order)" << internal::stats_arc_file.push_out_of_order
<< " = " << percent_frac(internal::stats_arc_file.push_out_of_order, total_pushes) << percent << endl;
indent_level--;

o << indent << bold_on << label << "push(level_info ...)" << bold_off << internal::stats_arc_file.push_level << endl;

o << indent << bold_on << label << "out-of-order sortings" << bold_off << internal::stats_arc_file.sort_out_of_order << endl;

indent_level--;
}

void __printstat_node_file(std::ostream &o)
{
o << indent << bold_on << "Node Files" << bold_off << endl;

indent_level++;

if (internal::stats_node_file.push_node == 0u) {
o << indent << "No writes" << endl;
indent_level--;
return;
}

o << indent << bold_on << label << "unsafe_push(...)" << bold_off << endl;

indent_level++;
o << indent << label << "node" << internal::stats_node_file.push_node << endl;
o << indent << label << "level_info" << internal::stats_node_file.push_level << endl;
indent_level--;

indent_level--;
}

void __printstat_lpq(std::ostream &o, const stats_t::levelized_priority_queue_t& stats)
{
if (indent_level == 0) {
Expand Down Expand Up @@ -472,9 +548,21 @@ namespace adiar
#else
o << std::fixed << std::setprecision(FLOAT_PRECISION);

o << bold_on << "--== I/O ==--" << bold_off << endl << endl;

__printstat_arc_file(o);
o << endl;

__printstat_node_file(o);
o << endl;

o << bold_on << "--== Data Structures ==--" << bold_off << endl << endl;

__printstat_lpq(o, internal::stats_levelized_priority_queue);
o << endl;

o << bold_on << "--== Top-Down Sweep Algorithms ==--" << bold_off << endl << endl;

__printstat_count(o);
o << endl;

Expand All @@ -493,13 +581,15 @@ namespace adiar
__printstat_prod3(o);
o << endl;

__printstat_reduce(o);
o << endl;

__printstat_quantify(o);
o << endl;

__printstat_substitute(o);
o << endl;

o << bold_on << "--== Bottom-Up Sweep Algorithms ==--" << bold_off << endl << endl;

__printstat_reduce(o);
#endif
}
}
Loading