votca 2026-dev
Loading...
Searching...
No Matches
votca::xtp::GridBoxAccumulator Class Reference

Adds per-grid-box blocks into a set of AO matrices from inside an OpenMP loop over grid boxes. More...

#include <gridboxaccumulator.h>

Collaboration diagram for votca::xtp::GridBoxAccumulator:

Public Member Functions

 GridBoxAccumulator (std::vector< Eigen::MatrixXd * > targets, double budget_bytes=2.0e9)
 ~GridBoxAccumulator ()
 GridBoxAccumulator (const GridBoxAccumulator &)=delete
GridBoxAccumulator & operator= (const GridBoxAccumulator &)=delete
bool UsesThreadLocalCopies () const
void Add (const GridBox &box, const std::vector< const Eigen::MatrixXd * > &small)
void Finish ()
 sums the thread-local copies into the targets (call outside the loop)

Private Attributes

std::vector< Eigen::MatrixXd * > targets_
bool thread_local_ = false
std::vector< std::vector< Eigen::MatrixXd > > copies_

Detailed Description

Adds per-grid-box blocks into a set of AO matrices from inside an OpenMP loop over grid boxes.

A single critical section around all matrices serializes the loop when there are many of them (one per response density or per atom). Two strategies instead:

  • thread-local copies of all target matrices, summed once in Finish(), when they fit into the memory budget (no synchronization at all);
  • otherwise one lock per matrix, taken in a thread-dependent order so that threads work on different matrices. Results are identical up to the order of floating-point additions.

Usage: construct before the parallel loop, call Add() inside it (any thread), call Finish() after it.

Definition at line 56 of file gridboxaccumulator.h.

Constructor & Destructor Documentation

◆ GridBoxAccumulator() [1/2]

votca::xtp::GridBoxAccumulator::GridBoxAccumulator ( std::vector< Eigen::MatrixXd * > targets,
double budget_bytes = 2.0e9 )
inlineexplicit

targets: zero-initialized matrices of equal size; budget in bytes for the thread-local copies (all threads together)

Definition at line 60 of file gridboxaccumulator.h.

◆ ~GridBoxAccumulator()

votca::xtp::GridBoxAccumulator::~GridBoxAccumulator ( )
inline

Definition at line 87 of file gridboxaccumulator.h.

◆ GridBoxAccumulator() [2/2]

votca::xtp::GridBoxAccumulator::GridBoxAccumulator ( const GridBoxAccumulator & )
delete

Member Function Documentation

◆ Add()

void votca::xtp::GridBoxAccumulator::Add ( const GridBox & box,
const std::vector< const Eigen::MatrixXd * > & small )
inline

adds the box blocks small[k] into target k, for all k (same order as the targets); entries with size 0 are skipped

Definition at line 101 of file gridboxaccumulator.h.

◆ Finish()

void votca::xtp::GridBoxAccumulator::Finish ( )
inline

sums the thread-local copies into the targets (call outside the loop)

Definition at line 163 of file gridboxaccumulator.h.

◆ operator=()

GridBoxAccumulator & votca::xtp::GridBoxAccumulator::operator= ( const GridBoxAccumulator & )
delete

◆ UsesThreadLocalCopies()

bool votca::xtp::GridBoxAccumulator::UsesThreadLocalCopies ( ) const
inline

Definition at line 97 of file gridboxaccumulator.h.

Member Data Documentation

◆ copies_

std::vector<std::vector<Eigen::MatrixXd> > votca::xtp::GridBoxAccumulator::copies_
private

Definition at line 182 of file gridboxaccumulator.h.

◆ targets_

std::vector<Eigen::MatrixXd*> votca::xtp::GridBoxAccumulator::targets_
private

Definition at line 180 of file gridboxaccumulator.h.

◆ thread_local_

bool votca::xtp::GridBoxAccumulator::thread_local_ = false
private

Definition at line 181 of file gridboxaccumulator.h.


The documentation for this class was generated from the following file: