Commit c3dc225d authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

added Environment for MPI initialization

parent 73513f33
#pragma once
// std c++ headers
#include <cassert>
#include <string>
#include <dune/common/parallel/mpihelper.hh>
namespace AMDiS
{
/// Establishes an environemnt for sequential and parallel AMDiS programs
/**
* This object initializes the MPI environement, parses initfiles and may
* initialize other external libraries. It is constructed with the program
* commandline arguments. In its destruction, the MPI environemnt is finalized.
* In the vast majority of AMDiS programs, an instance of Environemnt should
* be desclared at the very beginning of the main function.
**/
class Environment
{
// insternal static container holding a pointer to the Dune::MPIHelper.
struct Mpi
{
static Mpi& instance()
{
static Mpi mpi;
return mpi;
}
void registerMpiHelper(Dune::MPIHelper& mpiHelper)
{
mpiHelper_ = &mpiHelper;
}
int rank()
{
assert(mpiHelper_ != nullptr);
return mpiHelper_->rank();
}
int size()
{
assert(mpiHelper_ != nullptr);
return mpiHelper_->size();
}
private:
Dune::MPIHelper* mpiHelper_ = nullptr;
};
public:
/// Create an environment without mpi initialization, with a fixed initfile given as string
Environment(std::string const& initFileName = "");
/// Create an environemtn with initialization of MPI and initifiles from commandline arguments
/// or the provided initfile filename.
Environment(int& argc, char**& argv, std::string const& initFileName = "");
/// Return the MPI_Rank of the current processor.
static int mpiRank()
{
return Mpi::instance().rank();
}
/// Return the MPI_Size if the group created by Dune::MPIHelper.
static int mpiSize()
{
return Mpi::instance().size();
}
};
} // end namespace AMDiS
#include <amdis/Initfile.hpp>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "Initfile.hpp"
#include <amdis/InitfileParser.hpp>
......
#include <amdis/InitfileParser.hpp>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "InitfileParser.hpp"
#include <amdis/Output.hpp>
#include <amdis/common/Filesystem.hpp>
......
#include "config.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ProblemInstat.hpp"
namespace AMDiS
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ProblemInstatBase.hpp"
#include "AdaptInfo.hpp"
......
#include "config.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ProblemStat.hpp"
namespace AMDiS
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "StandardProblemIteration.hpp"
#include <amdis/AdaptInfo.hpp>
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "Filesystem.hpp"
#ifdef _WIN32
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "String.hpp"
namespace AMDiS
......
......@@ -7,6 +7,7 @@
#include <dune/functions/functionspacebases/powerbasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <amdis/AMDiS.hpp>
#include <amdis/GridTransferManager.hpp>
#include <amdis/LinearAlgebra.hpp>
......@@ -36,7 +37,7 @@ void test_dofvector(B const& basis, DOFVector<B,T>& vec)
int main(int argc, char** argv)
{
Dune::MPIHelper::instance(argc, argv);
Environment env(argc, argv);
// create grid
Dune::FieldVector<double, 2> L; L = 1.0;
......
#include <amdis/AMDiS.hpp>
#include "DataTransferTest.hpp"
int main(int argc, char** argv)
{
Environment env(argc, argv);
#ifdef HAVE_DUNE_UGGRID
using Grid = Dune::UGGrid<2>;
#else
using Grid = Dune::YaspGrid<2>;
#endif
Dune::MPIHelper::instance(argc, argv);
using Domain = typename Dune::FieldVector<double, 2>;
// polynomial of order 1
......
#include <amdis/AMDiS.hpp>
#include "DataTransferTest.hpp"
int main(int argc, char** argv)
{
Environment env(argc, argv);
#ifdef HAVE_DUNE_UGGRID
using Grid = Dune::UGGrid<3>;
#else
using Grid = Dune::YaspGrid<3>;
#endif
Dune::MPIHelper::instance(argc, argv);
using Domain = typename Dune::FieldVector<double, 3>;
// polynomial of order 1
......
......@@ -33,7 +33,7 @@ bool comp(DOFVector<GB,T> const& U, DOFVector<GB,T> const& V)
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
using namespace Dune::Indices;
......@@ -129,6 +129,5 @@ int main(int argc, char** argv)
AMDIS_TEST( comp(W3, W5) );
AMDIS_TEST( comp(W3, W6) );
AMDiS::finalize();
return 0;
}
......@@ -18,7 +18,7 @@ using ElliptProblem = ProblemStat<ElliptParam>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
using namespace Dune::Indices;
......@@ -103,6 +103,5 @@ int main(int argc, char** argv)
DUNE_UNUSED auto int5 = integrate(op5, gv, 5);
DUNE_UNUSED auto int6 = integrate(op6, gv, 5);
AMDiS::finalize();
return 0;
}
......@@ -18,7 +18,7 @@ using ElliptProblem = ProblemStat<ElliptParam>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
ElliptProblem prob("ellipt");
prob.initialize(INIT_ALL);
......@@ -40,6 +40,5 @@ int main(int argc, char** argv)
AMDIS_TEST(i4 == 1.0);
AMDiS::finalize();
return 0;
}
......@@ -14,7 +14,7 @@ using DomainType = typename Dune::FieldVector<double,d>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
DomainType lowerLeft; lowerLeft = 0.0; // lower left grid corner
DomainType upperRight; upperRight = 1.0; // upper right grid corner
......@@ -53,7 +53,5 @@ int main(int argc, char** argv)
prob.solution().interpolate(markerFunc);
prob.writeFiles(adaptInfo);
AMDiS::finalize();
return report_errors();
}
......@@ -11,7 +11,7 @@ using namespace AMDiS;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
constexpr Operation::StaticConstant<int,0> op0a;
constexpr Operation::Zero op0b;
......@@ -77,6 +77,5 @@ int main(int argc, char** argv)
AMDIS_TEST_EQ(erg8, 2);
// constexpr int order8 = order(op8,2,3); // no order() for divides
AMDiS::finalize();
return report_errors();
}
......@@ -15,7 +15,7 @@ using Problem = ProblemStat<Param>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
using namespace Dune::Indices;
......@@ -109,6 +109,5 @@ int main(int argc, char** argv)
prob.addMatrixOperator(opCDb, _p, _p);
prob.addVectorOperator(opCDb, _p);
AMDiS::finalize();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment