Templatize main algorithm
This commit is contained in:
parent
f8dd6b3f31
commit
5c177a85bc
127
atrip.org
127
atrip.org
@ -2028,7 +2028,8 @@ void Atrip::init() {
|
|||||||
MPI_Comm_size(MPI_COMM_WORLD, &Atrip::np);
|
MPI_Comm_size(MPI_COMM_WORLD, &Atrip::np);
|
||||||
}
|
}
|
||||||
|
|
||||||
Atrip::Output Atrip::run(Atrip::Input const& in) {
|
template <typename F>
|
||||||
|
Atrip::Output Atrip::run(Atrip::Input<F> const& in) {
|
||||||
|
|
||||||
const int np = Atrip::np;
|
const int np = Atrip::np;
|
||||||
const int rank = Atrip::rank;
|
const int rank = Atrip::rank;
|
||||||
@ -2043,14 +2044,14 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
LOG(0,"Atrip") << "Nv: " << Nv << "\n";
|
LOG(0,"Atrip") << "Nv: " << Nv << "\n";
|
||||||
|
|
||||||
// allocate the three scratches, see piecuch
|
// allocate the three scratches, see piecuch
|
||||||
std::vector<double> Tijk(No*No*No) // doubles only (see piecuch)
|
std::vector<F> Tijk(No*No*No) // doubles only (see piecuch)
|
||||||
, Zijk(No*No*No) // singles + doubles (see piecuch)
|
, Zijk(No*No*No) // singles + doubles (see piecuch)
|
||||||
// we need local copies of the following tensors on every
|
// we need local copies of the following tensors on every
|
||||||
// rank
|
// rank
|
||||||
, epsi(No)
|
, epsi(No)
|
||||||
, epsa(Nv)
|
, epsa(Nv)
|
||||||
, Tai(No * Nv)
|
, Tai(No * Nv)
|
||||||
;
|
;
|
||||||
|
|
||||||
in.ei->read_all(epsi.data());
|
in.ei->read_all(epsi.data());
|
||||||
in.ea->read_all(epsa.data());
|
in.ea->read_all(epsa.data());
|
||||||
@ -2079,20 +2080,20 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
chrono["nv-slices"].start();
|
chrono["nv-slices"].start();
|
||||||
// BUILD SLICES PARAMETRIZED BY NV ==================================={{{1
|
// BUILD SLICES PARAMETRIZED BY NV ==================================={{{1
|
||||||
LOG(0,"Atrip") << "BUILD NV-SLICES\n";
|
LOG(0,"Atrip") << "BUILD NV-SLICES\n";
|
||||||
TAPHH taphh(*in.Tpphh, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
TAPHH<F> taphh(*in.Tpphh, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
||||||
HHHA hhha(*in.Vhhhp, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
HHHA<F> hhha(*in.Vhhhp, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
||||||
chrono["nv-slices"].stop();
|
chrono["nv-slices"].stop();
|
||||||
|
|
||||||
chrono["nv-nv-slices"].start();
|
chrono["nv-nv-slices"].start();
|
||||||
// BUILD SLICES PARAMETRIZED BY NV x NV =============================={{{1
|
// BUILD SLICES PARAMETRIZED BY NV x NV =============================={{{1
|
||||||
LOG(0,"Atrip") << "BUILD NV x NV-SLICES\n";
|
LOG(0,"Atrip") << "BUILD NV x NV-SLICES\n";
|
||||||
ABPH abph(*in.Vppph, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
ABPH<F> abph(*in.Vppph, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
||||||
ABHH abhh(*in.Vpphh, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
ABHH<F> abhh(*in.Vpphh, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
||||||
TABHH tabhh(*in.Tpphh, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
TABHH<F> tabhh(*in.Tpphh, (size_t)No, (size_t)Nv, (size_t)np, child_comm, universe);
|
||||||
chrono["nv-nv-slices"].stop();
|
chrono["nv-nv-slices"].stop();
|
||||||
|
|
||||||
// all tensors
|
// all tensors
|
||||||
std::vector< SliceUnion* > unions = {&taphh, &hhha, &abph, &abhh, &tabhh};
|
std::vector< SliceUnion<F>* > unions = {&taphh, &hhha, &abph, &abhh, &tabhh};
|
||||||
|
|
||||||
//CONSTRUCT TUPLE LIST ==============================================={{{1
|
//CONSTRUCT TUPLE LIST ==============================================={{{1
|
||||||
LOG(0,"Atrip") << "BUILD TUPLE LIST\n";
|
LOG(0,"Atrip") << "BUILD TUPLE LIST\n";
|
||||||
@ -2126,18 +2127,20 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
= [&tuplesList](size_t const i) { return i >= tuplesList.size(); };
|
= [&tuplesList](size_t const i) { return i >= tuplesList.size(); };
|
||||||
|
|
||||||
|
|
||||||
|
using Database = typename Slice<F>::Database;
|
||||||
|
using LocalDatabase = typename Slice<F>::LocalDatabase;
|
||||||
auto communicateDatabase
|
auto communicateDatabase
|
||||||
= [ &unions
|
= [ &unions
|
||||||
, np
|
, np
|
||||||
, &chrono
|
, &chrono
|
||||||
] (ABCTuple const& abc, MPI_Comm const& c) -> Slice::Database {
|
] (ABCTuple const& abc, MPI_Comm const& c) -> typename Slice<F>::Database {
|
||||||
|
|
||||||
chrono["db:comm:type:do"].start();
|
chrono["db:comm:type:do"].start();
|
||||||
auto MPI_LDB_ELEMENT = Slice::mpi::localDatabaseElement();
|
auto MPI_LDB_ELEMENT = Slice<F>::mpi::localDatabaseElement();
|
||||||
chrono["db:comm:type:do"].stop();
|
chrono["db:comm:type:do"].stop();
|
||||||
|
|
||||||
chrono["db:comm:ldb"].start();
|
chrono["db:comm:ldb"].start();
|
||||||
Slice::LocalDatabase ldb;
|
LocalDatabase ldb;
|
||||||
|
|
||||||
for (auto const& tensor: unions) {
|
for (auto const& tensor: unions) {
|
||||||
auto const& tensorDb = tensor->buildLocalDatabase(abc);
|
auto const& tensorDb = tensor->buildLocalDatabase(abc);
|
||||||
@ -2145,7 +2148,8 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
}
|
}
|
||||||
chrono["db:comm:ldb"].stop();
|
chrono["db:comm:ldb"].stop();
|
||||||
|
|
||||||
Slice::Database db(np * ldb.size(), ldb[0]);
|
typename
|
||||||
|
Slice<F>::Database db(np * ldb.size(), ldb[0]);
|
||||||
|
|
||||||
chrono["oneshot-db:comm:allgather"].start();
|
chrono["oneshot-db:comm:allgather"].start();
|
||||||
chrono["db:comm:allgather"].start();
|
chrono["db:comm:allgather"].start();
|
||||||
@ -2167,7 +2171,7 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
auto doIOPhase
|
auto doIOPhase
|
||||||
= [&unions, &rank, &np, &universe, &chrono] (Slice::Database const& db) {
|
= [&unions, &rank, &np, &universe, &chrono] (typename Slice<F>::Database const& db) {
|
||||||
|
|
||||||
const size_t localDBLength = db.size() / np;
|
const size_t localDBLength = db.size() / np;
|
||||||
|
|
||||||
@ -2217,7 +2221,7 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
;
|
;
|
||||||
for (auto it = begin; it != end; ++it) {
|
for (auto it = begin; it != end; ++it) {
|
||||||
sendTag++;
|
sendTag++;
|
||||||
Slice::LocalDatabaseElement const& el = *it;
|
typename Slice<F>::LocalDatabaseElement const& el = *it;
|
||||||
|
|
||||||
if (el.info.from.rank != rank) continue;
|
if (el.info.from.rank != rank) continue;
|
||||||
|
|
||||||
@ -2266,7 +2270,7 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
|
|
||||||
// START MAIN LOOP ======================================================{{{1
|
// START MAIN LOOP ======================================================{{{1
|
||||||
|
|
||||||
Slice::Database db;
|
typename Slice<F>::Database db;
|
||||||
|
|
||||||
for ( size_t i = abcIndex.first, iteration = 1
|
for ( size_t i = abcIndex.first, iteration = 1
|
||||||
; i < abcIndex.second
|
; i < abcIndex.second
|
||||||
@ -2373,30 +2377,31 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
)))
|
)))
|
||||||
chrono["oneshot-doubles"].start();
|
chrono["oneshot-doubles"].start();
|
||||||
chrono["doubles"].start();
|
chrono["doubles"].start();
|
||||||
doublesContribution( abc, (size_t)No, (size_t)Nv
|
LOGREMOVE << "doubles " << iteration << "\n";
|
||||||
// -- VABCI
|
doublesContribution<F>( abc, (size_t)No, (size_t)Nv
|
||||||
, abph.unwrapSlice(Slice::AB, abc)
|
// -- VABCI
|
||||||
, abph.unwrapSlice(Slice::AC, abc)
|
, abph.unwrapSlice(Slice<F>::AB, abc)
|
||||||
, abph.unwrapSlice(Slice::BC, abc)
|
, abph.unwrapSlice(Slice<F>::AC, abc)
|
||||||
, abph.unwrapSlice(Slice::BA, abc)
|
, abph.unwrapSlice(Slice<F>::BC, abc)
|
||||||
, abph.unwrapSlice(Slice::CA, abc)
|
, abph.unwrapSlice(Slice<F>::BA, abc)
|
||||||
, abph.unwrapSlice(Slice::CB, abc)
|
, abph.unwrapSlice(Slice<F>::CA, abc)
|
||||||
// -- VHHHA
|
, abph.unwrapSlice(Slice<F>::CB, abc)
|
||||||
, hhha.unwrapSlice(Slice::A, abc)
|
// -- VHHHA
|
||||||
, hhha.unwrapSlice(Slice::B, abc)
|
, hhha.unwrapSlice(Slice<F>::A, abc)
|
||||||
, hhha.unwrapSlice(Slice::C, abc)
|
, hhha.unwrapSlice(Slice<F>::B, abc)
|
||||||
// -- TA
|
, hhha.unwrapSlice(Slice<F>::C, abc)
|
||||||
, taphh.unwrapSlice(Slice::A, abc)
|
// -- TA
|
||||||
, taphh.unwrapSlice(Slice::B, abc)
|
, taphh.unwrapSlice(Slice<F>::A, abc)
|
||||||
, taphh.unwrapSlice(Slice::C, abc)
|
, taphh.unwrapSlice(Slice<F>::B, abc)
|
||||||
// -- TABIJ
|
, taphh.unwrapSlice(Slice<F>::C, abc)
|
||||||
, tabhh.unwrapSlice(Slice::AB, abc)
|
// -- TABIJ
|
||||||
, tabhh.unwrapSlice(Slice::AC, abc)
|
, tabhh.unwrapSlice(Slice<F>::AB, abc)
|
||||||
, tabhh.unwrapSlice(Slice::BC, abc)
|
, tabhh.unwrapSlice(Slice<F>::AC, abc)
|
||||||
// -- TIJK
|
, tabhh.unwrapSlice(Slice<F>::BC, abc)
|
||||||
, Tijk.data()
|
// -- TIJK
|
||||||
, chrono
|
, Tijk.data()
|
||||||
);
|
, chrono
|
||||||
|
);
|
||||||
WITH_RANK << iteration << "-th doubles done\n";
|
WITH_RANK << iteration << "-th doubles done\n";
|
||||||
chrono["doubles"].stop();
|
chrono["doubles"].stop();
|
||||||
chrono["oneshot-doubles"].stop();
|
chrono["oneshot-doubles"].stop();
|
||||||
@ -2414,12 +2419,12 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
for (size_t I(0); I < Zijk.size(); I++) Zijk[I] = Tijk[I];
|
for (size_t I(0); I < Zijk.size(); I++) Zijk[I] = Tijk[I];
|
||||||
chrono["reorder"].stop();
|
chrono["reorder"].stop();
|
||||||
chrono["singles"].start();
|
chrono["singles"].start();
|
||||||
singlesContribution( No, Nv, abc
|
singlesContribution<F>( No, Nv, abc
|
||||||
, Tai.data()
|
, Tai.data()
|
||||||
, abhh.unwrapSlice(Slice::AB, abc)
|
, abhh.unwrapSlice(Slice<F>::AB, abc)
|
||||||
, abhh.unwrapSlice(Slice::AC, abc)
|
, abhh.unwrapSlice(Slice<F>::AC, abc)
|
||||||
, abhh.unwrapSlice(Slice::BC, abc)
|
, abhh.unwrapSlice(Slice<F>::BC, abc)
|
||||||
, Zijk.data());
|
, Zijk.data());
|
||||||
chrono["singles"].stop();
|
chrono["singles"].stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2431,13 +2436,13 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
int distinct(0);
|
int distinct(0);
|
||||||
if (abc[0] == abc[1]) distinct++;
|
if (abc[0] == abc[1]) distinct++;
|
||||||
if (abc[1] == abc[2]) distinct--;
|
if (abc[1] == abc[2]) distinct--;
|
||||||
const double epsabc(epsa[abc[0]] + epsa[abc[1]] + epsa[abc[2]]);
|
const F epsabc(epsa[abc[0]] + epsa[abc[1]] + epsa[abc[2]]);
|
||||||
|
|
||||||
chrono["energy"].start();
|
chrono["energy"].start();
|
||||||
if ( distinct == 0)
|
if ( distinct == 0)
|
||||||
tupleEnergy = getEnergyDistinct(epsabc, epsi, Tijk, Zijk);
|
tupleEnergy = getEnergyDistinct<F>(epsabc, epsi, Tijk, Zijk);
|
||||||
else
|
else
|
||||||
tupleEnergy = getEnergySame(epsabc, epsi, Tijk, Zijk);
|
tupleEnergy = getEnergySame<F>(epsabc, epsi, Tijk, Zijk);
|
||||||
chrono["energy"].stop();
|
chrono["energy"].stop();
|
||||||
|
|
||||||
#if defined(HAVE_OCD) || defined(ATRIP_PRINT_TUPLES)
|
#if defined(HAVE_OCD) || defined(ATRIP_PRINT_TUPLES)
|
||||||
@ -2478,8 +2483,8 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
<< " :abc " << pretty_print(abc)
|
<< " :abc " << pretty_print(abc)
|
||||||
<< " :abcN " << pretty_print(*abcNext)
|
<< " :abcN " << pretty_print(*abcNext)
|
||||||
<< "\n";
|
<< "\n";
|
||||||
for (auto const& slice: u->slices)
|
// for (auto const& slice: u->slices)
|
||||||
WITH_RANK << "__gc__:guts:" << slice.info << "\n";
|
// WITH_RANK << "__gc__:guts:" << slice.info << "\n";
|
||||||
u->clearUnusedSlicesForNext(*abcNext);
|
u->clearUnusedSlicesForNext(*abcNext);
|
||||||
|
|
||||||
WITH_RANK << "__gc__: checking validity\n";
|
WITH_RANK << "__gc__: checking validity\n";
|
||||||
@ -2487,13 +2492,13 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
#ifdef HAVE_OCD
|
#ifdef HAVE_OCD
|
||||||
// check for validity of the slices
|
// check for validity of the slices
|
||||||
for (auto type: u->sliceTypes) {
|
for (auto type: u->sliceTypes) {
|
||||||
auto tuple = Slice::subtupleBySlice(abc, type);
|
auto tuple = Slice<F>::subtupleBySlice(abc, type);
|
||||||
for (auto& slice: u->slices) {
|
for (auto& slice: u->slices) {
|
||||||
if ( slice.info.type == type
|
if ( slice.info.type == type
|
||||||
&& slice.info.tuple == tuple
|
&& slice.info.tuple == tuple
|
||||||
&& slice.isDirectlyFetchable()
|
&& slice.isDirectlyFetchable()
|
||||||
) {
|
) {
|
||||||
if (slice.info.state == Slice::Dispatched)
|
if (slice.info.state == Slice<F>::Dispatched)
|
||||||
throw std::domain_error( "This slice should not be undispatched! "
|
throw std::domain_error( "This slice should not be undispatched! "
|
||||||
+ pretty_print(slice.info));
|
+ pretty_print(slice.info));
|
||||||
}
|
}
|
||||||
@ -2560,6 +2565,10 @@ Atrip::Output Atrip::run(Atrip::Input const& in) {
|
|||||||
return { - globalEnergy };
|
return { - globalEnergy };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// instantiate
|
||||||
|
template Atrip::Output Atrip::run(Atrip::Input<double> const& in);
|
||||||
|
template Atrip::Output Atrip::run(Atrip::Input<Complex> const& in);
|
||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user