diff --git a/Sources.mk b/Sources.mk index c63770b..2b85d8d 100644 --- a/Sources.mk +++ b/Sources.mk @@ -1 +1 @@ -ATRIP_SOURCES = include/atrip.hpp src/atrip/Atrip.cxx include/atrip/Atrip.hpp include/atrip/Debug.hpp include/atrip/Equations.hpp include/atrip/Tuples.hpp include/atrip/Unions.hpp include/atrip/RankMap.hpp include/atrip/Blas.hpp include/atrip/Utils.hpp include/atrip/SliceUnion.hpp include/atrip/Slice.hpp +ATRIP_SOURCES = include/atrip.hpp src/atrip/Atrip.cxx include/atrip/Atrip.hpp include/atrip/Debug.hpp include/atrip/Equations.hpp include/atrip/Tuples.hpp include/atrip/Unions.hpp include/atrip/RankMap.hpp include/atrip/Blas.hpp include/atrip/Utils.hpp include/atrip/SliceUnion.hpp include/atrip/Slice.hpp \ No newline at end of file diff --git a/atrip.org b/atrip.org index 1aadca3..455b128 100644 --- a/atrip.org +++ b/atrip.org @@ -528,7 +528,7 @@ namespace atrip { #+end_src ** The rank mapping -#+begin_src c++ :tangle (atrip-utils-h) +#+begin_src c++ :tangle (atrip-rankmap-h) #pragma once #include diff --git a/include/atrip/RankMap.hpp b/include/atrip/RankMap.hpp new file mode 100644 index 0000000..d438234 --- /dev/null +++ b/include/atrip/RankMap.hpp @@ -0,0 +1,61 @@ +// [[file:../../atrip.org::*The rank mapping][The rank mapping:1]] +#pragma once + +#include +#include + +#include + +namespace atrip { + struct RankMap { + + std::vector const lengths; + size_t const np, size; + + RankMap(std::vector lens, size_t np_) + : lengths(lens) + , np(np_) + , size(std::accumulate(lengths.begin(), lengths.end(), + 1, std::multiplies())) + { assert(lengths.size() <= 2); } + + size_t find(Slice::Location const& p) const noexcept { + return p.source * np + p.rank; + } + + size_t nSources() const noexcept { + return size / np + size_t(size % np != 0); + } + + + bool isPaddingRank(size_t rank) const noexcept { + return size % np == 0 + ? false + : rank > (size % np - 1) + ; + } + + bool isSourcePadding(size_t rank, size_t source) const noexcept { + return source == nSources() && isPaddingRank(rank); + } + + Slice::Location + find(ABCTuple const& abc, Slice::Type sliceType) const noexcept { + // tuple = {11, 8} when abc = {11, 8, 9} and sliceType = AB + const auto tuple = Slice::subtupleBySlice(abc, sliceType); + + const size_t index + = tuple[0] + + tuple[1] * (lengths.size() > 1 ? lengths[0] : 0) + ; + + return + { index % np + , index / np + }; + } + + }; + +} +// The rank mapping:1 ends here diff --git a/include/atrip/Utils.hpp b/include/atrip/Utils.hpp index 1efe179..a6bd743 100644 --- a/include/atrip/Utils.hpp +++ b/include/atrip/Utils.hpp @@ -35,65 +35,3 @@ namespace atrip { using Timings = std::map; } // Utils:1 ends here - -// [[file:../../atrip.org::*The rank mapping][The rank mapping:1]] -#pragma once - -#include -#include - -#include - -namespace atrip { - struct RankMap { - - std::vector const lengths; - size_t const np, size; - - RankMap(std::vector lens, size_t np_) - : lengths(lens) - , np(np_) - , size(std::accumulate(lengths.begin(), lengths.end(), - 1, std::multiplies())) - { assert(lengths.size() <= 2); } - - size_t find(Slice::Location const& p) const noexcept { - return p.source * np + p.rank; - } - - size_t nSources() const noexcept { - return size / np + size_t(size % np != 0); - } - - - bool isPaddingRank(size_t rank) const noexcept { - return size % np == 0 - ? false - : rank > (size % np - 1) - ; - } - - bool isSourcePadding(size_t rank, size_t source) const noexcept { - return source == nSources() && isPaddingRank(rank); - } - - Slice::Location - find(ABCTuple const& abc, Slice::Type sliceType) const noexcept { - // tuple = {11, 8} when abc = {11, 8, 9} and sliceType = AB - const auto tuple = Slice::subtupleBySlice(abc, sliceType); - - const size_t index - = tuple[0] - + tuple[1] * (lengths.size() > 1 ? lengths[0] : 0) - ; - - return - { index % np - , index / np - }; - } - - }; - -} -// The rank mapping:1 ends here