-
Notifications
You must be signed in to change notification settings - Fork 19
Read input file to determine dimensions #974
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
Conversation
dcdf6b4 to
6aaebd5
Compare
|
[Rebased on top of updated base branch] |
c60b3eb to
f5428d5
Compare
|
[Rebased on top of |
f5428d5 to
e45bfe1
Compare
core/src/ParaGridIO.cpp
Outdated
| // TODO: Do this once rather than with every read | ||
| ModelMetadata& metadata = ModelMetadata::getInstance(); | ||
| metadata.setDimensionsFromFile(filePath); |
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.
Question for reviewer: Do we really want to set dimensions from file in every call to getModelState, as in the existing implementation? Would it not be better to do the following?
| // TODO: Do this once rather than with every read | |
| ModelMetadata& metadata = ModelMetadata::getInstance(); | |
| metadata.setDimensionsFromFile(filePath); | |
| ModelMetadata& metadata = ModelMetadata::getInstance(); | |
| if (filePath /= metadata.initialFileName) { | |
| metadata.setDimensionsFromFile(filePath); | |
| } |
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.
How many calls to getModelState() are expected? In each model run, there should only be one call to SomethingGrid::getModelState() and within that one call to SomethingGridIO::getModelState() (where SomethingGrid is the name of the IStructureimplementing class). There are a few more examples around the code base for testing, but I believe that is all.
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.
Fair point, thanks. I removed the TODO in 17ea449 and will merge once tests pass.
timspainNERSC
left a comment
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 we were calling getModelState() in the main model loop, the extra change would be worth adding. As it should only be called once per run, I'm not sure even the small amount of added complexity is worthwhile.
core/src/ParaGridIO.cpp
Outdated
| // TODO: Do this once rather than with every read | ||
| ModelMetadata& metadata = ModelMetadata::getInstance(); | ||
| metadata.setDimensionsFromFile(filePath); |
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.
How many calls to getModelState() are expected? In each model run, there should only be one call to SomethingGrid::getModelState() and within that one call to SomethingGridIO::getModelState() (where SomethingGrid is the name of the IStructureimplementing class). There are a few more examples around the code base for testing, but I believe that is all.
|
Actually, before merging I should check with @Thanduriel that this PR does what was requested and will be of use in the GPU port? |
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 solved my buffer initialization problem by doing it lazily on GPU, so as long as the CPU initialization still works it should be fine for me.
I noticed that you sometimes pass large objects (like std::string) by value. This is considered bad practice in general for performance reasons (see the CppCoreGuidelines). It does not really matter in the places I commented on, so you decide if you want to change it, but I think it is best to simply always follow the linked rule.
core/src/Xios.cpp
Outdated
| auto& metadata = ModelMetadata::getInstance(); | ||
|
|
||
| // Initial read of the NetCDF file to deduce the dimensions | ||
| for (std::string filename : { inputFilename, forcingFilename }) { |
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.
Unnecessary copy.
for(const std::string& filename : ...)
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.
Thanks @Thanduriel, fixed in 7c27843.
core/src/ModelMetadata.cpp
Outdated
|
|
||
| #endif | ||
|
|
||
| void ModelMetadata::setDimensionsFromFile(const std::string filename) |
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.
Unnecessary copy, could be a reference.
void ModelMetadata::setDimensionsFromFile(const std::string& filename)
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.
Fixed in 7c27843.
core/src/include/ModelMetadata.hpp
Outdated
| * set. Otherwise, a consistency check is made against the dimensions read from file | ||
| * and already set. | ||
| */ | ||
| void setDimensionsFromFile(const std::string filename); |
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.
.
# XIOS handler restructure Fixes #850 Fixes #1000 ~~Merges into #974~~ This will hopefully be the last major restructuring of the XIOS handler class. The PR includes some pruning: * Remove unused `enableXios` function. * Drop errors from the `ParaGridIO_Xios` member functions already thrown in `Xios.read` and `Xios.write`. * Cut down the `configGetX` member functions. * Remove the `contextId` and `calendarType` arguments from the constructor because they're now set in `iodef.xml` as of #993. It also includes better modularisation: * Extract a new `setupFiles` member function out of the constructor. * Rename `parseInputFiles` as `setupFields`. * Split the configuration into `setupClient`, `setupContext`, and `setupCalendar` and have all of them called from `configure` alongside `setupFiles` and `setupFields`. Other misc changes: * Additional checking of the calendar setup. * Reordering of member functions to better group XIOS concepts together. * Better use of references to avoid unnecessary copies. * Use of `const` qualifier in more places.
Read input file to determine dimensions
Fixes #972
Merges into #968
Task List
Change Description
Currently, there are differences in how the serial, MPI-parallel, and XIOS configurations read dimensions. For greater consistency, this PR implements a
setDimensionsFromFilemember function forModelMetadata. It gets called inModel.configureRestarts. It also gets called inParaGridIO.getModelState(for consistency with the existing implementation).Test Description
XIOS tests are updated to account for the fact that dimensions are set in
Model.configureRestarts.Documentation Impact
None
Pre-Request Checklist