Skip to content
Snippets Groups Projects
Commit 72dce620 authored by Markus Blatt's avatar Markus Blatt
Browse files

A preliminary version of an MPI helper for discussion

[[Imported from SVN: r4598]]
parent 5b86f617
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
// -*- 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
......@@ -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.
......
......@@ -21,4 +21,5 @@ streamtest
exprtmpl
timing_xpr
timing_old
timing_flt
\ No newline at end of file
timing_flt
mpihelpertest
......@@ -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
// -*- 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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment