Skip to content

Commit

Permalink
#16: fix openmp availability check
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly committed May 7, 2024
1 parent 31c8200 commit 0a66707
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bindings/python/tv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,33 @@ void tvFromJson(const std::vector<std::string>& input_json_per_rank_list, const

assert(input_json_per_rank_list.size() == num_ranks && "Must have the same number of json files as ranks");

// Initialize the info object, that will hold data for all ranks for all phases
std::unique_ptr<Info> info = std::make_unique<Info>();

#ifdef VT_TV_N_THREADS
const int threads = VT_TV_N_THREADS;
#else
const int threads = 2;
#endif
#ifdef VT_TV_OPENMP_ENABLED
#if VT_TV_OPENMP_ENABLED
omp_set_num_threads(threads);
// print number of threads
fmt::print("vt-tv: Using {} threads\n", threads);
#endif

// Initialize the info object, that will hold data for all ranks for all phases
std::unique_ptr<Info> info = std::make_unique<Info>();

#ifdef VT_TV_OPENMP_ENABLED
# pragma omp parallel for
#endif
#endif
for (int64_t rank_id = 0; rank_id < num_ranks; rank_id++) {
fmt::print("Reading file for rank {}\n", rank_id);
std::string rank_json_str = input_json_per_rank_list[rank_id];
utility::JSONReader reader{static_cast<NodeType>(rank_id)};
reader.readString(rank_json_str);
auto tmpInfo = reader.parse();
#ifdef VT_TV_OPENMP_ENABLED
#if VT_TV_OPENMP_ENABLED
#pragma omp critical
#endif
#endif
{
info->addInfo(tmpInfo->getObjectInfo(), tmpInfo->getRank(rank_id));
}
Expand Down
2 changes: 2 additions & 0 deletions bindings/python/tv.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
#include <map>

#ifdef VT_TV_OPENMP_ENABLED
#if VT_TV_OPENMP_ENABLED
#include <omp.h>
#endif
#endif

namespace vt::tv::bindings::python {

Expand Down
4 changes: 4 additions & 0 deletions src/vt-tv/utility/parse_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,22 @@ void ParseRender::parseAndRender(PhaseType phase_id, std::unique_ptr<Info> info)
const int threads = 2;
#endif
#ifdef VT_TV_OPENMP_ENABLED
#if VT_TV_OPENMP_ENABLED
omp_set_num_threads(threads);
fmt::print("vt-tv: Using {} threads\n", threads);
# pragma omp parallel for
#endif
#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) + ".json");
auto tmpInfo = reader.parse();
#ifdef VT_TV_OPENMP_ENABLED
#if VT_TV_OPENMP_ENABLED
#pragma omp critical
#endif
#endif
{
info->addInfo(tmpInfo->getObjectInfo(), tmpInfo->getRank(rank));
}
Expand Down
2 changes: 2 additions & 0 deletions src/vt-tv/utility/parse_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
#include <memory>

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

/**
Expand Down

0 comments on commit 0a66707

Please sign in to comment.