From 36f3373c142c0bdf470f3bb5a462ea339b44cbfa Mon Sep 17 00:00:00 2001 From: Henry <henry.korb@geo.uu.se> Date: Tue, 14 Nov 2023 17:15:51 +0100 Subject: [PATCH] rename bindings for parallel library to parallel --- pythonbindings/CMakeLists.txt | 18 ++++---- pythonbindings/pyfluids-stubs/parallel.pyi | 46 +++++++++++++++++++ .../src/{communicator.cpp => parallel.cpp} | 24 ++++++---- 3 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 pythonbindings/pyfluids-stubs/parallel.pyi rename pythonbindings/src/{communicator.cpp => parallel.cpp} (75%) diff --git a/pythonbindings/CMakeLists.txt b/pythonbindings/CMakeLists.txt index 53700cc8d..c3cf182cb 100644 --- a/pythonbindings/CMakeLists.txt +++ b/pythonbindings/CMakeLists.txt @@ -41,15 +41,15 @@ target_include_directories(lbm_bindings PRIVATE ${CMAKE_SOURCE_DIR}/src/) target_include_directories(lbm_bindings PRIVATE ${CMAKE_BINARY_DIR}) add_dependencies(python_bindings lbm_bindings) -pybind11_add_module(communicator_bindings MODULE src/communicator.cpp) -set_target_properties( communicator_bindings PROPERTIES +pybind11_add_module(parallel_bindings MODULE src/parallel.cpp) +set_target_properties( parallel_bindings PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYFLUIDS_DIR} - OUTPUT_NAME "communicator") -target_link_libraries(communicator_bindings PRIVATE parallel) -target_include_directories(communicator_bindings PRIVATE ${CMAKE_SOURCE_DIR}/src/) -target_include_directories(communicator_bindings PRIVATE ${CMAKE_BINARY_DIR}) -target_compile_definitions(communicator_bindings PRIVATE VF_MPI) -add_dependencies(python_bindings communicator_bindings) + OUTPUT_NAME "parallel") +target_link_libraries(parallel_bindings PRIVATE parallel) +target_include_directories(parallel_bindings PRIVATE ${CMAKE_SOURCE_DIR}/src/) +target_include_directories(parallel_bindings PRIVATE ${CMAKE_BINARY_DIR}) +target_compile_definitions(parallel_bindings PRIVATE VF_MPI) +add_dependencies(python_bindings parallel_bindings) IF(BUILD_VF_GPU) @@ -105,5 +105,5 @@ endif() IF(BUILD_VF_GPU) target_compile_definitions(gpu_bindings PRIVATE VF_DOUBLE_ACCURACY) endif() - target_compile_definitions(communicator_bindings PRIVATE VF_DOUBLE_ACCURACY) + target_compile_definitions(parallel_bindings PRIVATE VF_DOUBLE_ACCURACY) endif() \ No newline at end of file diff --git a/pythonbindings/pyfluids-stubs/parallel.pyi b/pythonbindings/pyfluids-stubs/parallel.pyi new file mode 100644 index 000000000..a1f420de3 --- /dev/null +++ b/pythonbindings/pyfluids-stubs/parallel.pyi @@ -0,0 +1,46 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file parallel.pyi +! \ingroup bindings +! \author Henry Korb +======================================================================================= +""" + +from __future__ import annotations + +class Communicator: + @staticmethod + def get_instance() -> Communicator: ... + def get_number_of_processes(self) -> int: ... + def get_process_id(self) -> int: ... + +class MPICommunicator(Communicator): + @staticmethod + def get_instance() -> MPICommunicator: ... \ No newline at end of file diff --git a/pythonbindings/src/communicator.cpp b/pythonbindings/src/parallel.cpp similarity index 75% rename from pythonbindings/src/communicator.cpp rename to pythonbindings/src/parallel.cpp index cf5157fe4..9eac1b60b 100644 --- a/pythonbindings/src/communicator.cpp +++ b/pythonbindings/src/parallel.cpp @@ -33,17 +33,21 @@ #include <pybind11/cast.h> #include <pybind11/pybind11.h> +#include <parallel/Communicator.h> #include <parallel/MPICommunicator.h> -namespace communicator_bindings +namespace parallel { - namespace py = pybind11; +namespace py = pybind11; - PYBIND11_MODULE(communicator, m) - { - py::class_<vf::parallel::MPICommunicator, std::shared_ptr<vf::parallel::MPICommunicator>>(m, "Communicator") - .def_static("get_instance", &vf::parallel::MPICommunicator::getInstance) - .def("get_number_of_processes", &vf::parallel::MPICommunicator::getNumberOfProcesses) - .def("get_process_id", py::overload_cast<>(&vf::parallel::MPICommunicator::getProcessID, py::const_)); - } -} // namespace communicator_bindings +PYBIND11_MODULE(parallel, m) +{ +py::class_<vf::parallel::Communicator, std::shared_ptr<vf::parallel::Communicator>>(m, "Communicator") + .def_static("get_instance", &vf::parallel::Communicator::getInstance) + .def("get_process_id", py::overload_cast<>(&vf::parallel::Communicator::getProcessID, py::const_)) + .def("get_number_of_processes", &vf::parallel::Communicator::getNumberOfProcesses); + + py::class_<vf::parallel::MPICommunicator, vf::parallel::Communicator, std::shared_ptr<vf::parallel::MPICommunicator>>(m, "MPICommunicator") + .def_static("get_instance", &vf::parallel::MPICommunicator::getInstance); +} +} // namespace parallel -- GitLab