Skip to content

Commit dafe4e8

Browse files
committed
add better docstring about gathering
1 parent c2e4e3d commit dafe4e8

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

‎GridKit/Model/OptimalPowerFlow/ComponentImpl.hpp‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
* @file ComponentImpl.hpp
33
* @brief Definition of `Component`, included by model translation units.
44
*
5-
* `gather` copies the internal variables, then those at each port, into a
6-
* local array where the model evaluates, and the scatters add the results back.
7-
* Devices at the same bus add to the same entries, so a parallel evaluation
8-
* must synchronize those additions.
5+
* A component evaluates on a local copy. `gather` copies its own variables,
6+
* then the variables at each port, into one fixed-size array, the model
7+
* evaluates there, and the scatter functions add the results back into the
8+
* system vectors.
9+
*
10+
* Gathers only read, so they are safe in parallel. Scatters are not: every
11+
* device at a bus adds to that bus's entries, so those additions must be
12+
* synchronized, and buses with many devices are the likely bottleneck.
913
*/
1014

1115
#pragma once
@@ -91,7 +95,7 @@ namespace GridKit
9195
return 0;
9296
}
9397

94-
/// Internal, then each port's variables
98+
/// Copy the internal variables, then the variables each port reads from its component, into `x`
9599
template <typename scalar_type, typename index_type>
96100
void Component<scalar_type, index_type>::gather(ScalarT* x) const
97101
{

‎GridKit/Model/OptimalPowerFlow/SystemModel.hpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ namespace GridKit
2424
/**
2525
* @brief AC optimal power flow in Cartesian coordinates
2626
*
27+
* `allocate()` gives each component a contiguous block of the system
28+
* vectors. Each evaluation loops over the components, which gather,
29+
* evaluate, and scatter as described in ComponentImpl.hpp.
30+
*
31+
* @todo Address thread safety. Constraint and gradient scatters and the
32+
* derivative refill add to entries shared by devices at the same bus.
33+
*
2734
* @todo Replace the temporary STL containers of system-level data.
2835
*/
2936
template <typename scalar_type, typename index_type>

‎GridKit/Model/OptimalPowerFlow/SystemModelEnzyme.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
* @file SystemModelEnzyme.cpp
33
* @brief Optimal power flow system derivatives from component Enzyme entries.
44
*
5-
* Each component writes its derivative entries to its own buffer. `refill`
6-
* adds them into the CSR values, where entries of different components can
7-
* share a value, so a parallel refill must synchronize those additions.
5+
* Each component writes its derivative entries to its own buffer, so the
6+
* components can be differentiated in parallel. `refill` then adds every entry
7+
* into the CSR values, and entries from devices at the same bus land on the
8+
* same value, so a parallel refill must synchronize those additions.
89
*/
910

1011
#include <algorithm>

0 commit comments

Comments
 (0)