-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
SurfaceWindow struct refactoring #8141
Conversation
@mjwitte @Myoldmopar This branch is ready for review and the refactoring efforts included in the current commits are listed in the PR overview. The CI is clean and CI performance suite is showing a 1.89% speedup. |
Xuan. I see that I am listed as a reviewer. I assume that is just a
courtesy. :)
…On Tue, Sep 1, 2020 at 1:24 PM Xuan Luo ***@***.***> wrote:
@mjwitte <https://github.com/mjwitte> @Myoldmopar
<https://github.com/Myoldmopar> This branch is ready for review and the
refactoring efforts included in the current commits are listed in the PR
overview. The CI is clean and CI performance suite is showing a 1.89%
speedup.
Some other surface arrays refactoring efforts are ongoing, but merging is
getting harder so I clean up some solid features and hope to get them
reviewed and merged first. I'll start another branch/draft PR to work on it
and keep this one as it is. Please let me know if you suggest otherwise.
@mjwitte <https://github.com/mjwitte> If you want to start your
investigation on movable insulation on top of this, please refer to this
branch.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#8141 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWYSISI7GHVZEJEBENQZFTSDUU3PANCNFSM4OU7UDPA>
.
--
__________________________________________
Amir Roth, PhD
http://energy.gov/eere/buildings/building-energy-modeling/
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll build locally with develop one more time and run tests.
@@ -1548,6 +1547,7 @@ namespace AirflowNetworkBalanceManager { | |||
using DataLoopNode::NodeConnectionType_Inlet; | |||
using DataLoopNode::NodeType_Air; | |||
using DataLoopNode::ObjectIsParent; | |||
using DataSurfaces::SurfWinOriginalClass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding more usings
isn't great. Probably not worth more commits, but we are moving away from it. Even if it makes the lines of code a little wider...that's hardly a problem on most folks monitors these days.
@@ -5153,19 +5153,19 @@ namespace AirflowNetworkBalanceManager { | |||
} | |||
SetupOutputVariable("AFN Surface Venting Window or Door Opening Modulation Multiplier", | |||
OutputProcessor::Unit::None, | |||
SurfaceWindow(SurfNum).VentingOpenFactorMultRep, | |||
DataSurfaces::SurfWinVentingOpenFactorMultRep(SurfNum), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in some cases, you put the namespace to avoid the using
.
// store the magnitude and time of the pulse | ||
radiantPulseTimestep(CurOverallSimDay, NZ) = (HourOfDay - 1) * NumOfTimeStepInHour + TimeStep; | ||
radiantPulseReceived(CurOverallSimDay, SurfNum) = (adjQL - curQL) * TMULT(radEnclosureNum) * ITABSF(SurfNum) * Surface(SurfNum).Area; | ||
for (int zoneNum = 1; zoneNum <= NumOfZones; ++zoneNum) {// Loop through all surfaces... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'm glad CI is showing no diffs to help me feel better about this functional change.
@@ -5515,7 +5513,7 @@ namespace InternalHeatGains { | |||
} | |||
|
|||
for (Loop = 1; Loop <= TotCO2Gen; ++Loop) { | |||
NZ = ZoneCO2Gen(Loop).ZonePtr; | |||
int NZ = ZoneCO2Gen(Loop).ZonePtr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Localizing NZ
is great.
|
||
std::vector<int> AllHTSurfaceList; // List of all heat transfer surfaces | ||
std::vector<int> AllIZSurfaceList; // List of all interzone heat transfer surfaces | ||
std::vector<int> AllHTNonWindowSurfaceList; // List of all non-window heat transfer surfaces | ||
std::vector<int> AllHTWindowSurfaceList; // List of all window surfaces | ||
std::vector<int> AllSurfaceListReportOrder; // List of all surfaces - output reporting order | ||
|
||
// Surface Window Heat Balance | ||
Array1D<Real64> SurfWinTransSolar; // Exterior beam plus diffuse solar transmitted through window, or window plus shade/blind, into zone (W) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot. I know this is one of the parts of EnergyPlus where things are looped over quickly, so I concede that this provides a performance benefit, but just no one get any ideas about doing this in lots of places in the code where we don't do tight loops over array items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't quite get the sentence after "but". By "doing this in lots of places in the code where we don't do tight loops over array items " do you mean using scalar arrays instead of struct arrays in places with loops that only call a few fields in the original SurfaceWindow struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, what is "this" in "this is a lot" referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If what you are referring to is the change from arrays of structs to arrays of scalars, then I don't think it's only a matter of tight loops. Tight loops (i.e., loops with no function calls or conditionals) are what you want for vectorization. But even without vectorization (which I don't think we are getting now) switching to arrays of scalars will improve your cache locality and utilization. If you have structs with a lot of fields that are only used in some calculations, in a given calculation you are probably bringing in a lot of that data unnecessarily. I think this is primarily what we are seeing here. I don't know that this type of transformation (which is really only partial for now) would be effective elsewhere in the code, but I would not dismiss it out of hand.
This runs fine locally. I'll leave this tab open to respond to comments but I have to run for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xuanluo113 Some initial comments.
@JasonGlazer This is likely to conflict with #8196 but oddly not as much as I thought, because many of the fields related to shading (e.g. WindowShadingControlPtr
) live on Surface
and SurfaceTemp
, not on SurfaceWindow
. But ShadedConstruction
exists in both places - ugh. I'm not finding where SurfWinShadedConstruction(SurfNum)
gets set to Surface(SurfNum).ShadedConstruction
.
But this didn't throw diffs and it just merged, so . . .
for (int zoneNum = 1; zoneNum <= NumOfZones; ++zoneNum) { | ||
int const firstSurfWin = Zone(zoneNum).WindowSurfaceFirst; | ||
int const lastSurfWin = Zone(zoneNum).WindowSurfaceLast; | ||
if (firstSurfWin == -1) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, these checks shouldn't be necessary. WindowSurfaceFirst
is initialized to zero, and for zones with no windows, WindowSurfaceLast
is set to -1 any loops on windowsurfaces will be skipped over. In fact, looking at this now, WindowSurfaceLast
and NonWindowSurfaceLast
should simply be initialized to -1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on windowSurfaceFirst to be initialized to 0 and windowSurfaceLast to be initialized to -1 is juuuuuuuust a little too cute. It's a recipe for bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjwitte I somehow wrongly pre-assumed this. And -1 is preferable if we want to convert these to vectors eventually? Can I make a follow-up PR to set WindowSurfaceLast
and NonWindowSurfaceLast
to -1 when no windows/opaqs and revised the checking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever you do, I would keep the check. Don't get too cute with loop bounds. It's not worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amirroth As it stand presently, *First
and *Last
are currently initialized to zero, and then *Last
is set to -1 if there are no surfaces in that group. Is there a better way to skip those loops when they are empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, set them both to -1 by default (which works for both 1- and 0-based arrays) and do a separate check. A check before a loop whether to do the loop or not is fine, in fact the compiler often inserts checks like that itself. A check on every element in the loop is a lot less fine.
Array1D<Real64> WinTransSolar; // Exterior beam plus diffuse solar transmitted through window, or | ||
// window plus shade/blind, into zone (W) | ||
Array1D<Real64> WinBmSolar; // Exterior beam solar transmitted through window, or | ||
// window plus blind, into zone (W) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering why you renamed arrays that were not previously part of SurfaceWindow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the naming convention/prefix we discussed about. SurfWin
, SurfOpaq
, Surf
, and Zone
to help understand their scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like, anything starts with SurfWin
is expected to be window indexed only and inside firstWindowSurf to lastWindowSurf loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I remember that discussion. I just didn't understand the scope of that went beyond the original SurfaceWindow struct. Not saying it needs to be undone, just didn't expect that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This convention should be propagated everywhere. The current naming convention "scheme" is terrible. As someone who doesn't actually know what should be going on, let me tell you, it really makes the code difficult to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I remember that discussion. I just didn't understand the scope of that went beyond the original SurfaceWindow struct. Not saying it needs to be undone, just didn't expect that.
:sweat_smile Yes. That went beyond that. Just after converting 30 of those beyond SurfaceWindow, I realized there are another 300 of them that better get renamed and I decided to get this partial effort merged before getting too far.
I see. @JasonGlazer Not sure if you've allowed for multiple blind numbers in #8196 . See here - this block looks like it may need modification to allow for multiple windowshadingcontrols. |
@mjwitte I will take a look at the code you pointed out. |
Pull request overview
The PR includes several refactoring effort on the SurfaceWindow related data structures, including:
Array1D A = 0.0
) to the element-wise assignment. This helps compiler level optimization.Pull Request Author
Add to this list or remove from it as applicable. This is a simple templated set of guidelines.
Reviewer
This will not be exhaustively relevant to every PR.