Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr memory #493

Merged
merged 5 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/madness/chem/SCF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1322,29 +1322,21 @@ vecfuncT SCF::apply_potential(World& world, const tensorT& occ,

vloc.truncate();

START_TIMER(world);
vecfuncT Vpsi;
if (!molecule.parameters.pure_ae()) {
Vpsi = gthpseudopotential->apply_potential(world, vloc, amo, occ, enl);
} else {
Vpsi = mul_sparse(world, vloc, amo, vtol);
}

END_TIMER(world, "V*psi");
print_meminfo(world.rank(), "V*psi");
if (xc.hf_exchange_coefficient()) {
START_TIMER(world);
// vecfuncT Kamo = apply_hf_exchange(world, occ, amo, amo);
Exchange<double, 3> K = Exchange<double, 3>(world, this, ispin).set_symmetric(true);
Exchange<double, 3> K = Exchange<double, 3>(world, this, ispin);
K.set_symmetric(true).set_printlevel(param.print_level());
vecfuncT Kamo = K(amo);
tensorT excv = inner(world, Kamo, amo);
double exchf = 0.0;
for (unsigned long i = 0; i < amo.size(); ++i) {
exchf -= 0.5 * excv[i] * occ[i];
}
if (!xc.is_spin_polarized())
exchf *= 2.0;
gaxpy(world, 1.0, Vpsi, -xc.hf_exchange_coefficient(), Kamo);
if (!xc.is_spin_polarized()) exchf *= 2.0;
Vpsi=-xc.hf_exchange_coefficient()* Kamo;
Kamo.clear();
END_TIMER(world, "HF exchange");
exc = exchf * xc.hf_exchange_coefficient() + exc;
Expand All @@ -1354,6 +1346,15 @@ vecfuncT SCF::apply_potential(World& world, const tensorT& occ,
potentialmanager->apply_nonlocal_potential(world, amo, Vpsi);
}

START_TIMER(world);
if (!molecule.parameters.pure_ae()) {
Vpsi += gthpseudopotential->apply_potential(world, vloc, amo, occ, enl);
} else {
Vpsi += mul_sparse(world, vloc, amo, vtol);
}

END_TIMER(world, "V*psi");

START_TIMER(world);
truncate(world, Vpsi);
END_TIMER(world, "Truncate Vpsi");
Expand Down
34 changes: 27 additions & 7 deletions src/madness/chem/exchangeoperator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ namespace madness {
template<typename T, std::size_t NDIM>
Exchange<T, NDIM>::ExchangeImpl::ExchangeImpl(World& world, const SCF *calc, const int ispin)
: world(world), symmetric_(false), lo(calc->param.lo()) {
if (ispin == 0) { // alpha spin
mo_ket = convert<double, T, NDIM>(world, calc->amo); // deep copy necessary if T==double_complex
} else if (ispin == 1) { // beta spin
mo_ket = convert<double, T, NDIM>(world, calc->bmo);

if constexpr (std::is_same_v<T,double_complex>) {
if (ispin == 0) { // alpha spin
mo_ket = convert<double, T, NDIM>(world, calc->amo); // deep copy necessary if T==double_complex
} else if (ispin == 1) { // beta spin
mo_ket = convert<double, T, NDIM>(world, calc->bmo);
}
mo_bra = conj(world, mo_ket);
} else {
if (ispin == 0) { // alpha spin
mo_ket = calc->amo; // deep copy necessary if T==double_complex
} else if (ispin == 1) { // beta spin
mo_ket = calc->bmo;
}
mo_bra = mo_ket;
}
mo_bra = conj(world, mo_ket);

}

template<typename T, std::size_t NDIM>
Expand Down Expand Up @@ -67,7 +78,15 @@ std::vector<Function<T, NDIM> > Exchange<T, NDIM>::ExchangeImpl::operator()(
} else {
MADNESS_EXCEPTION("unknown algorithm in exchangeoperator", 1);
}
if (printdebug()) {
auto size = get_size(world, Kf);
if (world.rank() == 0) print("total size of Kf before truncation", size);
}
truncate(world, Kf);
if (printdebug()) {
auto size=get_size(world,Kf);
if (world.rank()==0) print("total size of Kf after truncation",size);
}
if (printlevel >= 3) print_timer(world);
return Kf;
}
Expand All @@ -87,7 +106,7 @@ template<typename T, std::size_t NDIM>
std::vector<Function<T, NDIM> >
Exchange<T, NDIM>::ExchangeImpl::K_macrotask_efficient(const vecfuncT& vf, const double mul_tol) const {

if (printdebug()) print("\nentering macrotask_efficient version:");
if (world.rank()==0 and printdebug()) print("\nentering macrotask_efficient version:");

// the result is a vector of functions living in the universe
const long nresult = vf.size();
Expand All @@ -96,13 +115,14 @@ Exchange<T, NDIM>::ExchangeImpl::K_macrotask_efficient(const vecfuncT& vf, const

// deferred execution if a taskq is provided by the user
if (taskq) {
taskq->set_printlevel(printlevel);
MacroTask mtask(world, xtask, taskq);
Kf = mtask(vf, mo_bra, mo_ket);
} else {
auto taskq_ptr = std::shared_ptr<MacroTaskQ>(new MacroTaskQ(world, world.size()));
taskq_ptr->set_printlevel(printlevel);
MacroTask mtask(world, xtask, taskq_ptr);
Kf = mtask(vf, mo_bra, mo_ket);
if (printdebug()) taskq_ptr->print_taskq();
taskq_ptr->run_all();
if (printdebug()) taskq_ptr->cloud.print_timings(world);
taskq_ptr->cloud.clear_timings();
Expand Down
2 changes: 2 additions & 0 deletions src/madness/mra/macrotaskq.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class MacroTaskQ : public WorldObject< MacroTaskQ> {

cloud.replicate();
universe.gop.fence();
if (printdebug()) cloud.print_size(universe);
universe.gop.set_forbid_fence(true); // make sure there are no hidden universe fences
pmap1=FunctionDefaults<1>::get_pmap();
pmap2=FunctionDefaults<2>::get_pmap();
Expand Down Expand Up @@ -225,6 +226,7 @@ class MacroTaskQ : public WorldObject< MacroTaskQ> {
universe.gop.fence();
if (universe.rank()==0) {
print("\ntaskq on universe rank",universe.rank());
print("total number of tasks: ",taskq.size());
print(" task batch priority status");
for (const auto& t : taskq) t->print_me_as_table();
}
Expand Down
36 changes: 36 additions & 0 deletions src/madness/world/cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct Recordlist {
class Cloud {

bool debug = false; ///< prints debug output
bool is_replicated=false; ///< if contents of the container are replicated
bool dofence = true; ///< fences after load/store
bool force_load_from_cache = false; ///< forces load from cache (mainly for debugging)

Expand Down Expand Up @@ -147,6 +148,36 @@ class Cloud {
force_load_from_cache = value;
}

void print_size(World& universe) {

std::size_t memsize=0;
for (auto& item : container) memsize+=item.second.size();
std::size_t global_memsize=memsize;
std::size_t max_memsize=memsize;
std::size_t min_memsize=memsize;
universe.gop.sum(global_memsize);
universe.gop.max(max_memsize);
universe.gop.min(min_memsize);

auto local_size=container.size();
auto global_size=local_size;
universe.gop.sum(global_size);
double byte2gbyte=1.0/(1024*1024*1024);

if (universe.rank()==0) {
print("Cloud memory:");
print(" replicated:",is_replicated);
print("size of cloud (total)");
print(" number of records:",global_size);
print(" memory in GBytes: ",global_memsize*byte2gbyte);
print("size of cloud (average per node)");
print(" number of records:",double(global_size)/universe.size());
print(" memory in GBytes: ",global_memsize*byte2gbyte/universe.size());
print("min/max of node");
print(" memory in GBytes: ",min_memsize*byte2gbyte,max_memsize*byte2gbyte);
}
}

void print_timings(World &universe) const {
double rtime = double(reading_time);
double wtime = double(writing_time);
Expand Down Expand Up @@ -196,6 +227,10 @@ class Cloud {

template<typename T>
recordlistT store(madness::World &world, const T &source) {
if (is_replicated) {
print("Cloud contents are replicated and read-only!");
MADNESS_EXCEPTION("cloud error",1);
}
cloudtimer t(world,writing_time);
recordlistT recordlist;
if constexpr (is_tuple<T>::value) {
Expand All @@ -212,6 +247,7 @@ class Cloud {
World& world=container.get_world();
cloudtimer t(world,replication_time);
container.reset_pmap_to_local();
is_replicated=true;

std::list<keyT> keylist;
for (auto it=container.begin(); it!=container.end(); ++it) {
Expand Down
Loading