Add distributions structs to main

This commit is contained in:
Alejandro Gallo 2021-10-19 13:49:48 +02:00
parent 2bcffb96f2
commit d2a8eff1b1

View File

@ -2830,36 +2830,36 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
// all tensors // all tensors
std::vector< SliceUnion* > unions = {&taphh, &hhha, &abph, &abhh, &tabhh}; std::vector< SliceUnion* > unions = {&taphh, &hhha, &abph, &abhh, &tabhh};
//CONSTRUCT TUPLE LIST ==============================================={{{1 // get tuples for the current rank
LOG(0,"Atrip") << "BUILD TUPLE LIST\n"; TuplesDistribution *distribution;
const auto tuplesList = std::move(getTuplesList(Nv));
WITH_RANK << "tupList.size() = " << tuplesList.size() << "\n";
// GET ABC INDEX RANGE FOR RANK ======================================{{{1 if (in.tuplesDistribution == Atrip::Input::TuplesDistribution::NAIVE) {
auto abcIndex = getABCRange(np, rank, tuplesList); LOG(0,"Atrip") << "Using the naive distribution\n";
size_t nIterations = abcIndex.second - abcIndex.first; distribution = new NaiveDistribution();
} else {
#ifdef ATRIP_BENCHMARK LOG(0,"Atrip") << "Using the group-and-sort distribution\n";
{ const size_t maxIterations = in.maxIterations; distribution = new group_and_sort::Distribution();
if (maxIterations != 0) {
abcIndex.second = abcIndex.first + maxIterations % (nIterations + 1);
nIterations = maxIterations % (nIterations + 1);
}
} }
#endif
WITH_RANK << "abcIndex = " << pretty_print(abcIndex) << "\n"; LOG(0,"Atrip") << "BUILDING TUPLE LIST\n";
LOG(0,"Atrip") << "#iterations: " << nIterations << "\n"; WITH_CHRONO(chrono["tuples:build"],
auto const tuplesList = distribution->getTuples(Nv, universe);
// first abc )
const ABCTuple firstAbc = tuplesList[abcIndex.first]; size_t nIterations = tuplesList.size();
{
const size_t _all_tuples = Nv * (Nv + 1) * (Nv + 2) / 6 - Nv;
double energy(0.); LOG(0,"Atrip") << "#iterations: "
<< nIterations
<< "/"
<< _all_tuples
<< "\n";
}
auto const isFakeTuple auto const isFakeTuple
= [&tuplesList](size_t const i) { return i >= tuplesList.size(); }; = [&tuplesList, distribution](size_t const i) {
return distribution->tupleIsFake(tuplesList[i]);
};
auto communicateDatabase auto communicateDatabase
@ -3002,10 +3002,10 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
// START MAIN LOOP ======================================================{{{1 // START MAIN LOOP ======================================================{{{1
Slice::Database db; double energy(0.);
for ( size_t i = abcIndex.first, iteration = 1 for ( size_t i = 0, iteration = 1
; i < abcIndex.second ; i < tuplesList.size()
; i++, iteration++ ; i++, iteration++
) { ) {
chrono["iterations"].start(); chrono["iterations"].start();
@ -3014,13 +3014,10 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
chrono["start:stop"].start(); chrono["start:stop"].stop(); chrono["start:stop"].start(); chrono["start:stop"].stop();
// check overhead of doing a barrier at the beginning // check overhead of doing a barrier at the beginning
chrono["oneshot-mpi:barrier"].start(); WITH_CHRONO(chrono["oneshot-mpi:barrier"],
chrono["mpi:barrier"].start(); WITH_CHRONO(chrono["mpi:barrier"],
// TODO: REMOVE if (in.barrier) MPI_Barrier(universe);
if (in.barrier == 1) ))
MPI_Barrier(universe);
chrono["mpi:barrier"].stop();
chrono["oneshot-mpi:barrier"].stop();
if (iteration % in.iterationMod == 0) { if (iteration % in.iterationMod == 0) {
LOG(0,"Atrip") LOG(0,"Atrip")
@ -3044,7 +3041,7 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
const ABCTuple abc = isFakeTuple(i) const ABCTuple abc = isFakeTuple(i)
? tuplesList[tuplesList.size() - 1] ? tuplesList[tuplesList.size() - 1]
: tuplesList[i] : tuplesList[i]
, *abcNext = i == (abcIndex.second - 1) , *abcNext = i == (tuplesList.size() - 1)
? nullptr ? nullptr
: isFakeTuple(i + 1) : isFakeTuple(i + 1)
? &tuplesList[tuplesList.size() - 1] ? &tuplesList[tuplesList.size() - 1]
@ -3061,12 +3058,12 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
// COMM FIRST DATABASE ================================================{{{1 // COMM FIRST DATABASE ================================================{{{1
if (i == abcIndex.first) { if (i == 0) {
WITH_RANK << "__first__:first database ............ \n"; WITH_RANK << "__first__:first database ............ \n";
const auto __db = communicateDatabase(abc, universe); const auto db = communicateDatabase(abc, universe);
WITH_RANK << "__first__:first database communicated \n"; WITH_RANK << "__first__:first database communicated \n";
WITH_RANK << "__first__:first database io phase \n"; WITH_RANK << "__first__:first database io phase \n";
doIOPhase(__db); doIOPhase(db);
WITH_RANK << "__first__:first database io phase DONE\n"; WITH_RANK << "__first__:first database io phase DONE\n";
WITH_RANK << "__first__::::Unwrapping all slices for first database\n"; WITH_RANK << "__first__::::Unwrapping all slices for first database\n";
for (auto& u: unions) u->unwrapAll(abc); for (auto& u: unions) u->unwrapAll(abc);
@ -3078,8 +3075,7 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
if (abcNext) { if (abcNext) {
WITH_RANK << "__comm__:" << iteration << "th communicating database\n"; WITH_RANK << "__comm__:" << iteration << "th communicating database\n";
chrono["db:comm"].start(); chrono["db:comm"].start();
//const auto db = communicateDatabase(*abcNext, universe); const auto db = communicateDatabase(*abcNext, universe);
db = communicateDatabase(*abcNext, universe);
chrono["db:comm"].stop(); chrono["db:comm"].stop();
chrono["db:io"].start(); chrono["db:io"].start();
doIOPhase(db); doIOPhase(db);
@ -3295,12 +3291,17 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
#pragma once #pragma once
#define ATRIP_BENCHMARK #define ATRIP_BENCHMARK
//#define ATRIP_DONT_SLICE //#define ATRIP_DONT_SLICE
#define ATRIP_DEBUG 1
//#define ATRIP_WORKLOAD_DUMP //#define ATRIP_WORKLOAD_DUMP
#define ATRIP_USE_DGEMM #define ATRIP_USE_DGEMM
//#define ATRIP_PRINT_TUPLES //#define ATRIP_PRINT_TUPLES
#ifndef ATRIP_DEBUG
#define ATRIP_DEBUG 1
#endif
#ifndef LOG
#define LOG(level, name) if (Atrip::rank == 0) std::cout << name << ": " #define LOG(level, name) if (Atrip::rank == 0) std::cout << name << ": "
#endif
#if ATRIP_DEBUG == 4 #if ATRIP_DEBUG == 4
# pragma message("WARNING: You have OCD debugging ABC triples "\ # pragma message("WARNING: You have OCD debugging ABC triples "\
@ -3338,7 +3339,7 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
# define WITH_CRAZY_DEBUG if (false) # define WITH_CRAZY_DEBUG if (false)
# define WITH_DBG # define WITH_DBG
# define DBG(...) dbg(__VA_ARGS__) # define DBG(...) dbg(__VA_ARGS__)
#elif ATRIP_DEBUG == 1 #else
# define OCD_Barrier(com) # define OCD_Barrier(com)
# define WITH_OCD if (false) # define WITH_OCD if (false)
# define WITH_ROOT if (false) # define WITH_ROOT if (false)
@ -3347,8 +3348,6 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
# define WITH_DBG if (false) # define WITH_DBG if (false)
# define WITH_CRAZY_DEBUG if (false) # define WITH_CRAZY_DEBUG if (false)
# define DBG(...) # define DBG(...)
#else
# error("ATRIP_DEBUG is not defined!")
#endif #endif
#+end_src #+end_src