diff --git a/dumux/assembly/fvassembler.hh b/dumux/assembly/fvassembler.hh index 5006331d43126b81d5d70cc11bd90c9771ac3a38..c83d1ae1e10a9dfde34331c537bbae3d9d4d418b 100644 --- a/dumux/assembly/fvassembler.hh +++ b/dumux/assembly/fvassembler.hh @@ -33,6 +33,8 @@ #include #include +#include + #include #include @@ -153,6 +155,7 @@ public: { static_assert(isImplicit, "Explicit assembler for stationary problem doesn't make sense!"); enableMultithreading_ = SupportsColoring::value + && Grid::Capabilities::supportsMultithreading(gridGeometry_->gridView()) && !Multithreading::isSerial() && getParam("Assembly.Multithreading", true); @@ -177,6 +180,7 @@ public: , isStationaryProblem_(!timeLoop) { enableMultithreading_ = SupportsColoring::value + && Grid::Capabilities::supportsMultithreading(gridGeometry_->gridView()) && !Multithreading::isSerial() && getParam("Assembly.Multithreading", true); diff --git a/dumux/common/gridcapabilities.hh b/dumux/common/gridcapabilities.hh index 1ed27e7dea37f178c84be32bdc3b37c94a9f5750..3806be646751b7acc3e77d5e2867030252c32157 100644 --- a/dumux/common/gridcapabilities.hh +++ b/dumux/common/gridcapabilities.hh @@ -66,4 +66,26 @@ static constexpr bool canCommunicate = } // namespace Dumux +namespace Dumux::Grid::Capabilities { + +// Default implementation +// The grid capability gives an absolute guarantee +// however this does not mean that multithreading is not +// supported at all. It might still work for some special cases. +// This knowledge is encoded in specializations for the different +// grid managers, see dumux/grid/io/gridmanager_*.hh +template +struct MultithreadingSupported +{ + template + static bool eval(const GV&) // default is independent of the grid view + { return Dune::Capabilities::viewThreadSafe::v; } +}; + +template +inline bool supportsMultithreading(const GridView& gridView) +{ return MultithreadingSupported::eval(gridView); } + +} // namespace Dumux::Grid::Capabilities + #endif diff --git a/dumux/io/grid/gridmanager_alu.hh b/dumux/io/grid/gridmanager_alu.hh index 274837e55e823335cadf261c6001c39c601eae83..8efb1700a0a25009b9b6161eb6d65c3949267e3b 100644 --- a/dumux/io/grid/gridmanager_alu.hh +++ b/dumux/io/grid/gridmanager_alu.hh @@ -35,6 +35,7 @@ #endif #include +#include namespace Dumux { @@ -248,6 +249,20 @@ private: int flag_; }; +namespace Grid::Capabilities { + +// To the best of our knowledge ALUGrid is view thread-safe +// This specialization can be removed after we depend on Dune release 2.9 in which this is guaranteed by ALUGrid itself +template +struct MultithreadingSupported> +{ + template + static bool eval(const GV&) // default is independent of the grid view + { return true; } +}; + +} // end namespace Grid::Capabilities + #endif // HAVE_DUNE_ALUGRID } // end namespace Dumux diff --git a/dumux/io/grid/gridmanager_foam.hh b/dumux/io/grid/gridmanager_foam.hh index 8ca5a5633231cabb51701e5bf9532c98bc764da3..2d78016dd086c8450be8e98cef1ca580af0f1527 100644 --- a/dumux/io/grid/gridmanager_foam.hh +++ b/dumux/io/grid/gridmanager_foam.hh @@ -34,6 +34,8 @@ #include #endif +#include + namespace Dumux { #if HAVE_DUNE_FOAMGRID @@ -163,6 +165,20 @@ public: } }; +namespace Grid::Capabilities { + +// To the best of our knowledge FoamGrid is view thread-safe +// This specialization can be removed after we depend on Dune release 2.9 in which this is guaranteed by FoamGrid itself +template +struct MultithreadingSupported> +{ + template + static bool eval(const GV&) // default is independent of the grid view + { return true; } +}; + +} // end namespace Grid::Capabilities + #endif // HAVE_DUNE_FOAMGRID } // end namespace Dumux diff --git a/dumux/io/grid/gridmanager_ug.hh b/dumux/io/grid/gridmanager_ug.hh index 0ac7b59aeec1178e654e6d95f04c509735e39dcc..201a427125764a4571e053088ba031ec53771826 100644 --- a/dumux/io/grid/gridmanager_ug.hh +++ b/dumux/io/grid/gridmanager_ug.hh @@ -33,6 +33,8 @@ #include #endif +#include + namespace Dumux { #if HAVE_DUNE_UGGRID @@ -175,6 +177,20 @@ private: } }; +namespace Grid::Capabilities { + +// To the best of our knowledge UGGrid is view thread-safe for sequential runs +// This specialization maybe be removed after we depend on Dune release 2.9 if is guaranteed by UGGrid itself by then +template +struct MultithreadingSupported> +{ + template + static bool eval(const GV& gv) // default is independent of the grid view + { return gv.comm().size() <= 1; } +}; + +} // end namespace Grid::Capabilities + #endif // HAVE_DUNE_UGGRID } // end namespace Dumux diff --git a/dumux/io/grid/gridmanager_yasp.hh b/dumux/io/grid/gridmanager_yasp.hh index 5e7450b029a56608fa5e9b4abaa56fd562e72593..88095d416ca09c8e2c08313e7049a373208643a3 100644 --- a/dumux/io/grid/gridmanager_yasp.hh +++ b/dumux/io/grid/gridmanager_yasp.hh @@ -33,6 +33,8 @@ #include #endif +#include + namespace Dumux { /*! @@ -434,6 +436,20 @@ private: } }; +namespace Grid::Capabilities { + +// To the best of our knowledge YaspGrid is view thread-safe +// This specialization can be removed after we depend on Dune release 2.9 and this is guaranteed by YaspGrid itself +template +struct MultithreadingSupported> +{ + template + static bool eval(const GV& gv) // default is independent of the grid view + { return true; } +}; + +} // end namespace Grid::Capabilities + } // end namespace Dumux #endif diff --git a/dumux/multidomain/fvassembler.hh b/dumux/multidomain/fvassembler.hh index 4603259c5f99803506f5c04ccb5256b33aaf642e..2673368433ef44531b58ba52fbfc4f55b1ee30e6 100644 --- a/dumux/multidomain/fvassembler.hh +++ b/dumux/multidomain/fvassembler.hh @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,26 @@ namespace Dumux { +namespace Grid::Capabilities { + +namespace Detail { +// helper for multi-domain models +template +bool allGridsSupportsMultithreadingImpl(const T& gridGeometries, std::index_sequence) +{ + return (... && supportsMultithreading(std::get(gridGeometries)->gridView())); +} +} // end namespace Detail + +// helper for multi-domain models (all grids have to support multithreading) +template +bool allGridsSupportsMultithreading(const std::tuple& gridGeometries) +{ + return Detail::allGridsSupportsMultithreadingImpl>(gridGeometries, std::make_index_sequence()); +} + +} // end namespace Grid::Capabilities + /*! * \ingroup MultiDomain * \ingroup Assembly @@ -182,6 +203,7 @@ public: std::cout << "Instantiated assembler for a stationary problem." << std::endl; enableMultithreading_ = CouplingManagerSupportsMultithreadedAssembly::value + && Grid::Capabilities::allGridsSupportsMultithreading(gridGeometryTuple_) && !Multithreading::isSerial() && getParam("Assembly.Multithreading", true); @@ -211,6 +233,7 @@ public: std::cout << "Instantiated assembler for an instationary problem." << std::endl; enableMultithreading_ = CouplingManagerSupportsMultithreadedAssembly::value + && Grid::Capabilities::allGridsSupportsMultithreading(gridGeometryTuple_) && !Multithreading::isSerial() && getParam("Assembly.Multithreading", true);