1+ """
2+ MPIError
3+
4+ Error thrown when an MPI function returns an error code. The `code` field contains the MPI error code.
5+ """
16struct MPIError <: Exception
27 code:: Cint
38end
9+ function Base. show (io:: IO , err:: MPIError )
10+ print (io, " MPIError(" , err. code, " ): " , error_string (err))
11+ end
12+
13+ """
14+ FeatureLevelError
15+
16+ Error thrown if a feature is not implemented in the current MPI backend.
17+ """
18+ struct FeatureLevelError <: Exception
19+ function_name:: Symbol
20+ min_version:: VersionNumber # minimal MPI version required for this feature to be available
21+ end
22+ function Base. show (io:: IO , err:: FeatureLevelError )
23+ print (io, " FeatureLevelError($(err. function_name) ): Minimum MPI version is $(err. min_version) " )
24+ end
25+
26+ macro mpichk (expr, min_version= nothing )
27+ if ! isnothing (min_version) && expr. args[2 ]. head == :tuple
28+ fn = expr. args[2 ]. args[1 ]. value
29+ if isnothing (dlsym (libmpi_handle, fn; throw_error= false ))
30+ return quote
31+ throw (FeatureLevelError ($ fn, $ min_version))
32+ end
33+ end
34+ end
435
5- macro mpichk (expr)
636 expr = macroexpand (@__MODULE__ , :(@mpicall ($ expr)))
737 # MPI_SUCCESS is defined to be 0
838 :((errcode = $ (esc (expr))) == 0 || throw (MPIError (errcode)))
939end
1040
11-
1241function error_string (err:: MPIError )
1342 len_ref = Ref {Cint} ()
1443 str_buf = Vector {UInt8} (undef, Consts. MPI_MAX_ERROR_STRING)
@@ -18,7 +47,3 @@ function error_string(err::MPIError)
1847 resize! (str_buf, len_ref[])
1948 return String (str_buf)
2049end
21-
22- function Base. show (io:: IO , err:: MPIError )
23- print (io, " MPIError(" , err. code, " ): " , error_string (err))
24- end
0 commit comments