Skip to content

Commit

Permalink
PyTrilinos2: Add Thyra and Stratimikos
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Glusa <[email protected]>
  • Loading branch information
cgcgcg committed Dec 21, 2024
1 parent 04eb5c4 commit 9aedfd1
Show file tree
Hide file tree
Showing 17 changed files with 618 additions and 103 deletions.
24 changes: 16 additions & 8 deletions packages/PyTrilinos2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- cmake -*-


# Set the package name
TRIBITS_PACKAGE(PyTrilinos2 DISABLE_STRONG_WARNINGS)

Expand All @@ -27,11 +24,11 @@ PYTRILINOS2_CMAKE_ERROR
ON )

TRIBITS_ADD_OPTION_AND_DEFINE(PyTrilinos2_BINDER_VERBOSE
PYTRILINOS2_B_VERBOSE
PYTRILINOS2_VERBOSE
"Increase the verbosity of binder."
OFF )

SET(PyTrilinos2_BINDER_NUM_FILES "100" CACHE STRING "Maxinum number of generated files by binder.")
SET(PyTrilinos2_BINDER_NUM_FILES "150" CACHE STRING "Maxinum number of generated files by binder.")

MESSAGE("-- Python3_EXECUTABLE:")
IF(NOT DEFINED ${Python3_EXECUTABLE})
Expand Down Expand Up @@ -212,6 +209,10 @@ add_custom_command(
add_custom_target(generate_include_name DEPENDS ${binder_include_name})
add_dependencies(generate_include_name generate_ETI_name)

ASSERT_DEFINED(
${PACKAGE_NAME}_ENABLE_MueLu
)

set(BINDER_OPTIONS "")
list(APPEND BINDER_OPTIONS --root-module PyTrilinos2)
list(APPEND BINDER_OPTIONS --prefix ${CMAKE_CURRENT_BINARY_DIR}/binder)
Expand All @@ -223,8 +224,13 @@ ELSE()
ENDIF()
list(APPEND BINDER_OPTIONS --bind Teuchos)
list(APPEND BINDER_OPTIONS --bind Tpetra)
list(APPEND BINDER_OPTIONS --bind MueLu)
IF(PYTRILINOS2_B_VERBOSE)
list(APPEND BINDER_OPTIONS --bind Thyra)
list(APPEND BINDER_OPTIONS --bind ThyraTpetraAdapters)
list(APPEND BINDER_OPTIONS --bind Stratimikos)
IF(${PACKAGE_NAME}_ENABLE_MueLu)
list(APPEND BINDER_OPTIONS --bind MueLu)
ENDIF()
IF(PYTRILINOS2_VERBOSE)
list(APPEND BINDER_OPTIONS -v)
ENDIF()
IF(PYTRILINOS2_SUPPRESS_ERRORS)
Expand Down Expand Up @@ -346,7 +352,9 @@ ADD_SUBDIRECTORY( src )
file(COPY ${PyTrilinos2PyFiles} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/PyTrilinos2/.)
#file(COPY ${PyTrilinos2PyFilesSo} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/PyTrilinos2/.)

SET(PyTrilinos2_PYTHONPATH "${CMAKE_CURRENT_BINARY_DIR}:$ENV{PYTHONPATH}")
SET(PyTrilinos2_PYTHONPATH "${CMAKE_CURRENT_BINARY_DIR}")

TRIBITS_ADD_EXAMPLE_DIRECTORIES(examples)

TRIBITS_ADD_TEST_DIRECTORIES(test)

Expand Down
8 changes: 5 additions & 3 deletions packages/PyTrilinos2/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
SET(LIB_REQUIRED_DEP_PACKAGES
Teuchos
Tpetra
MueLu
)
SET(LIB_OPTIONAL_DEP_PACKAGES)
Thyra
ThyraTpetraAdapters
Stratimikos
)
SET(LIB_OPTIONAL_DEP_PACKAGES MueLu)
SET(TEST_REQUIRED_DEP_PACKAGES)
SET(TEST_OPTIONAL_DEP_PACKAGES)
SET(LIB_REQUIRED_DEP_TPLS)
Expand Down
8 changes: 5 additions & 3 deletions packages/PyTrilinos2/cmake/PyTrilinos2MakeTest.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

MACRO(PyTrilinos2_MAKE_MPI_TEST TEST_NAME)

FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_NAME}.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

TRIBITS_ADD_TEST(
${Python3_EXECUTABLE}
NOEXEPREFIX
NOEXESUFFIX
NAME ${TEST_NAME}
ARGS "${TEST_NAME}.py"
PASS_REGULAR_EXPRESSION "OK"
ENVIRONMENT "PYTHONPATH=${PyTrilinos2_PYTHONPATH}"
ENVIRONMENT "PYTHONPATH=${PyTrilinos2_PYTHONPATH}:$ENV{PYTHONPATH}"
${ARGN}
)

TRIBITS_COPY_FILES_TO_BINARY_DIR(${TEST_NAME}_cp
SOURCE_FILES ${TEST_NAME}.py
CATEGORIES BASIC)

ENDMACRO(PyTrilinos2_MAKE_MPI_TEST TEST_NAME)
6 changes: 6 additions & 0 deletions packages/PyTrilinos2/cmake/PyTrilinos2_config.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef PYTILINOS2_CONFIG_HPP
#define PYTILINOS2_CONFIG_HPP

#cmakedefine HAVE_PYTRILINOS2_MUELU

#endif
3 changes: 3 additions & 0 deletions packages/PyTrilinos2/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INCLUDE(PyTrilinos2MakeTest)

PyTrilinos2_MAKE_MPI_TEST(exampleCG)
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def main():
plt.plot(x0_view)
plt.savefig('x0_view.png', dpi=800, bbox_inches='tight',pad_inches = 0)

success = True
if comm.getRank() == 0:
if success:
print("OK")
else:
print("FAIL")


if __name__ == "__main__":
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
Expand Down
2 changes: 2 additions & 0 deletions packages/PyTrilinos2/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
__version__ = '0.1.0'
def version():
return 'PyTrilinos2 version: ' + __version__

from . PyTrilinos2 import *
201 changes: 119 additions & 82 deletions packages/PyTrilinos2/scripts/PyTrilinos2_config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,77 @@

+include <pybind11/stl.h>
+include <pybind11/stl_bind.h>

# Standard library
-class std::basic_ios
-class std::vector
-class std::map
-class std::integral_constant
-class std::iterator
-class std::reverse_iterator
-class std::set

# OpenMPI
-class ompi_status_public_t
-class ompi_request_t
-class ompi_errhandler_t
-class ompi_communicator_t

###############################################################################
# Teuchos
+include <Teuchos_RCP.hpp>
+custom_shared Teuchos::RCP

+include_for_namespace Teuchos <PyTrilinos2_Teuchos_Custom.hpp>
+add_on_binder_for_namespace Teuchos def_Teuchos_functions
+add_on_binder_for_namespace Tpetra def_initialize_Kokkos

+custom_shared Teuchos::RCP

-namespace Teuchos::Details

-function Teuchos::Ptr::operator->
-function Teuchos::Ptr::get
-function Teuchos::Ptr::getRawPtr
-function Teuchos::Array::data
-function Teuchos::Array::getRawPtr
-function Teuchos::ArrayRCP::getRawPtr
-function Teuchos::ArrayView::access_private_ptr
-function Teuchos::ArrayView::begin
-function Teuchos::ArrayView::end
-function Teuchos::ArrayView::data
-function Teuchos::ArrayView::getRawPtr
-class Teuchos::ArrayRCP<void>
-class Teuchos::ArrayRCP<const void>
-class Teuchos::Array<bool>
-class Teuchos::Ptr<int>
-class Teuchos::Ptr<long>
-class Teuchos::Ptr<long int>
-class Teuchos::Ptr<long long>
-class Teuchos::Ptr<unsigned long>
-class Teuchos::Ptr<long long int>
-class Teuchos::Ptr<long unsigned int>
-class Teuchos::Ptr<bool>
-class Teuchos::Ptr<double>

+add_on_binder Teuchos::ParameterList def_ParameterList_member_functions
-function Teuchos::ParameterList::sublist
-function Teuchos::ParameterList::set
-function Teuchos::ParameterList::get
+add_on_binder Teuchos::ParameterList def_ParameterList_member_functions
+include_for_namespace Tpetra <PyTrilinos2_Tpetra_Custom.hpp>
+add_on_binder Tpetra::CrsGraph define_CrsGraph_member_functions
+include <PyTrilinos2_Tpetra_Types.hpp>
+add_on_binder Tpetra::CrsMatrix define_CrsMatrix_member_functions
+add_on_binder Tpetra::Vector define_Vector_member_functions
+add_on_binder Tpetra::MultiVector define_MultiVector_member_functions
-class Kokkos::View
-class Kokkos::DualView
-class Teuchos::ParameterListAcceptorDefaultBase

-class Teuchos::PromotionTraits
-function Teuchos::Serializer::createObj
-function Teuchos::TimeMonitor::computeGlobalTimerStatistics
-class Teuchos::CommandLineProcessor::enum_opt_data_t
-class Teuchos::CommandLineProcessor::TimeMonitorSurrogate
-class Teuchos::RawWorkspace
-function Teuchos::getRawMpiComm
-function Teuchos::rcp_dynamic_cast
-function Teuchos::ptr_dynamic_cast
-class Teuchos::BLAS
-class Teuchos::Describable

###############################################################################
# Kokkos
-namespace Kokkos::Impl
-namespace KokkosBlas
-include <Cuda/Kokkos_Cuda_Instance.hpp>
Expand Down Expand Up @@ -91,88 +145,71 @@
-include <OpenMP/Kokkos_OpenMP_Instance.hpp>
-include <impl/Kokkos_HostThreadTeam.hpp>
-include <impl/Kokkos_InitializationSettings.hpp>
-class Teuchos::ArrayView<ompi_status_public_t>
-class Teuchos::ArrayView<const ompi_status_public_t>
-class Teuchos::Serializer
-class Teuchos::PromotionTraits
-class Teuchos::CommandLineProcessor
-class Teuchos::Ptr<Teuchos::RCP<Teuchos::CommRequest<int> >>
-class Teuchos::ArrayView<Teuchos::RCP<Teuchos::CommRequest<int> >>
-class Teuchos::TimeMonitor
-include <View/Kokkos_ViewLegacy.hpp>
-include <View/Kokkos_ViewTraits.hpp>
-include <View/Kokkos_ViewMapping.hpp>
-class Kokkos::Device
-class Kokkos::DualView
-class Kokkos::DynRankView
-class Kokkos::View

###############################################################################
# Tpetra
+add_on_binder_for_namespace Tpetra def_initialize_Kokkos
+include_for_namespace Tpetra <PyTrilinos2_Tpetra_Custom.hpp>
+include <PyTrilinos2_Tpetra_Types.hpp>
+add_on_binder Tpetra::CrsGraph define_CrsGraph_member_functions
+add_on_binder Tpetra::Vector define_Vector_member_functions
+add_on_binder Tpetra::MultiVector define_MultiVector_member_functions
+add_on_binder Tpetra::CrsMatrix define_CrsMatrix_member_functions
-namespace Tpetra::Details
-namespace Tpetra::Import_Util
-namespace Teuchos::Details
-namespace Tpetra::KokkosRefactor
-function Tpetra::Details::isInterComm
-function Tpetra::SrcDistObject::operator=
-function Teuchos::TimeMonitor::computeGlobalTimerStatistics
-function Teuchos::mpiErrorCodeToString
-class Teuchos::CommandLineProcessor::enum_opt_data_t
-class Teuchos::CommandLineProcessor::TimeMonitorSurrogate
-class Teuchos::RawWorkspace
-class std::ostream
-class std::basic_ios
-class std::vector
-class std::map
-class std::integral_constant
-class std::integral_constant
-class std::iterator
-class std::reverse_iterator
-class Teuchos::ArrayView
-class Teuchos::ArrayRCP
-class Teuchos::Array
-class Teuchos::Describable
-class Teuchos::BLAS
-function Teuchos::fancyOStream
-class Teuchos::ParameterListAcceptorDefaultBase
-class Teuchos::Dependency
-class Teuchos::DependencySheet
-class Teuchos::MpiCommRequestBase<int>
-function Teuchos::getRawMpiComm
-class Teuchos::OpaqueWrapper<ompi_communicator_t *>
-class Teuchos::OpaqueWrapper<ompi_errhandler_t *>
-function Teuchos::Details::setMpiReductionOp
-function Teuchos::Details::getMpiOpForEReductionType
-function Tpetra::Details::extractMpiCommFromTeuchos
-class Teuchos::OpaqueWrapper<ompi_errhandler_t *>
-function Teuchos::Details::setMpiReductionOp
-function Teuchos::Details::getMpiOpForEReductionType
-function Tpetra::Details::PackCrsGraphImpl::packRow
-class Tpetra::BlockCrsMatrix
-class Tpetra::Details::DistributorPlan
-class Tpetra::Directory
-class Tpetra::Distribution
-class Tpetra::Distribution1D
-class Tpetra::Distribution2D
-class Tpetra::DistributionLowerTriangularBlock
-class Tpetra::DistributionMM
-class Tpetra::DistributionType
-namespace Xpetra
-class Thyra::VectorSpaceBase
-class Thyra::ProductVectorSpace
-class Tpetra::Details::DistributorPlan
-class Tpetra::Distributor
-class Tpetra::DistributionType
-class Tpetra::LowerTriangularBlockOperator
-class Tpetra::distributorSendTypes
-class Tpetra::ImportExportData
-function Tpetra::Details::extractMpiCommFromTeuchos
-function Tpetra::Details::isInterComm
-function Tpetra::Details::PackCrsGraphImpl::packRow
-function Tpetra::SrcDistObject::operator=

###############################################################################
# Xpetra
-namespace Xpetra

###############################################################################
# MueLu
-class MueLu::BaseClass
-class MueLu::Describable
-class MueLu::FactoryAcceptor
-class MueLu::FactoryBase
-class MueLu::FactoryFactory
-class MueLu::FactoryManagerBase
-class MueLu::FactoryManager
-class MueLu::FactoryBase
-class MueLu::FactoryManagerBase
-class MueLu::Hierarchy
-class MueLu::HierarchyManager
-class MueLu::Level
-class MueLu::TimeMonitor
-class MueLu::Describable
-class Kokkos::Device
-class Tpetra::DistributionType
-class Tpetra::Directory
-class Tpetra::Distribution
-class Tpetra::Distribution1D
-class Tpetra::Distribution2D
-class Tpetra::DistributionMM
-class Tpetra::DistributionLowerTriangularBlock
-class MueLu::BaseClass
-function Teuchos::rcp_dynamic_cast
-class Teuchos::VerboseObjectBase
-class MueLu::VerboseObject
-class Tpetra::BlockCrsMatrix
-class Kokkos::DynRankView
-class MueLu::VariableContainer
-class Tpetra::LowerTriangularBlockOperator
-class MueLu::Level
-class MueLu::Hierarchy
-class std::set
-class Teuchos::Ptr
-class MueLu::VerboseObject
+include <Stratimikos_MueLuHelpers.hpp>

###############################################################################
# Thyra
+include <Thyra_VectorSpaceFactoryBase.hpp>
-class Thyra::ProductVectorSpace
-class Thyra::RowStatLinearOpBase
-class Thyra::ScaledLinearOpBase
-class Thyra::LinearOpSourceBase
+include_for_namespace Thyra <PyTrilinos2_Thyra_Custom.hpp>
+add_on_binder Thyra::LinearOpWithSolveBase define_solve
9 changes: 5 additions & 4 deletions packages/PyTrilinos2/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TRIBITS_CONFIGURE_FILE(${PACKAGE_NAME}_config.hpp)

FILE(GLOB PYTRILINOS2_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
MESSAGE("PYTRILINOS2_SRC = ${PYTRILINOS2_SRC}")
# MESSAGE("PYTRILINOS2_SRC = ${PYTRILINOS2_SRC}")
FILE(COPY ${PYTRILINOS2_SRC} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

list(APPEND PYTRILINOS2_SRC ${CMAKE_CURRENT_BINARY_DIR}/../binder/PyTrilinos2.cpp)
Expand All @@ -23,15 +24,15 @@ IF(NOT PYTRILINOS2_USE_ONE_FILE)
)
ENDIF()

MESSAGE("PYTRILINOS2_SRC with binder = ${PYTRILINOS2_SRC}")
# MESSAGE("PYTRILINOS2_SRC with binder = ${PYTRILINOS2_SRC}")

pybind11_add_module(PyTrilinos2 ${PYTRILINOS2_SRC})

add_dependencies(PyTrilinos2 binder_call generate_ETI_name generate_include_name checkBinderNumFiles)
target_include_directories(PyTrilinos2 PUBLIC ${Mpi4Py_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(PyTrilinos2 PUBLIC cxx_std_14)

foreach(depPkg IN LISTS PyTrilinos2_LIB_ENABLED_DEPENDENCIES)
foreach(depPkg IN LISTS PyTrilinos2_LIB_ENABLED_DEPENDENCIES)
target_link_libraries(PyTrilinos2 PUBLIC ${depPkg}::all_libs)
endforeach()
target_link_libraries(PyTrilinos2 PUBLIC ${Trilinos_EXTRA_LINK_FLAGS})
Expand All @@ -43,4 +44,4 @@ INSTALL(TARGETS PyTrilinos2
add_custom_command(TARGET PyTrilinos2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/PyTrilinos2.so ${CMAKE_CURRENT_BINARY_DIR}/../PyTrilinos2/.
COMMENT "Copy ${PROJECT_BINARY_DIR}/src/PyTrilinos2.so"
)
)
Loading

0 comments on commit 9aedfd1

Please sign in to comment.