AMDiS  0.1
The Adaptive Multi-Dimensional Simulation Toolbox
Algorithm.hpp
1 #pragma once
2 
3 #include <algorithm>
4 #include <functional>
5 #include <utility>
6 
7 namespace AMDiS
8 {
11  template <class InputIter, class Tp, class BinaryFunc>
12  void split(InputIter first, InputIter last, Tp sep, BinaryFunc f)
13  {
14  if (first == last)
15  return;
16 
17  while (true) {
18  InputIter found = std::find(first, last, sep);
19  f(first, found);
20  if (found == last)
21  break;
22  first = ++found;
23  }
24  }
25 
28  template <class InputIter, class SeparaterIter, class BinaryFunc>
29  void split(InputIter first, InputIter last, SeparaterIter s_first, SeparaterIter s_last, BinaryFunc f)
30  {
31  if (first == last)
32  return;
33 
34  while (true) {
35  InputIter found = std::find_first_of(first, last, s_first, s_last);
36  f(first, found);
37  if (found == last)
38  break;
39  first = ++found;
40  }
41  }
42 
44  // NOTE: backport of std::exclusive_scan from c++17
45  template <class InputIter, class OutputIter, class Tp, class BinaryOperation>
46  OutputIter exclusive_scan(InputIter first, InputIter last,
47  OutputIter result, Tp init, BinaryOperation binary_op)
48  {
49  while (first != last) {
50  auto v = init;
51  init = binary_op(init, *first);
52  ++first;
53  *result++ = std::move(v);
54  }
55  return result;
56  }
57 
59  // NOTE: backport of std::exclusive_scan from c++17
60  template <class InputIter, class OutputIter, class Tp>
61  inline OutputIter exclusive_scan(InputIter first, InputIter last,
62  OutputIter result, Tp init)
63  {
64  return AMDiS::exclusive_scan(first, last, result, std::move(init), std::plus<>());
65  }
66 
67 }
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
void init(int &argc, char **&argv, std::string const &initFileName="")
Initialized the Environment for MPI.
Definition: AMDiS.hpp:29
OutputIter exclusive_scan(InputIter first, InputIter last, OutputIter result, Tp init, BinaryOperation binary_op)
Output the cumulative sum of one range to a second range.
Definition: Algorithm.hpp:46
void split(InputIter first, InputIter last, Tp sep, BinaryFunc f)
Split a sequence [first,last) by the separators sep and pass the tokens as begin-end iterator pair to...
Definition: Algorithm.hpp:12