I know I can write a bind(C) function that just takes in my error message and calls error stop, and use that as a way to call error stop from a C function in a mixed fortran/C program, but is there a more direct way? I didn’t see anything about error stop in ISO_Fortran_binding.h so I’m assuming there is no more direct/standardized way, but I thought I would at least ask.
Is the main program C or Fortran? You should use the exit method suitable to the language used to create the main program.
The main program is Fortran in this case. I’m currently using abort() from C where needed. It works, I just feel like it would be more “elegant” to use error stop.
Since “error stop” is a statement and not a function/subroutine, I do not think you can do this in another way than calling a wrapper routine.
(The problem is in a way similar to C macro that masquerade as functions - on the Fortran side you cannot call them directly.)
The safer option will be to have your Fortran main include an “error handler” procedure (say fort_abort
) and your C side of code invoke that instead of C abort()
.
Unfortunately nothing more “elegant” than this is on tap given how primitive the `Termination of Execution" section is in the Fortran standard for application needs going back to 1990 even, let alone year 2021.
ERROR STOP is to explicitly initiate error termination with coarray programms and thus, to stop execution of a coarray app on all images as soon as possible.
Advanced coarray programming, on the other hand, should rather seek to avoid error termination (by using stat= specifiers).