Skip to content
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

Align update of nextSIM-DG and XIOS calendars #757

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions .github/workflows/test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,43 @@ jobs:
cd test
python3 ThermoIntegration_test.py
./run_test_jan2010_integration_test.sh python3
cd -

test-ubuntu-mpi:
test-ubuntu-mpi-noxios:

runs-on: ubuntu-22.04
container:
image: ghcr.io/nextsimhub/nextsimdg-dev-env:latest

steps:
- uses: actions/checkout@v2

- name: build and compile with MPI but not XIOS
run: |
. /opt/spack-environment/activate.sh
mkdir -p build && cd build
cmake -DENABLE_MPI=ON -DENABLE_XIOS=OFF -DCMAKE_CXX_COMPILER="$(which mpic++)" ..
make -j 4

- name: run MPI tests
run: |
. /opt/spack-environment/activate.sh
apt update
apt install -y wget
cd build
(cd core/test && wget "ftp://ftp.nersc.no/nextsim/netCDF/partition_metadata_1.nc")
for component in core physics dynamics
do
cd $component/test
for file in $(find test* -maxdepth 0 -type f)
do
echo $file
nprocs=$(echo $file | sed -r "s/.*MPI([0-9]+)/\1/")
mpirun --allow-run-as-root --oversubscribe -n $nprocs ./$file
done
cd -
done

test-ubuntu-mpi-xios:
Comment on lines +54 to +89
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this change is the same as the one in #758.


runs-on: ubuntu-22.04
container:
Expand Down Expand Up @@ -86,7 +120,6 @@ jobs:
done
cd -
done
cd -

test-mac-serial:

Expand Down Expand Up @@ -138,4 +171,3 @@ jobs:
cd test
python ThermoIntegration_test.py
./run_test_jan2010_integration_test.sh python
cd -
7 changes: 6 additions & 1 deletion Dockerfiles/install-xios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ cat <<EOF >arch/arch-GCC_LINUX.fcm
%MAKE gmake
EOF

./make_xios --arch GCC_LINUX --job 8 --full --debug
# Hack to remove a line that stops calendar attributes being accessed after the
# context definition has been closed.
# This should be fixed when we update to XIOS3 (see #761).
sed -i "s/if (hasClient) CleanTree/\/\/if (hasClient) CleanTree/" src/node/context.cpp

./make_xios --arch GCC_LINUX --job 8 --debug
rm -r /xios/obj /xios/bin/generic_testcase.exe /xios/src /xios/tools \
/xios/inputs /xios/doc /xios/arch /xios/xios_test_suite /xios/flags \
/xios/generic_testcase /xios/ppsrc /xios/done
9 changes: 9 additions & 0 deletions core/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Sources for the main neXtSIM model

if(ENABLE_XIOS)
set(XIOS_INCLUDE_LIST
"${xios_INCLUDES}"
"${xios_EXTERNS}/blitz/"
"${xios_EXTERNS}/rapidxml/include"
)
set(NextsimIncludeDirs "${NextsimIncludeDirs}" "${XIOS_INCLUDE_LIST}")
endif()

set(BaseSources
"Logged.cpp"
"ModelConfig.cpp"
Expand Down
26 changes: 25 additions & 1 deletion core/src/ModelMetadata.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @file ModelMetadata.cpp
*
* @date 21 August 2024
* @date 10 Dec 2024
* @author Tim Spain <[email protected]>
*/

Expand Down Expand Up @@ -103,4 +103,28 @@ ModelState& ModelMetadata::affixCoordinates(ModelState& state) const
}
return state;
}

void ModelMetadata::setTime(const TimePoint& time)
{
m_time = time;
#ifdef USE_XIOS
if (!xiosHandler->isInitialized()) {
throw std::runtime_error("ModelMetadata: Xios handler has not been initialized");
}
xiosHandler->setCalendarStep(0);
xiosHandler->setCalendarStart(time);
#endif
}

void ModelMetadata::incrementTime(const Duration& step)
{
m_time += step;
#ifdef USE_XIOS
if (!xiosHandler->isInitialized()) {
throw std::runtime_error("ModelMetadata: Xios handler has not been initialized");
}
xiosHandler->incrementCalendar();
#endif
}

} /* namespace Nextsim */
4 changes: 2 additions & 2 deletions core/src/ParaGridIO.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @file ParaGridIO.cpp
*
* @date Oct 24, 2022
* @date 09 Dec 2024
* @author Tim Spain <[email protected]>
*/

Expand Down Expand Up @@ -227,7 +227,7 @@ ModelState ParaGridIO::readForcingTimeStatic(
std::vector<double> timeVec(timeDim.getSize());
timeVar.getVar(timeVec.data());
// Get the index of the largest TimePoint less than the target.
targetTIndex = std::find_if(begin(timeVec), end(timeVec), [time](double t) {
targetTIndex = std::find_if(std::begin(timeVec), std::end(timeVec), [time](double t) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required to avoid compile errors about begin and end being overloaded and it not being clear which version to use.

return (TimePoint() + Duration(t)) > time;
}) - timeVec.begin();
// Rather than the first that is greater than, get the last that is less
Expand Down
22 changes: 13 additions & 9 deletions core/src/Xios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Xios.cpp
* @author Tom Meltzer <[email protected]>
* @author Joe Wallwork <[email protected]>
* @date 09 Dec 2024
* @date 10 Dec 2024
* @brief XIOS interface implementation
* @details
*
Expand Down Expand Up @@ -37,7 +37,6 @@ static const std::map<int, std::string> keyMap = { { Xios::ENABLED_KEY, "xios.en
//! Enable XIOS in the 'config'
void enableXios()
{
Configurator::clearStreams();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is important when you set up XIOS after you've already configured other parts of nextSIM-DG.

std::stringstream config;
config << "[xios]" << std::endl << "enable = true" << std::endl;
std::unique_ptr<std::istream> pcstream(new std::stringstream(config.str()));
Expand Down Expand Up @@ -271,6 +270,18 @@ void Xios::setCalendarTimestep(const Duration timestep)
cxios_update_calendar_timestep(clientCalendar);
}

/*!
* Update XIOS calendar iteration/step number to some value
*
* @param Step number to update to
*/
void Xios::setCalendarStep(const int stepNumber) { cxios_update_calendar(stepNumber); }

/*!
* Increment XIOS' calendar iteration/step number by one.
*/
void Xios::incrementCalendar() { setCalendarStep(getCalendarStep() + 1); }

/*!
* Get calendar type
*
Expand Down Expand Up @@ -347,13 +358,6 @@ std::string Xios::getCurrentDate(const bool isoFormat)
return convertXiosDatetimeToString(xiosDate, isoFormat);
}

/*!
* Update XIOS calendar iteration/step number
*
* @param current step number
*/
void Xios::updateCalendar(const int stepNumber) { cxios_update_calendar(stepNumber); }

/*!
* Get the axis_definition group
*
Expand Down
21 changes: 18 additions & 3 deletions core/src/include/ModelMetadata.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @file ModelMetadata.hpp
*
* @date Jun 29, 2022
* @date 09 Dec 2024
* @author Tim Spain <[email protected]>
*/

Expand All @@ -12,6 +12,9 @@
#include "include/ModelArray.hpp"
#include "include/ModelState.hpp"
#include "include/Time.hpp"
#ifdef USE_XIOS
#include "include/Xios.hpp"
#endif

#include <string>

Expand Down Expand Up @@ -47,13 +50,13 @@ class ModelMetadata {
*
* @param time TimePoint instance encoding the current time.
*/
inline void setTime(const TimePoint& time) { m_time = time; }
void setTime(const TimePoint& time);
/*!
* @brief Increments the model time metadata value.
*
* @param step Duration of the time increment to add.
*/
inline void incrementTime(const Duration& step) { m_time += step; }
void incrementTime(const Duration& step);
//! Returns the current model time.
inline const TimePoint& time() const { return m_time; }

Expand Down Expand Up @@ -99,6 +102,15 @@ class ModelMetadata {
int localCornerX, localCornerY, localExtentX, localExtentY, globalExtentX, globalExtentY;
#endif

#ifdef USE_XIOS
/*
* @brief Set pointer to Xios handler instance.
*
* @param xiosPtr Pointer to set
*/
inline void setXiosHandler(Xios* xiosPtr) { xiosHandler = xiosPtr; }
#endif

private:
TimePoint m_time;
ConfigMap m_config;
Expand All @@ -117,6 +129,9 @@ class ModelMetadata {
#ifdef USE_MPI
const std::string bboxName = "bounding_boxes";
#endif
#ifdef USE_XIOS
Xios* xiosHandler = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ModelMetadata the best place for the XIOS handler? It doesn't (instinctively) feel like metadata data to me. Perhaps implementing the infrastructure necessary to return an Xios singleton.

Also, wherever it ends up, might a smarter pointer be better than a raw pointer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I currently have it set up in #751 is that multiple classes (ParaGridIO and ModelMetadata) have pointers to it. A singleton would make sense in general, yes. It might make test files containing multiple tests that use XIOS a little trickier to set up, but that's not really the important thing. I'll look into how to implement it. Also good point on using smart pointers.

#endif
};

} /* namespace Nextsim */
Expand Down
5 changes: 3 additions & 2 deletions core/src/include/Xios.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Xios.hpp
* @author Tom Meltzer <[email protected]>
* @author Joe Wallwork <[email protected]>
* @date 04 Dec 2024
* @date 10 Dec 2024
* @brief XIOS interface header
* @details
*
Expand Down Expand Up @@ -55,13 +55,14 @@ class Xios : public Configured<Xios> {
void setCalendarOrigin(const TimePoint origin);
void setCalendarStart(const TimePoint start);
void setCalendarTimestep(const Duration timestep);
void setCalendarStep(const int stepNumber);
void incrementCalendar();
std::string getCalendarType();
TimePoint getCalendarOrigin();
TimePoint getCalendarStart();
Duration getCalendarTimestep();
int getCalendarStep();
std::string getCurrentDate(const bool isoFormat = true);
void updateCalendar(const int stepNumber);

/* Axis */
void createAxis(const std::string axisId);
Expand Down
Loading
Loading