Skip to content

Commit

Permalink
#16: Improve OpenMP integration
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrepebay committed May 7, 2024
1 parent 5d82a9a commit 512d0da
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")

option(VT_TV_PYTHON_BINDINGS_ENABLED "Build vt-tv with Python bindings" ON)
option(VT_TV_OPENMP_ENABLED "Build vt-tv with openMP support" ON)
option(VT_TV_N_THREADS "Number of threads to use" 2)

include(cmake/load_packages.cmake)

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

if(VT_TV_OPENMP_ENABLED)
set(VT_TV_NUM_THREADS "2" CACHE STRING "Number of threads to use")
add_definitions(-DVT_TV_NUM_THREADS=${VT_TV_NUM_THREADS})
add_definitions(-DVT_TV_OPENMP_ENABLED=${VT_TV_OPENMP_ENABLED})
endif()
add_definitions(-DVT_TV_N_THREADS=${VT_TV_N_THREADS})
add_definitions(-DVT_TV_OPENMP_ENABLED=${VT_TV_OPENMP_ENABLED})

add_custom_target(vt_tv_examples)
add_custom_target(vt_tv_tests)
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/tv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ 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");

#ifdef VT_TV_NUM_THREADS
const int threads = VT_TV_NUM_THREADS;
#ifdef VT_TV_N_THREADS
const int threads = VT_TV_N_THREADS;
#else
const int threads = 2;
#endif
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def build_extension(self, ext):
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DVTK_DIR=' + vtk_dir,
'-DVT_TV_NUM_THREADS=' + str(n_threads)]
'-DVT_TV_N_THREADS=' + str(n_threads)]

if sys.platform == "darwin":
import platform
Expand Down
5 changes: 3 additions & 2 deletions src/vt-tv/utility/parse_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ void ParseRender::parseAndRender(PhaseType phase_id, std::unique_ptr<Info> info)

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

#ifdef VT_TV_NUM_THREADS
const int threads = VT_TV_NUM_THREADS;
#ifdef VT_TV_N_THREADS
const int threads = VT_TV_N_THREADS;
#else
const int threads = 2;
#endif
#ifdef VT_TV_OPENMP_ENABLED
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++) {
Expand Down

0 comments on commit 512d0da

Please sign in to comment.