Communication.inc.hpp 2.22 KB
Newer Older
1
2
3
4
5
6
7
8
9
#pragma once

#include <amdis/Initfile.hpp>
#include <amdis/Output.hpp>

namespace AMDiS {

#if HAVE_MPI

10
11
12
template <class G, class L>
  template <class Basis>
ISTLCommunication<G,L> CommunicationCreator<ISTLCommunication<G,L>>
13
  ::create(Basis const& basis, std::string const& prefix)
14
{
15
  using SolverType = Dune::SolverCategory::Category;
16
  std::string category = "";
17
  Parameters::get(prefix + "->category", category);
18
19
20
21
22
23
  if (category == "")
  {
    // check global parameter if no local one was found
    category = "default";
    Parameters::get("solver category", category);
  }
Praetorius, Simon's avatar
Praetorius, Simon committed
24
  SolverType cat = SolverType::sequential;
25
  auto const& gv = basis.gridView();
26
  int mpiSize = gv.comm().size();
27
28
29

  if (category == "default")
  {
30
    if (mpiSize == 1)
31
32
33
34
35
36
37
38
39
40
41
    {
      cat = SolverType::sequential;
    }
    else
    {
      // Use overlapping solver if grid has overlap
      if (gv.overlapSize(0) > 0)
        cat = SolverType::overlapping;
      else
      {
        // TODO(FM): Remove once nonoverlapping solvers are supported
42
43
        warning("Nonoverlapping solvers are currently not supported.");
        cat = SolverType::nonoverlapping;
44
45
46
      }
    }
  }
47
  else if (category != "sequential" && mpiSize == 1)
48
49
50
51
52
53
  {
    warning("Only one process detected. Solver category set to sequential\n");
    cat = SolverType::sequential;
  }
  else if (category == "sequential")
  {
54
    test_exit(mpiSize == 1, "Solver category sequential is not supported in parallel\n");
55
56
57
58
59
60
61
62
63
64
    cat = SolverType::sequential;
  }
  else if (category == "overlapping")
  {
    if (gv.overlapSize(0) == 0)
      warning("Overlapping solver category chosen for grid with no overlap\n");
    cat = SolverType::overlapping;
  }
  else if (category == "nonoverlapping")
  {
65
66
    // TODO(FM): Remove once nonoverlapping solvers are supported
    warning("Nonoverlapping solvers are currently not supported.");
67
68
69
70
71
72
73
    cat = SolverType::nonoverlapping;
  }
  else
  {
    error_exit("Unknown solver category\n");
  }

74
  return {basis, cat};
75
76
}

77
78
#else // HAVE_MPI

79
80
81
template <class G, class L>
  template <class Basis>
ISTLCommunication<G,L> CommunicationCreator<ISTLCommunication<G,L>>
82
83
  ::create(Basis const& /*basis*/, std::string const& /*prefix*/)
{
84
  return {};
85
86
87
}

#endif // HAVE_MPI
88
89

} // end namespace AMDiS