ALL 0.9.3
A Loadbalacing Library
Loading...
Searching...
No Matches
ALL_Functions.hpp
Go to the documentation of this file.
1#ifndef ALL_GENERAL_FUNCTION_HEADER_INCLUDED
2#define ALL_GENERAL_FUNCTION_HEADER_INCLUDED
3
4#include <mpi.h>
5#include <cmath>
6#include <vector>
7
8namespace ALL{
9namespace Functions {
10
33template <typename T, typename W>
34T borderShift1d(const int remote_rank, const int local_coord,
35 const int global_dim, const W local_work, const W remote_work,
36 const T local_size, const T remote_size, const T gamma,
37 const T minSize) {
38 // calculate shift of borders:
39 // s = 0.5 * gamma * (W_r - W_l) / (W_r + W_l) * (d_r + d_l)
40 // *_r = * of neighbor (remote)
41 // *_l = * of local domain
42
43 T shift;
44 // check if a sensible shift can be made
45 if (remote_rank != MPI_PROC_NULL && local_coord != global_dim - 1 &&
46 !(remote_work == (T)0 && local_work == (T)0)) {
47 shift = 1.0 / gamma * 0.5 * (remote_work - local_work) /
48 (remote_work + local_work) * (local_size + remote_size);
49
50 // determine a maximum move in order to avoid overlapping borders and to
51 // guarantee a stable shift of the domain borders (avoid the loss of a
52 // domain due to too large shifts of its borders [no crossing of borders])
53 T maxmove;
54 if (shift > 0.0)
55 maxmove = 0.49 * (remote_size - minSize);
56 else
57 maxmove = 0.49 * (local_size - minSize);
58
59 if (std::abs(shift) > maxmove) {
60 shift = (shift < 0.0) ? -maxmove : maxmove;
61 }
62 } else {
63 shift = (T)0;
64 }
65
66 return shift;
67}
68
69}}// namespace ALL::Functions
70#endif
T borderShift1d(const int remote_rank, const int local_coord, const int global_dim, const W local_work, const W remote_work, const T local_size, const T remote_size, const T gamma, const T minSize)
Definition ALL.hpp:75