Fix naive implementation, NH3 working for both

This commit is contained in:
Alejandro Gallo 2021-11-04 16:10:23 +01:00
parent a5619146f0
commit 7b617930a6
3 changed files with 159 additions and 163 deletions

183
atrip.org
View File

@ -1449,94 +1449,7 @@ struct TuplesDistribution {
*** 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, size_t rank, size_t np) {
const size_t
// total number of tuples for the problem
n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv
// all ranks should have the same number of tuples_per_rank
, tuples_per_rank = n / np + size_t(n % np != 0)
// start index for the global tuples list
, start = tuples_per_rank * rank
// end index for the global tuples list
, end = tuples_per_rank * (rank + 1)
;
ABCTuples result(tuples_per_rank, FAKE_TUPLE);
for (size_t a(0), r(0), g(0); a < Nv; a++)
for (size_t b(a); b < Nv; b++)
for (size_t c(b); c < Nv; c++, g++){
if ( a == b && b == c ) continue;
if ( g > start && g <= end) result[r++] = {a, b, c};
}
return result;
}
#+end_src
and all tuples would simply be
#+begin_src c++ :tangle (atrip-tuples-h)
ABCTuples getAllTuplesList(const size_t Nv) {
const size_t n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv;
ABCTuples result(n);
for (size_t a(0), u(0); a < Nv; a++)
for (size_t b(a); b < Nv; b++)
for (size_t c(b); c < Nv; c++){
if ( a == b && b == c ) continue;
result[u++] = {a, b, c};
}
return result;
}
#+end_src
With =getTupleList= we can easily define a tuple distribution like
#+begin_src c++ :tangle (atrip-tuples-h)
struct NaiveDistribution : public TuplesDistribution {
ABCTuples getTuples(size_t Nv, MPI_Comm universe) override {
int rank, np;
MPI_Comm_rank(universe, &rank);
MPI_Comm_size(universe, &np);
return getTuplesList(Nv, (size_t)rank, (size_t)np);
}
};
#+end_src
*** Group and sort list
**** Prolog :noexport:
#+begin_src c++ :tangle (atrip-tuples-h)
namespace group_and_sort {
#+end_src
**** Node information
*** Node information
- nodeList ::
List of hostnames of size \( N_n \)
@ -1630,6 +1543,96 @@ getNodeInfos(std::vector<string> const& nodeNames) {
}
#+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, size_t rank, size_t np) {
const size_t
// total number of tuples for the problem
n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv
// all ranks should have the same number of tuples_per_rank
, tuples_per_rank = n / np + size_t(n % np != 0)
// start index for the global tuples list
, start = tuples_per_rank * rank
// end index for the global tuples list
, end = tuples_per_rank * (rank + 1)
;
LOG(1,"Atrip") << "tuples_per_rank = " << tuples_per_rank << "\n";
WITH_RANK << "start, end = " << start << ", " << end << "\n";
ABCTuples result(tuples_per_rank, FAKE_TUPLE);
for (size_t a(0), r(0), g(0); a < Nv; a++)
for (size_t b(a); b < Nv; b++)
for (size_t c(b); c < Nv; c++){
if ( a == b && b == c ) continue;
if ( start <= g && g < end) result[r++] = {a, b, c};
g++;
}
return result;
}
#+end_src
and all tuples would simply be
#+begin_src c++ :tangle (atrip-tuples-h)
ABCTuples getAllTuplesList(const size_t Nv) {
const size_t n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv;
ABCTuples result(n);
for (size_t a(0), u(0); a < Nv; a++)
for (size_t b(a); b < Nv; b++)
for (size_t c(b); c < Nv; c++){
if ( a == b && b == c ) continue;
result[u++] = {a, b, c};
}
return result;
}
#+end_src
With =getTupleList= we can easily define a tuple distribution like
#+begin_src c++ :tangle (atrip-tuples-h)
struct NaiveDistribution : public TuplesDistribution {
ABCTuples getTuples(size_t Nv, MPI_Comm universe) override {
int rank, np;
MPI_Comm_rank(universe, &rank);
MPI_Comm_size(universe, &np);
return getTuplesList(Nv, (size_t)rank, (size_t)np);
}
};
#+end_src
*** Group and sort list
**** Prolog :noexport:
#+begin_src c++ :tangle (atrip-tuples-h)
namespace group_and_sort {
#+end_src
**** Utils
#+begin_src c++ :tangle (atrip-tuples-h)
@ -2863,7 +2866,7 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
LOG(0,"Atrip") << "#iterations: "
<< nIterations
<< "/"
<< _all_tuples
<< nIterations * np
<< "\n";
}
@ -3052,8 +3055,6 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
: tuplesList[i]
, *abcNext = i == (tuplesList.size() - 1)
? nullptr
: isFakeTuple(i + 1)
? &tuplesList[tuplesList.size() - 1]
: &tuplesList[i + 1]
;

View File

@ -36,68 +36,6 @@ struct TuplesDistribution {
};
// Distributing the tuples:1 ends here
// [[file:~/atrip/atrip.org::*Naive%20list][Naive list:1]]
ABCTuples getTuplesList(size_t Nv, size_t rank, size_t np) {
const size_t
// total number of tuples for the problem
n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv
// all ranks should have the same number of tuples_per_rank
, tuples_per_rank = n / np + size_t(n % np != 0)
// start index for the global tuples list
, start = tuples_per_rank * rank
// end index for the global tuples list
, end = tuples_per_rank * (rank + 1)
;
ABCTuples result(tuples_per_rank, FAKE_TUPLE);
for (size_t a(0), r(0), g(0); a < Nv; a++)
for (size_t b(a); b < Nv; b++)
for (size_t c(b); c < Nv; c++, g++){
if ( a == b && b == c ) continue;
if ( g > start && g <= end) result[r++] = {a, b, c};
}
return result;
}
// Naive list:1 ends here
// [[file:~/atrip/atrip.org::*Naive%20list][Naive list:2]]
ABCTuples getAllTuplesList(const size_t Nv) {
const size_t n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv;
ABCTuples result(n);
for (size_t a(0), u(0); a < Nv; a++)
for (size_t b(a); b < Nv; b++)
for (size_t c(b); c < Nv; c++){
if ( a == b && b == c ) continue;
result[u++] = {a, b, c};
}
return result;
}
// Naive list:2 ends here
// [[file:~/atrip/atrip.org::*Naive%20list][Naive list:3]]
struct NaiveDistribution : public TuplesDistribution {
ABCTuples getTuples(size_t Nv, MPI_Comm universe) override {
int rank, np;
MPI_Comm_rank(universe, &rank);
MPI_Comm_size(universe, &np);
return getTuplesList(Nv, (size_t)rank, (size_t)np);
}
};
// Naive list:3 ends here
// [[file:~/atrip/atrip.org::*Prolog][Prolog:1]]
namespace group_and_sort {
// Prolog:1 ends here
// [[file:~/atrip/atrip.org::*Node%20information][Node information:1]]
std::vector<std::string> getNodeNames(MPI_Comm comm){
int rank, np;
@ -177,6 +115,71 @@ getNodeInfos(std::vector<string> const& nodeNames) {
}
// Node information:2 ends here
// [[file:~/atrip/atrip.org::*Naive%20list][Naive list:1]]
ABCTuples getTuplesList(size_t Nv, size_t rank, size_t np) {
const size_t
// total number of tuples for the problem
n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv
// all ranks should have the same number of tuples_per_rank
, tuples_per_rank = n / np + size_t(n % np != 0)
// start index for the global tuples list
, start = tuples_per_rank * rank
// end index for the global tuples list
, end = tuples_per_rank * (rank + 1)
;
LOG(1,"Atrip") << "tuples_per_rank = " << tuples_per_rank << "\n";
WITH_RANK << "start, end = " << start << ", " << end << "\n";
ABCTuples result(tuples_per_rank, FAKE_TUPLE);
for (size_t a(0), r(0), g(0); a < Nv; a++)
for (size_t b(a); b < Nv; b++)
for (size_t c(b); c < Nv; c++){
if ( a == b && b == c ) continue;
if ( start <= g && g < end) result[r++] = {a, b, c};
g++;
}
return result;
}
// Naive list:1 ends here
// [[file:~/atrip/atrip.org::*Naive%20list][Naive list:2]]
ABCTuples getAllTuplesList(const size_t Nv) {
const size_t n = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv;
ABCTuples result(n);
for (size_t a(0), u(0); a < Nv; a++)
for (size_t b(a); b < Nv; b++)
for (size_t c(b); c < Nv; c++){
if ( a == b && b == c ) continue;
result[u++] = {a, b, c};
}
return result;
}
// Naive list:2 ends here
// [[file:~/atrip/atrip.org::*Naive%20list][Naive list:3]]
struct NaiveDistribution : public TuplesDistribution {
ABCTuples getTuples(size_t Nv, MPI_Comm universe) override {
int rank, np;
MPI_Comm_rank(universe, &rank);
MPI_Comm_size(universe, &np);
return getTuplesList(Nv, (size_t)rank, (size_t)np);
}
};
// Naive list:3 ends here
// [[file:~/atrip/atrip.org::*Prolog][Prolog:1]]
namespace group_and_sort {
// Prolog:1 ends here
// [[file:~/atrip/atrip.org::*Utils][Utils:1]]
// Provides the node on which the slice-element is found
// Right now we distribute the slices in a round robin fashion
@ -460,13 +463,7 @@ if (makeDistribution) {
// Main:4 ends here
// [[file:~/atrip/atrip.org::*Main][Main:6]]
/*
result.insert(result.end(),
tuplesPerRankGlobal - result.size(),
FAKE_TUPLE);
*/
LOG(1,"Atrip") << "scattering tuples \n";
LOG(1,"Atrip") << "scattering tuples \n";
return result;

View File

@ -102,7 +102,7 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
LOG(0,"Atrip") << "#iterations: "
<< nIterations
<< "/"
<< _all_tuples
<< nIterations * np
<< "\n";
}
@ -291,8 +291,6 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
: tuplesList[i]
, *abcNext = i == (tuplesList.size() - 1)
? nullptr
: isFakeTuple(i + 1)
? &tuplesList[tuplesList.size() - 1]
: &tuplesList[i + 1]
;