Comment tuples section

This commit is contained in:
Alejandro Gallo 2021-10-14 15:23:30 +02:00
parent 1cf6795130
commit 3dd8af052d
2 changed files with 143 additions and 114 deletions

View File

@ -1387,6 +1387,12 @@ namespace atrip {
#+end_src #+end_src
** Tuples ** Tuples
This section introduces the types for tuples \( (a,b,c) \)
as well as their distribution to nodes and cores.
*** Prolog :noexport:
#+begin_src c++ :tangle (atrip-tuples-h) #+begin_src c++ :tangle (atrip-tuples-h)
#pragma once #pragma once
@ -1398,11 +1404,38 @@ namespace atrip {
#include <atrip/Debug.hpp> #include <atrip/Debug.hpp>
namespace atrip { namespace atrip {
#+end_src
*** Tuples types
The main tuple types are simple type aliases for finite-size arrays.
A tuple is thus simply 3 natural numbers \( (a,b,c) \)
whereas a partial tuple is a two dimensional subset of these three.
#+begin_src c++ :tangle (atrip-tuples-h)
using ABCTuple = std::array<size_t, 3>; using ABCTuple = std::array<size_t, 3>;
using PartialTuple = std::array<size_t, 2>; using PartialTuple = std::array<size_t, 2>;
using ABCTuples = std::vector<ABCTuple>; using ABCTuples = std::vector<ABCTuple>;
#+end_src
*** Naive list
The naive implementation of the global tuples list is simple
three for loops creating tuples of the sort
\( (a,b,c) \) where the following conditions are met at the same time:
- \( a \leq b \leq c \)
- \(
a \neq b \land b \neq c
\)
This means,
\( (1, 2, 3)
, (1, 1, 3)
, (1, 2, 2)
\) are acceptable tuples wherease \( (2, 1, 1) \) and \( (1, 1, 1) \) are not.
#+begin_src c++ :tangle (atrip-tuples-h)
ABCTuples getTuplesList(size_t Nv) { ABCTuples getTuplesList(size_t Nv) {
const size_t n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv; const size_t n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv;
ABCTuples result(n); ABCTuples result(n);
@ -1418,8 +1451,13 @@ namespace atrip {
return result; return result;
} }
#+end_src
Once the list of tuples is built, every rank will only go through
a section of the list, the start and end indices in the original
global list are given by the following function.
#+begin_src c++ :tangle (atrip-tuples-h)
std::pair<size_t, size_t> std::pair<size_t, size_t>
getABCRange(size_t np, size_t rank, ABCTuples const& tuplesList) { getABCRange(size_t np, size_t rank, ABCTuples const& tuplesList) {
@ -1436,17 +1474,6 @@ namespace atrip {
if (nRoundRobin) for (int i = 0; i < np; i++) n_tuples_per_rank[i]++; if (nRoundRobin) for (int i = 0; i < np; i++) n_tuples_per_rank[i]++;
#if defined(TODO)
assert( tuplesList.size()
==
( std::accumulate(n_tuples_per_rank.begin(),
n_tuples_per_rank.end(),
0UL,
std::plus<size_t>())
+ nExtraInvalid
));
#endif
WITH_RANK << "nRoundRobin = " << nRoundRobin << "\n"; WITH_RANK << "nRoundRobin = " << nRoundRobin << "\n";
WITH_RANK << "nExtraInvalid = " << nExtraInvalid << "\n"; WITH_RANK << "nExtraInvalid = " << nExtraInvalid << "\n";
WITH_RANK << "ntuples = " << n_tuples_per_rank[rank] << "\n"; WITH_RANK << "ntuples = " << n_tuples_per_rank[rank] << "\n";
@ -1459,13 +1486,19 @@ namespace atrip {
}; };
} }
#+end_src
*** Group and sort list
*** Epilog :noexport:
#+begin_src c++ :tangle (atrip-tuples-h)
} }
#+end_src #+end_src
** Unions ** Unions
Since every tensor slice in a different way, we can override the slicing procedure
and define subclasses of slice unions. Every slice pertaining to every different tensor
is sliced differently.
#+begin_src c++ :tangle (atrip-unions-h) #+begin_src c++ :tangle (atrip-unions-h)
#pragma once #pragma once

View File

@ -1,4 +1,4 @@
// [[file:../../atrip.org::*Tuples][Tuples:1]] // [[file:../../atrip.org::*Prolog][Prolog:1]]
#pragma once #pragma once
#include <vector> #include <vector>
@ -9,11 +9,15 @@
#include <atrip/Debug.hpp> #include <atrip/Debug.hpp>
namespace atrip { namespace atrip {
// Prolog:1 ends here
// [[file:../../atrip.org::*Tuples types][Tuples types:1]]
using ABCTuple = std::array<size_t, 3>; using ABCTuple = std::array<size_t, 3>;
using PartialTuple = std::array<size_t, 2>; using PartialTuple = std::array<size_t, 2>;
using ABCTuples = std::vector<ABCTuple>; using ABCTuples = std::vector<ABCTuple>;
// Tuples types:1 ends here
// [[file:../../atrip.org::*Naive list][Naive list:1]]
ABCTuples getTuplesList(size_t Nv) { ABCTuples getTuplesList(size_t Nv) {
const size_t n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv; const size_t n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv;
ABCTuples result(n); ABCTuples result(n);
@ -29,8 +33,9 @@ namespace atrip {
return result; return result;
} }
// Naive list:1 ends here
// [[file:../../atrip.org::*Naive list][Naive list:2]]
std::pair<size_t, size_t> std::pair<size_t, size_t>
getABCRange(size_t np, size_t rank, ABCTuples const& tuplesList) { getABCRange(size_t np, size_t rank, ABCTuples const& tuplesList) {
@ -47,17 +52,6 @@ namespace atrip {
if (nRoundRobin) for (int i = 0; i < np; i++) n_tuples_per_rank[i]++; if (nRoundRobin) for (int i = 0; i < np; i++) n_tuples_per_rank[i]++;
#if defined(TODO)
assert( tuplesList.size()
==
( std::accumulate(n_tuples_per_rank.begin(),
n_tuples_per_rank.end(),
0UL,
std::plus<size_t>())
+ nExtraInvalid
));
#endif
WITH_RANK << "nRoundRobin = " << nRoundRobin << "\n"; WITH_RANK << "nRoundRobin = " << nRoundRobin << "\n";
WITH_RANK << "nExtraInvalid = " << nExtraInvalid << "\n"; WITH_RANK << "nExtraInvalid = " << nExtraInvalid << "\n";
WITH_RANK << "ntuples = " << n_tuples_per_rank[rank] << "\n"; WITH_RANK << "ntuples = " << n_tuples_per_rank[rank] << "\n";
@ -70,6 +64,8 @@ namespace atrip {
}; };
} }
// Naive list:2 ends here
// [[file:../../atrip.org::*Epilog][Epilog:1]]
} }
// Tuples:1 ends here // Epilog:1 ends here