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

added Environment for MPI initialization

parent 73513f33
Pipeline #2014 passed with stage
in 95 minutes and 3 seconds
......@@ -95,7 +95,7 @@ void run_periodic()
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
auto b = [](auto const& x){ return x[0] < 1.e-8 || x[1] < 1.e-8 || x[0] > 1.0-1.e-8 || x[1] > 1.0-1.e-8; };
......@@ -119,6 +119,5 @@ int main(int argc, char** argv)
run_periodic();
AMDiS::finalize();
return 0;
}
......@@ -13,7 +13,7 @@ using Param = LagrangeBasis<Grid, 1, 1>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
ProblemStat<Param> prob("ch");
prob.initialize(INIT_ALL);
......@@ -68,6 +68,5 @@ int main(int argc, char** argv)
AdaptInstationary adapt("adapt", prob, adaptInfo, probInstat, adaptInfo);
adapt.adapt();
AMDiS::finalize();
return 0;
}
......@@ -17,7 +17,7 @@ using ElliptProblem = ProblemStat<ElliptParam>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
using namespace Dune::Indices;
......@@ -39,6 +39,5 @@ int main(int argc, char** argv)
prob.solve(adaptInfo);
prob.writeFiles(adaptInfo, true);
AMDiS::finalize();
return 0;
}
......@@ -18,7 +18,7 @@ using ElliptProblem = ProblemStat<Param>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
int numLevels = GRIDDIM == 2 ? 8 : 5;
if (argc > 2)
......@@ -92,6 +92,5 @@ int main(int argc, char** argv)
msg("{:<5} | {:<12} | {:<12} | {:<12} | {:<12} | {:<12}",
i+1, widths[i], errL2[i], errH1[i], eocL2[i], eocH1[i]);
AMDiS::finalize();
return 0;
}
......@@ -21,7 +21,7 @@ using HeatProblemInstat = ProblemInstat<HeatParam>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
HeatProblem prob("heat");
prob.initialize(INIT_ALL);
......@@ -55,6 +55,5 @@ int main(int argc, char** argv)
AdaptInstationary adapt("adapt", prob, adaptInfo, probInstat, adaptInfo);
adapt.adapt();
AMDiS::finalize();
return 0;
}
......@@ -12,7 +12,7 @@ using Basis = TaylorHoodBasis<Grid>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
ProblemStat<Basis> prob("stokes");
prob.initialize(INIT_ALL);
......@@ -89,6 +89,5 @@ int main(int argc, char** argv)
// output solution
prob.writeFiles(adaptInfo);
AMDiS::finalize();
return 0;
}
......@@ -51,7 +51,7 @@ void run(Grid& grid)
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
// 2d grids
......@@ -85,6 +85,5 @@ int main(int argc, char** argv)
Dune::YaspGrid<3> grid4({1.0,1.0,1.0},{2,2,2});
run(grid4);
AMDiS::finalize();
return 0;
}
......@@ -79,7 +79,7 @@ void run(Grid& grid)
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
#if HAVE_DUNE_SPGRID
Dune::SPCube<double,2> cube({0.0,0.0},{1.0,1.0});
......@@ -92,6 +92,5 @@ int main(int argc, char** argv)
Dune::YaspGrid<2> grid2({1.0,1.0}, {2,2});
run(grid2);
AMDiS::finalize();
return 0;
}
......@@ -10,7 +10,7 @@ using StokesProblem = ProblemStat<StokesParam>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
StokesProblem prob("stokes");
prob.initialize(INIT_ALL);
......@@ -58,6 +58,5 @@ int main(int argc, char** argv)
// output solution
prob.writeFiles(adaptInfo);
AMDiS::finalize();
return 0;
}
......@@ -10,7 +10,7 @@ using StokesProblem = ProblemStat<StokesParam>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
StokesProblem prob("stokes");
prob.initialize(INIT_ALL);
......@@ -58,6 +58,5 @@ int main(int argc, char** argv)
// output solution
prob.writeFiles(adaptInfo);
AMDiS::finalize();
return 0;
}
......@@ -11,7 +11,7 @@ using StokesProblem = ProblemStat<StokesParam>;
int main(int argc, char** argv)
{
AMDiS::init(argc, argv);
Environment env(argc, argv);
StokesProblem prob("stokes");
prob.initialize(INIT_ALL);
......@@ -48,6 +48,5 @@ int main(int argc, char** argv)
// output solution
prob.writeFiles(adaptInfo);
AMDiS::finalize();
return 0;
}
......@@ -15,7 +15,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);
......@@ -53,6 +53,5 @@ int main(int argc, char** argv)
prob.solve(adaptInfo);
prob.writeFiles(adaptInfo, true);
AMDiS::finalize();
return 0;
}
#include "AMDiS.hpp"
// AMDiS includes
#include <amdis/Initfile.hpp>
#include <amdis/Output.hpp>
namespace AMDiS
{
Dune::MPIHelper& init(int& argc, char**& argv, std::string const& initFileName)
{
// Maybe initialize MPI
static Dune::MPIHelper& mpiHelper = Dune::MPIHelper::instance(argc, argv);
Parameters::clearData();
if (initFileName.empty() && argc > 1) {
Parameters::init(argv[1]);
} else if (!initFileName.empty()) {
Parameters::init(initFileName);
} else {
warning("No initfile specified. Using default values for all parameters.");
}
return mpiHelper;
}
void finalize()
{}
} // end namespace AMDiS
......@@ -4,16 +4,11 @@
# include "config.h"
#endif
// std c++ headers
#include <string>
#include <dune/common/exceptions.hh> // We use exceptions
#include <dune/common/parallel/mpihelper.hh>
namespace AMDiS
{
Dune::MPIHelper& init(int& argc, char**& argv, std::string const& initFileName = "");
void finalize();
} // end namespace AMDiS
#include <amdis/AdaptInfo.hpp>
#include <amdis/Environment.hpp>
#include <amdis/Initfile.hpp>
#include <amdis/LinearAlgebra.hpp>
#include <amdis/Output.hpp>
#include <amdis/ProblemStat.hpp>
namespace AMDiS {} // end namespace AMDiS
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "AdaptInfo.hpp"
// std c++ headers
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "AdaptInstationary.hpp"
// AMDiS includes
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "AdaptStationary.hpp"
// AMDiS includes
......
......@@ -4,7 +4,7 @@ dune_library_add_sources(amdis SOURCES
AdaptInfo.cpp
AdaptInstationary.cpp
AdaptStationary.cpp
AMDiS.cpp
Environment.cpp
Initfile.cpp
InitfileParser.cpp
ProblemInstatBase.cpp
......@@ -31,6 +31,7 @@ install(FILES
DataTransfer.inc.hpp
DirichletBC.hpp
DirichletBC.inc.hpp
Environment.hpp
FileWriter.hpp
FileWriterInterface.hpp
Flag.hpp
......
......@@ -14,6 +14,7 @@
#include <dune/common/fvector.hh>
#include <dune/common/hash.hh>
#include <dune/grid/common/geometry.hh>
#include <dune/grid/common/mcmgmapper.hh>
#include <dune/grid/common/rangegenerators.hh>
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "Environment.hpp"
// AMDiS includes
#include <amdis/Initfile.hpp>
#include <amdis/Output.hpp>
namespace AMDiS
{
Environment::Environment(std::string const& initFileName)
{
Parameters::clearData();
if (!initFileName.empty())
Parameters::init(initFileName);
}
Environment::Environment(int& argc, char**& argv, std::string const& initFileName)
: Environment(initFileName)
{
auto& helper = Dune::MPIHelper::instance(argc, argv);
auto& mpi = Mpi::instance();
mpi.registerMpiHelper(helper);
Parameters::clearData();
if (initFileName.empty()) {
if (argc > 1)
Parameters::init(argv[1]);
else
warning("No initfile specified. Using default values for all parameters.");
}
}
} // end namespace AMDiS
#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);