-
Notifications
You must be signed in to change notification settings - Fork 123
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
Reservoir coupling: Implement time stepping #5620
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
4fd225c
Spawn slaves from master
hakonhagland bf59620
Do not specify program name twice
hakonhagland ba7c1d5
Open MPI does not support output redirection
hakonhagland 71d06c5
Pass parameter --slave=true to the slaves
hakonhagland e58ada1
Copy command line parameters from master
hakonhagland dffe282
Redirect slave standard output to a logfile
hakonhagland 097f951
Improved comments
hakonhagland ef62ea7
Add missing header files
hakonhagland 5dfbf50
Remove debug code
hakonhagland 864b55f
Rebased, and fixed command line parsing
hakonhagland d4855b0
Check if MPI is enabled
hakonhagland 7dfc250
Add missing header files
hakonhagland e47c898
Rebased, and fixed command line parsing
hakonhagland 09aa0be
Send slave start dates to master
hakonhagland 9ad5b8a
Rebased, and fixed command line parsing
hakonhagland 48856f9
Timestepping for reservoir coupling
hakonhagland 943d7fc
Enable start at any report step
hakonhagland 402bb85
Enable building without MPI
hakonhagland 5ae50c9
Simplify storage of communicators
hakonhagland 879fa72
Eliminate TimePoint class
hakonhagland 00be5ed
Conversion of std::time_t to double
hakonhagland afab98a
Clarify how the timestep is selected
hakonhagland 8da3c20
Do not check return values for MPI calls
hakonhagland 4074245
Fix typo in Equinor ASA
hakonhagland 89dc193
Mark GRUPSLAV and GRUPMAST as unsupported
hakonhagland 46406a2
Use Dune::MPITraits to determine MPI datatype
hakonhagland dfbafd9
Clearify that errhandler is a handle
hakonhagland 18a03da
Add doxygen comments
hakonhagland ac7e77b
Remove duplicate headers
hakonhagland f867f9a
Cleanup after rebase on master
hakonhagland 93eda52
Fix typo
hakonhagland b4192b0
Fix rebase problem
hakonhagland 18d35cb
Explain the timestepping
hakonhagland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
Copyright 2024 Equinor ASA | ||
|
||
This file is part of the Open Porous Media project (OPM). | ||
|
||
OPM is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
OPM is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with OPM. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <config.h> | ||
|
||
#include <opm/simulators/flow/ReservoirCoupling.hpp> | ||
#include <opm/simulators/utils/ParallelCommunication.hpp> | ||
#include <opm/common/OpmLog/OpmLog.hpp> | ||
|
||
#include <fmt/format.h> | ||
|
||
namespace Opm { | ||
namespace ReservoirCoupling { | ||
|
||
void custom_error_handler_(MPI_Comm* comm, int* err, const std::string &msg) | ||
{ | ||
// It can be useful to have a custom error handler for debugging purposes. | ||
// If not, MPI will use the default error handler which aborts the program, and | ||
// it can be difficult to determine exactly where the error occurred. With a custom | ||
// error handler you can at least set a breakpoint here to get a backtrace. | ||
int rank; | ||
MPI_Comm_rank(*comm, &rank); | ||
char err_string[MPI_MAX_ERROR_STRING]; | ||
int len; | ||
MPI_Error_string(*err, err_string, &len); | ||
const std::string error_msg = fmt::format( | ||
"Reservoir coupling MPI error handler {} rank {}: {}", msg, rank, err_string); | ||
// NOTE: The output to terminal vie stderr or stdout has been redirected to files for | ||
// the slaves, see Main.cpp. So the following output will not be visible in the terminal | ||
// if we are called from a slave process. | ||
// std::cerr << error_msg << std::endl; | ||
OpmLog::error(error_msg); // Output to log file, also shows the message on stdout for master. | ||
MPI_Abort(*comm, *err); | ||
} | ||
|
||
void custom_error_handler_slave_(MPI_Comm* comm, int* err, ...) | ||
{ | ||
custom_error_handler_(comm, err, "slave"); | ||
} | ||
|
||
void custom_error_handler_master_(MPI_Comm* comm, int* err, ...) | ||
{ | ||
custom_error_handler_(comm, err, "master"); | ||
} | ||
|
||
void setErrhandler(MPI_Comm comm, bool is_master) | ||
{ | ||
MPI_Errhandler errhandler; | ||
// NOTE: Lambdas with captures cannot be used as C function pointers, also | ||
// converting lambdas that use ellipsis "..." as last argument to a C function pointer | ||
// is not currently possible, so we need to use static functions instead. | ||
if (is_master) { | ||
MPI_Comm_create_errhandler(custom_error_handler_master_, &errhandler); | ||
} | ||
else { | ||
MPI_Comm_create_errhandler(custom_error_handler_slave_, &errhandler); | ||
} | ||
// NOTE: The errhandler is a handle (an integer) that is associated with the communicator | ||
// that is why we pass this by value below. And it is safe to free the errhandler after it has | ||
// been associated with the communicator. | ||
MPI_Comm_set_errhandler(comm, errhandler); | ||
// Mark the error handler for deletion. According to the documentation: "The error handler will | ||
// be deallocated after all the objects associated with it (communicator, window, or file) have | ||
// been deallocated." So the error handler will still be in effect until the communicator is | ||
// deallocated. | ||
MPI_Errhandler_free(&errhandler); | ||
} | ||
|
||
bool Seconds::compare_eq(double a, double b) | ||
{ | ||
// Are a and b equal? | ||
return std::abs(a - b) < std::max(abstol, reltol * std::max(std::abs(a), std::abs(b))); | ||
} | ||
|
||
bool Seconds::compare_gt_or_eq(double a, double b) | ||
{ | ||
// Is a greater than or equal to b? | ||
if (compare_eq(a, b)) { | ||
return true; | ||
} | ||
return a > b; | ||
} | ||
|
||
bool Seconds::compare_gt(double a, double b) | ||
{ | ||
// Is a greater than b? | ||
return !compare_eq(a, b) && a > b; | ||
} | ||
|
||
bool Seconds::compare_lt_or_eq(double a, double b) | ||
{ | ||
// Is a less than or equal to b? | ||
if (compare_eq(a, b)) { | ||
return true; | ||
} | ||
return a < b; | ||
} | ||
|
||
} // namespace ReservoirCoupling | ||
} // namespace Opm |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Was this needed to make serial compilation work? Could we hide this somewhere e.g. by providing methods doing nothing in this case are throwing? Might make the code clearer and cleaner.
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 this was done to make serial compilation work. I think it is clearer than using
#if HAVE_MPI
. Instead we use#ifdef RESERVOIR_COUPLING_ENABLED
which could make it clearer. I am not sure I understood your comment about hiding it? Did you mean moving it to a designated header file?