diff --git a/common/geometrytype.hh b/common/geometrytype.hh index 11a3bcab2256c1ada3cbe6e79a4a2ec68a9a1bef..7ac491ad4480cacecd34f13ca04dc8262172b00e 100644 --- a/common/geometrytype.hh +++ b/common/geometrytype.hh @@ -27,7 +27,8 @@ namespace Dune { simplex, //!< Simplicial element in any nonnegative dimension cube, //!< Cube element in any nonnegative dimension pyramid, //!< Four sided pyramid in three dimensions - prism //!< Prism element in three dimensions + prism, //!< Prism element in three dimensions + undefined }; private: @@ -36,11 +37,12 @@ namespace Dune { BasicType basicType_ : 16; /** \brief Dimension of the element */ - short dim_; + unsigned int dim_; public: /** \brief Default constructor, not initializing anything */ - GeometryType () {} + GeometryType () + {} /** \brief Constructor */ GeometryType(BasicType basicType, unsigned int dim) diff --git a/common/mpihelper.hh b/common/mpihelper.hh new file mode 100644 index 0000000000000000000000000000000000000000..d3984d05803785f9c878886ca49f6ebe13e74b7c --- /dev/null +++ b/common/mpihelper.hh @@ -0,0 +1,185 @@ +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set et ts=4 sw=2 sts=2: +// $Id: $ +#ifndef DUNE_MPIHELPER +#define DUNE_MPIHELPER +#if HAVE_MPI +#include "mpi.h" +#endif + +namespace Dune +{ + + class FakeMPIHelper + { + public: + /** + * @brief A simple smart pointer responsible for creation + * and deletion of the instance. + */ + class InstancePointer + { + public: + /** @brief Construct a null pointer. */ + InstancePointer() : pointer_(0) + {} + /** @brief Delete the instance we point to. */ + ~InstancePointer() + { + if(pointer_ != 0) + delete pointer_; + } + /** + * @brief Get a pointer to the instance. + * @return The instance we store. + */ + FakeMPIHelper* get() + { + return pointer_; + } + /** + * @brief Set the pointer. + * @paramter pointer A pointer to the instance. + */ + void set(FakeMPIHelper* pointer) + { + if(pointer != 0) { + delete pointer_; + pointer_ = pointer; + } + } + private: + FakeMPIHelper* pointer_; + }; + public: + enum { + /** + * @brief Are we fake (i. e. pretend to have MPI support but are compiled + * without. + */ + isFake = true + }; + + + /** + * @brief The type of the mpi communicator. + */ + typedef int MPICommunicator; + + static MPICommunicator getCommunicator() + { + return -1; + } + + static FakeMPIHelper& instance(int argc, char** argv) + { + if(instance_.get() == 0) + instance_.set(new FakeMPIHelper()); + return *instance_.get(); + } + + private: + FakeMPIHelper() + {} + FakeMPIHelper(const FakeMPIHelper&); + FakeMPIHelper& operator=(const FakeMPIHelper); + + static InstancePointer instance_; + }; + + FakeMPIHelper::InstancePointer FakeMPIHelper::instance_ = FakeMPIHelper::InstancePointer(); + +#ifdef HAVE_MPI + + class MPIHelper + { + public: + /** + * @brief A simple smart pointer responsible for creation + * and deletion of the instance. + */ + class InstancePointer + { + public: + /** @brief Construct a null pointer. */ + InstancePointer() : pointer_(0) + {} + /** @brief Delete the instance we point to. */ + ~InstancePointer() + { + if(pointer_ != 0) + delete pointer_; + } + /** + * @brief Get a pointer to the instance. + * @return The instance we store. + */ + MPIHelper* get() + { + return pointer_; + } + /** + * @brief Set the pointer. + * @paramter pointer A pointer to the instance. + */ + void set(MPIHelper* pointer) + { + if(pointer != 0) { + delete pointer_; + pointer_ = pointer; + } + } + private: + MPIHelper* pointer_; + }; + public: + enum { + /** + * @brief Are we fake (i. e. pretend to have MPI support but are compiled + * without. + */ + isFake = false + }; + + /** + * @brief The type of the mpi communicator. + */ + typedef MPI_Comm MPICommunicator; + + static MPICommunicator getCommunicator(){ + return MPI_COMM_WORLD; + } + + static MPIHelper& instance(int argc, char** argv) + { + if(instance_.get() == 0) + instance_.set(new MPIHelper(argc, argv)); + return *instance_.get(); + } + + private: + MPIHelper(int argc, char** argv) + { + MPI_Init(&argc, &argv); + } + ~MPIHelper() + { + MPI_Finalize(); + } + MPIHelper(const MPIHelper&); + MPIHelper& operator=(const MPIHelper); + + static InstancePointer instance_; + }; + + MPIHelper::InstancePointer MPIHelper::instance_ = MPIHelper::InstancePointer(); + +#else + // We do not have MPI therefore FakeMPIHelper + // is the MPIHelper +#define MPIHelper FakeMPIHelper + +#endif + +} // end namespace Dune +#endif diff --git a/common/stdstreams.hh b/common/stdstreams.hh index bc228e87fdb568146061510e9076ce872026a1f3..6ce9adb4fd1d330e073613856b7bce236ea643f0 100644 --- a/common/stdstreams.hh +++ b/common/stdstreams.hh @@ -61,7 +61,7 @@ namespace Dune { * If the level of a stream is bigger than this value * it will be activated. */ - static const DebugLevel MINIMAL_DEBUG_LEVEL = 4; + static const DebugLevel MINIMAL_DEBUG_LEVEL = 3; /** * @brief The level of the very verbose debug stream. diff --git a/common/test/.gitignore b/common/test/.gitignore index 00a0dfc68b96d4586cd852ed153902f5725c14be..2658c4983b7e64353fc891b581e0d5e08d35f796 100644 --- a/common/test/.gitignore +++ b/common/test/.gitignore @@ -21,4 +21,5 @@ streamtest exprtmpl timing_xpr timing_old -timing_flt \ No newline at end of file +timing_flt +mpihelpertest diff --git a/common/test/Makefile.am b/common/test/Makefile.am index b679265fd56156b96300742375caf51dc1eacf89..529ec98fccee6a9c10f0315e6ee80daa67714d18 100644 --- a/common/test/Makefile.am +++ b/common/test/Makefile.am @@ -3,7 +3,7 @@ TESTPROGS = parsetest test-stack arraylisttest smartpointertest \ sllisttest iteratorfacadetest tuplestest fmatrixtest \ poolallocatortest settest gcdlcdtest streamtest \ - bigunsignedinttest + bigunsignedinttest mpihelpertest # exprtmpl # which tests to run @@ -74,4 +74,8 @@ timing_flt_SOURCES = timing.cc timing_flt_CXXFLAGS = -DDUNE_EXPRESSIONTEMPLATES -DDUNE_FLATIT -g timing_flt_DEPENDENCIES = $(LOCAL_LIBS) +mpihelpertest_SOURCES = mpihelpertest.cc +mpihelpertest_CXXFLAGS = $(MPI_CPPFLAGS) +mpihelpertest_LDFLAGS = $(MPI_LDFLAGS) $(MPI_LIBS) + include $(top_srcdir)/am/global-rules diff --git a/common/test/mpihelpertest.cc b/common/test/mpihelpertest.cc new file mode 100644 index 0000000000000000000000000000000000000000..0eecbeb3e51008efd43e09fd3898a7b2b078c32e --- /dev/null +++ b/common/test/mpihelpertest.cc @@ -0,0 +1,23 @@ +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set et ts=4 sw=2 sts=2: +#include "config.h" +#include <dune/common/mpihelper.hh> +#include <iostream> +int main(int argc, char** argv) +{ + typedef Dune::MPIHelper Helper; + + { + Helper& mpi = Helper::instance(argc, argv); + + Helper::MPICommunicator comm = mpi.getCommunicator(); + } + + { + Helper& mpi = Helper::instance(argc, argv); + + Helper::MPICommunicator comm= mpi.getCommunicator(); + } + std::cout << "We are at the end!"<<std::endl; + +}