Commit 99634e60 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

output for all or own rank only

parent 9cb1d1e2
......@@ -95,13 +95,6 @@ namespace Dec
template <class T>
using Store_t = typename aux::StoreType<Decay_t<T>>::type;
/// Variadic type list
template <class... Ts>
struct Types {};
template <class... Ts>
using Types_t = Types<Decay_t<Ts>...>;
/// Identity type wrapper, represents the type itself
template <class T>
struct Type
......@@ -109,6 +102,23 @@ namespace Dec
using type = T;
};
/// Variadic type list
template <class... Ts>
struct Types
{
template <bool...> struct _bools {};
template <class T>
static constexpr bool contains(Type<T> = {})
{
return not std::is_same< _bools<false, std::is_same<T,Ts>::value...>,
_bools<std::is_same<T,Ts>::value..., false> >::value;
}
};
template <class... Ts>
using Types_t = Types<Decay_t<Ts>...>;
template <class T>
using owner = T;
......
......@@ -5,6 +5,8 @@
#include <sstream>
#include <string>
#include <dune/dec/common/Common.hpp>
/**
* \def DEC_NO_THROW
* \brief The preprocessor constant sets whether to use c-asserts (if defined) or
......@@ -40,6 +42,15 @@
namespace Dec
{
namespace tag
{
struct own_rank {};
struct all_ranks {};
template <class OStream> OStream& operator<<(OStream& out, own_rank) { return out; }
template <class OStream> OStream& operator<<(OStream& out, all_ranks) { return out; }
}
namespace aux
{
template <class OStream>
......@@ -67,9 +78,12 @@ namespace Dec
int num_ranks = -1;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_ranks);
if (num_ranks > 1/* && rank == 0*/) {
concatImpl(out, "[",rank,"] ",std::forward<Args>(args)...);
} else if (num_ranks == 1) {
bool print = rank == 0 || Types<Decay_t<Args>...>::contains(Type<tag::all_ranks>{});
if (num_ranks > 1) {
if (print)
concatImpl(out, "[",rank,"] ",std::forward<Args>(args)...);
} else {
concatImpl(out, std::forward<Args>(args)...);
}
#else
......
......@@ -22,9 +22,29 @@ namespace Dec
/// returns the elapsed time (from construction or last reset) to now in seconds
value_type elapsed() const;
private:
protected:
/// start time
TimePoint t0;
};
template <class GridView>
class ParallelTimer
: public Timer
{
public:
ParallelTimer(GridView const& gv)
: gv_(gv)
{}
auto elapsed() const
{
auto e = Timer::elapsed();
return gv_.comm().max(e);
}
protected:
GridView gv_;
};
} // end namespace Dec
......@@ -64,7 +64,7 @@ int main(int argc, char** argv)
auto& mpihelper = Dune::MPIHelper::instance(argc, argv);
assert_msg( argc > 1, "usage: ./alugrid grid-filename [nSteps]");
Timer t;
Timer t0;
using GridBase = Dune::ALUGrid<2, 2, Dune::simplex, Dune::conforming>;
#if 1
// Create ug grid from structured grid
......@@ -81,30 +81,32 @@ int main(int argc, char** argv)
Dune::AlbertaReader<GridBase>().readGrid(argv[1], gridFactory);
std::unique_ptr<GridBase> gridBase( gridFactory.createGrid() );
#endif
msg("time(create gridBase) = ",t.elapsed(),"sec");
msg("time(create gridBase) = ",t0.elapsed(),"sec");
t.reset();
t0.reset();
LoadBalance<GridBase> lb(*gridBase, mpihelper);
gridBase->repartition(lb);
msg("#elements = ",gridBase->leafGridView().size(0));
msg("time(loadBalance) = ",t.elapsed(),"sec");
msg("time(loadBalance) = ",t0.elapsed(),"sec");
t.reset();
t0.reset();
using Grid = DecGrid<GridBase>;
Grid grid(*gridBase);
msg("time(create DECGrid) = ",t.elapsed(),"sec");
msg("time(create DECGrid) = ",t0.elapsed(),"sec");
if (argc > 2) {
t.reset();
t0.reset();
grid.globalRefine(std::atoi(argv[2]));
msg("#elements after global refinement = ",gridBase->leafGridView().size(0));
msg("time(global refine) = ",t.elapsed(),"sec");
msg("time(global refine) = ",t0.elapsed(),"sec");
}
using GridView = Grid::LeafGridView;
const GridView gv = grid.leafGridView();
auto const& indexSet = gv.indexSet();
ParallelTimer<GridView> t(gv);
// -----------------------------------------------------------------------------------------------
#if 0
for (auto const& v : vertices(gv, Dune::Partitions::All{}) ) {
......
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