-
Notifications
You must be signed in to change notification settings - Fork 51
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
Initial error handling #131
base: main
Are you sure you want to change the base?
Conversation
* Make functions in point_to_point.rs return Result * Add error.rs + ErrorKind enum for representing MPI error classes * Set the errhandler for MPI_COMM_WORLD to ERRORS_RETURN by default
de16900
to
8b78725
Compare
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 good in general; thanks! I think the razor is to ask whether a given function can fail for a reason other than programmer error. So .world()
and .this_process()
don't have errors. Certainly anything collective should return Result
because it can fail due to network partition or disruption of other ranks; indeed these are errors some applications would want to actually recover from versus mere clean-up-and-exit.
Rust std has decided that allocation doesn't return Result
(just panics). I can't envision a scenario in which rsmpi would be used in nostd so I think mere allocation need not return Result
. So this raises the question of whether the likes of .immediate_send()
should return Result
. Perhaps not if it can't fail (when given valid inputs) except by something akin to failed allocation. (When we can't enforce "valid inputs" via the type system, we can panic if they are invalid, just like array indexing with an out of range index.)
I'd be curious to hear your and @hppritcha opinions about when to return Result
and when to panic.
pub(crate) fn error_kind(res: c_int) -> ErrorKind { | ||
match ErrorKind::from_raw(res) { | ||
Some(kind) => kind, | ||
None => panic!("Could not find matching ErrorKind for returncode '{}'", res), |
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.
Should we be calling MPI_Error_string()
to be more descriptive?
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 that would be nice to do
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.
Yeah that might be more useful here. Do you think this should be encapsulated in ErrorKind
? Maybe it doesn't need to be an enum.
unsafe { SystemCommunicator::from_raw_unchecked(ffi::RSMPI_COMM_WORLD) } | ||
pub fn world() -> Result<SystemCommunicator, ErrorKind> { | ||
unsafe { | ||
let res = ffi::MPI_Comm_set_errhandler(ffi::RSMPI_COMM_WORLD, ffi::RSMPI_ERRORS_RETURN); |
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 don't think world()
should imply this change of error handling behavior, and I don't think world()
needs to return a Result
.
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. Do you think we should just panic here on an error with MPI_Comm_set_errhandler
? Or maybe I should move this call into Universe::initialize()
.
Thanks for looking at this. For It seems that MPI, when set to ERRORS_RETURN, will even return argument errors such as I'm thinking that we should probably panic on some of these MPI errors, while returning the others. For example errors that might indicate that RSMPI code is doing something wrong or errors like |
This is currently a WIP, but I wanted to open it now to get feedback since these would be breaking changes for any code that relies on rsmpi. I have not attempted anything yet with the collective code, but I've made all the code in
point_to_point.rs
returnResult
, indicating the MPI error class on failure. The examples should be updated as well.