Dune Core Modules (2.6.0)

partitioning.hh
Go to the documentation of this file.
1#ifndef DUNE_GRID_YASPGRID_PARTITIONING_HH
2#define DUNE_GRID_YASPGRID_PARTITIONING_HH
3
11#include<array>
12
14
15namespace Dune
16{
17
22 template<int d>
24 {
25 public:
26 typedef std::array<int, d> iTupel;
27 virtual ~YLoadBalance() {}
28 virtual void loadbalance(const iTupel&, int, iTupel&) const = 0;
29 };
30
33 template<int d>
35 {
36 public:
37 typedef std::array<int, d> iTupel;
38 virtual ~YLoadBalanceDefault() {}
39
45 virtual void loadbalance (const iTupel& size, int P, iTupel& dims) const
46 {
47 double opt=1E100;
48 iTupel trydims;
49
50 optimize_dims(d-1,size,P,dims,trydims,opt);
51 }
52 private:
53 void optimize_dims (int i, const iTupel& size, int P, iTupel& dims, iTupel& trydims, double &opt ) const
54 {
55 if (i>0) // test all subdivisions recursively
56 {
57 for (int k=1; k<=P; k++)
58 if (P%k==0)
59 {
60 // P divisible by k
61 trydims[i] = k;
62 optimize_dims(i-1,size,P/k,dims,trydims,opt);
63 }
64 }
65 else
66 {
67 // found a possible combination
68 trydims[0] = P;
69
70 // check for optimality
71 double m = -1.0;
72
73 for (int k=0; k<d; k++)
74 {
75 double mm=((double)size[k])/((double)trydims[k]);
76 if (fmod((double)size[k],(double)trydims[k])>0.0001) mm*=3;
77 if ( mm > m ) m = mm;
78 }
79 //if (_rank==0) std::cout << "optimize_dims: " << size << " | " << trydims << " norm=" << m << std::endl;
80 if (m<opt)
81 {
82 opt = m;
83 dims = trydims;
84 }
85 }
86 }
87 };
88
91 template<int d>
93 {
94 public:
95 typedef std::array<int, d> iTupel;
96 virtual ~YLoadBalancePowerD() {}
97
98 virtual void loadbalance (const iTupel& size, int P, iTupel& dims) const
99 {
100 for(int i=1; i<=P; ++i)
101 if(Power<d>::eval(i)==P) {
102 std::fill(dims.begin(), dims.end(),i);
103 return;
104 }
105
106 DUNE_THROW(GridError, "Loadbalancing failed: your number of processes needs to be a " << d << "-th power.");
107 }
108 };
109
114 template<int d>
116 {
117 public:
118 YaspFixedSizePartitioner(const std::array<int,d>& dims) : _dims(dims) {}
119
120 virtual ~YaspFixedSizePartitioner() {}
121
122 virtual void loadbalance(const std::array<int,d>&, int P, std::array<int,d>& dims) const
123 {
124 int prod = 1;
125 for (int i=0; i<d; i++)
126 prod *= _dims[i];
127 if (P != prod)
128 DUNE_THROW(Dune::Exception,"Your processor number doesn't match your partitioning information");
129 dims = _dims;
130 }
131
132 private:
133 std::array<int,d> _dims;
134 };
135
136}
137
138#endif
Base class for Dune-Exceptions.
Definition: exceptions.hh:94
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Implement the default load balance strategy of yaspgrid.
Definition: partitioning.hh:35
virtual void loadbalance(const iTupel &size, int P, iTupel &dims) const
Distribute a structured grid across a set of processors.
Definition: partitioning.hh:45
Implement yaspgrid load balance strategy for P=x^{dim} processors.
Definition: partitioning.hh:93
a base class for the yaspgrid partitioning strategy The name might be irritating. It will probably ch...
Definition: partitioning.hh:24
Implement partitioner that gets a fixed partitioning from an array If the given partitioning doesn't ...
Definition: partitioning.hh:116
Various implementations of the power function for run-time and static arguments.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
Compute power for a run-time mantissa and a compile-time integer exponent.
Definition: power.hh:47
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 26, 23:30, 2024)