Skip to content

Commit

Permalink
#8: use std::filestystem to get all data files in input directory; cl…
Browse files Browse the repository at this point in the history
…ean up OpenMP preprocessing
  • Loading branch information
cwschilly committed Aug 26, 2024
1 parent 29178d0 commit 931d8b7
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 35 deletions.
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ option(VT_TV_PYTHON_BINDINGS_ENABLED "Build vt-tv with Python bindings" OFF)
option(VT_TV_OPENMP_ENABLED "Build vt-tv with openMP support" ON)
option(VT_TV_TESTS_ENABLED "Build vt-tv with unit tests" ON)
option(VT_TV_COVERAGE_ENABLED "Build vt-tv with coverage" OFF)
set(VT_TV_N_THREADS "2" CACHE STRING "Number of OpenMP threads to use")

# add -fPIC to all targets (if building with nanobind)
if(VT_TV_PYTHON_BINDINGS_ENABLED)
Expand All @@ -41,18 +42,20 @@ endif()

option(VT_TV_WERROR_ENABLED "Build vt-tv with warnings as errors" OFF)

set(VT_TV_N_THREADS "2" CACHE STRING "Number of OpenMP threads to use")

include(cmake/load_packages.cmake)

if(APPLE)
add_compile_options(-ffat-lto-objects)
endif()

add_definitions(-DVT_TV_N_THREADS=${VT_TV_N_THREADS})
add_definitions(-DVT_TV_OPENMP_ENABLED=${VT_TV_OPENMP_ENABLED})
add_compile_definitions(SRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_compile_definitions(BUILD_DIR="${CMAKE_BINARY_DIR}")
if(VT_TV_OPENMP_ENABLED)
add_definitions(-DVT_TV_OPENMP_ENABLED=1)
else()
add_definitions(-DVT_TV_OPENMP_ENABLED=0)
endif()

add_custom_target(vt_tv_examples)
add_custom_target(vt_tv_tests)
Expand Down
59 changes: 32 additions & 27 deletions src/vt-tv/utility/parse_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ void ParseRender::parseAndRender(PhaseType phase_id, std::unique_ptr<Info> info)
std::string input_dir = config["input"]["directory"].as<std::string>();
std::filesystem::path input_path(input_dir);

// Allow user to point to specific files (e.g. json.br)
std::string file_suffix = config["input"]["suffix"].as<std::string>("json");

// If it's a relative path, prepend the SRC_DIR
if (input_path.is_relative()) {
input_path = std::filesystem::path(SRC_DIR) / input_path;
Expand All @@ -80,34 +77,44 @@ void ParseRender::parseAndRender(PhaseType phase_id, std::unique_ptr<Info> info)
std::filesystem::path p = input_dir;
std::string path = std::filesystem::absolute(p).string();

// Collect all file paths into a vector
std::vector<std::filesystem::path> data_files;
for (const auto& entry : std::filesystem::directory_iterator(input_dir)) {
data_files.push_back(entry.path());
}

info = std::make_unique<Info>();

#ifdef VT_TV_OPENMP_ENABLED
#if VT_TV_OPENMP_ENABLED
#ifdef VT_TV_N_THREADS
const int threads = VT_TV_N_THREADS;
#else
const int threads = 2;
#endif // VT_TV_N_THREADS
omp_set_num_threads(threads);
fmt::print("vt-tv: Using {} threads\n", threads);
# pragma omp parallel for
#endif
const int threads = VT_TV_N_THREADS;
omp_set_num_threads(threads);
fmt::print("vt-tv: Using {} threads\n", threads);
# pragma omp parallel for
#endif // VT_TV_OPENMP_ENABLED
for (int64_t rank = 0; rank < n_ranks; rank++) {
fmt::print("Reading file for rank {}\n", rank);
utility::JSONReader reader{static_cast<NodeType>(rank)};
reader.readFile(input_dir + "data." + std::to_string(rank) + "." + file_suffix);
auto tmpInfo = reader.parse();
#ifdef VT_TV_OPENMP_ENABLED
#if VT_TV_OPENMP_ENABLED
#pragma omp critical
#endif
#endif
{

for (uint64_t i = 0; i < data_files.size(); i++) {
auto filepath = data_files[i].string();
auto filename = data_files[i].filename().string();

int64_t rank;
auto first_dot = filename.find(".");
auto next_dot = filename.find(".", first_dot + 1);

rank = std::stoll(filename.substr(first_dot + 1, next_dot - first_dot - 1));

fmt::print("Reading file for rank {}\n", rank);
utility::JSONReader reader{static_cast<NodeType>(rank)};
reader.readFile(filepath);
auto tmpInfo = reader.parse();
#if VT_TV_OPENMP_ENABLED
# pragma omp critical
#endif
{
info->addInfo(tmpInfo->getObjectInfo(), tmpInfo->getRank(rank));
}
}
}
assert(info->getNumRanks() == static_cast<std::size_t>(n_ranks));
fmt::print("Num ranks={}\n", info->getNumRanks());
}

std::array<std::string, 3> qoi_request = {
Expand Down Expand Up @@ -153,8 +160,6 @@ void ParseRender::parseAndRender(PhaseType phase_id, std::unique_ptr<Info> info)

output_file_stem = config["output"]["file_stem"].as<std::string>("vttv");

fmt::print("Num ranks={}\n", info->getNumRanks());

if (config["output"]["window_size"]) {
win_size = config["output"]["window_size"].as<uint64_t>(2000);
// Update font_size with new win_size
Expand Down
4 changes: 1 addition & 3 deletions src/vt-tv/utility/parse_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@
#include <limits>
#include <memory>

#ifdef VT_TV_OPENMP_ENABLED
#if VT_TV_OPENMP_ENABLED
#include <omp.h>
#endif
#include <omp.h>
#endif
namespace vt::tv::utility {

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed tests/data/synthetic_attributes/data.0.json.br
Binary file not shown.
Binary file removed tests/data/synthetic_attributes/data.1.json.br
Binary file not shown.
Binary file removed tests/data/synthetic_attributes/data.2.json.br
Binary file not shown.
Binary file removed tests/data/synthetic_attributes/data.3.json.br
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/unit/utility/test_json_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ TEST_F(JSONReaderTest, test_json_reader_1) {
}
}

TEST_F(JSONReaderTest, test_json_reader_metadata_attributes) {
std::filesystem::path p = std::filesystem::path(SRC_DIR) / "tests/data/lb_test_data" ;
TEST_F(TestJSONReader, test_json_reader_metadata_attributes) {
std::filesystem::path p = std::filesystem::path(SRC_DIR) / "tests/unit/reader_test_data" ;
std::string path = std::filesystem::absolute(p).string();

NodeType rank = 0;
Expand Down

0 comments on commit 931d8b7

Please sign in to comment.