-
Notifications
You must be signed in to change notification settings - Fork 392
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
Replace readItem in ProcessNumber to speed-up SolarShadingTest_ImportedShading #8819
Conversation
The run time differences are amazing. I wish we knew what was causing so much improvement in Mac builds, or, what was causing Mac builds to slow down so much with the original code. The runtimes in Linux builds only had an improvement from 8s to 5s. I wonder if it is something to do with the compiler we use for Mac builds, since the code is the same. |
I'm not sure what the issue is. |
The ScheduleManager refactor is focused on decreasing unnecessary file open, close operations where they can be avoided. I was using the original |
Since ProcessNumber is used in three places in ScheduleManager.cc, any case that uses those parts of the code should see improvements from this PR:
|
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.
@mitchute Similar timing results on Windows (just one run each, so not super accurate):
SolarShadingTest_ExternalFraction went from 214s to 113s
SolarShadingTest_ImportedShading went from 118s to 10s
This looks good so far. It would be good to have a unit test that exercises the new catch
blocks. I've tested one path with bad values in Schedule;Compact and in the csv (I think), but a unit test that covers all the flavors of numbers this could see including bad values would be useful.
Thanks, @mjwitte. Yes, I was going to do that but it looks like I didn't get it done. I'll work one up. |
src/EnergyPlus/UtilityRoutines.cc
Outdated
ErrorFlag = false; | ||
try { | ||
rProcessNumber = std::stod(PString, nullptr); | ||
ErrorFlag = false; |
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.
ErrorFlag = false is already set at line 128. Delete line 138. Also, remember the discussion long ago about setting a function argument bool &ErrorFlag to false within any function. It's OK to set it true, but don't set it to false which would erase any previous error. To that end I would delete line 128 as well. @mjwitte.
I am amazed at the impact this has on execution speed!
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.
It looks like there are several places in code where this function is called that relies on ErrorFlag being true or false for each specific call. So do not delete line 128,
OK, the unit test has been added. I marked the "3.14159+0" - returns 3.14159 Maybe we should also be checking for multiple "+", "-", ".", and "E" (or similar, "d", "D", or "e"). It looks like |
Ah, I figured out the Anything else? |
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 all looks good with a remarkable improvement in execution speed.
With this speed improvement, wouldn't it be smarter to catch that in the input processor? |
I'm honestly not sure what the right path is currently. I think we'll find that this a part of all input processing, regardless of whether it happens in the |
Just a thought, could this be moved to the input processor for numeric inputs? That certainly does not have to happen in this branch since all looks good here.
|
This looks good to me. Testing done:
|
try { | ||
rProcessNumber = std::stod(PString, nullptr); | ||
} catch (std::invalid_argument &e) { | ||
rProcessNumber = 0.0; | ||
ErrorFlag = true; | ||
} catch (std::out_of_range &e) { | ||
rProcessNumber = 0.0; | ||
ErrorFlag = true; | ||
} |
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.
Looks great!
badString = "1E5000"; | ||
expectedVal = 0.0; | ||
EXPECT_NEAR(UtilityRoutines::ProcessNumber(badString, expectedError), expectedVal, 1E-5); | ||
EXPECT_TRUE(expectedError); |
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 think this is comprehensive, and touched the cases I could think of.
This is absolutely awesome! I'll look over the code changes now but this has been reviewed by multiple folks and looks like it has a great unit test in place. CI is really happy too. |
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.
OK this is ridiculous. What an impactful change!!!
All clean with develop merged up. Thanks all. |
Pull request overview
readItem
inProcessNumber
withstd::stod
.Runtimes for SolarShadingTest_ImportedShading
Before
Run 1: 170.00 s
Run 2: 173.31 s
Run 3: 156.62 s
After
Run 1: 15.77 s
Run 2: 15.25 s
Run 3: 10.68 s
Run 4: 11.55 s
Run 5: 12.32 s
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.