Exit codes falsely imply failure

Report any suspected bugs and unexpected behavior here
Post Reply
drewejohnson
Posts: 57
Joined: Thu Oct 20, 2016 4:25 pm
Security question 1: No
Security question 2: 84

Exit codes falsely imply failure

Post by drewejohnson » Mon Oct 21, 2019 4:29 pm

I've noticed that Serpent will exit with non-zero exit codes for some of the sub-commands even if nothing fails. For example

Code: Select all

sss2 -plot input
returns an exit code of 255. For most shells, this is interpreted as "something has failed" and restricts some chained commands. When building complex geometries, I like to call an image viewer right after generating the plots with

Code: Select all

sss2 -plot input && feh input_geom0.png
but since Serpent "failed" in the eyes of the shell, the image is not opened. I have also confirmed this happens for the -comp, -elem, -version, -disperse, and -checkstl commands.

The smaller consequence of this is the above inconveniences. The larger consequence could occur if people are running some of these commands entirely from a script configured to exit at the first failure (set -e), the job will terminate even if nothing has failed.

Running 2.1.31

User avatar
Jaakko Leppänen
Site Admin
Posts: 2445
Joined: Thu Mar 18, 2010 10:43 pm
Security question 2: 0
Location: Espoo, Finland
Contact:

Re: Exit codes falsely imply failure

Post by Jaakko Leppänen » Mon Oct 21, 2019 5:05 pm

If I remember correctly, I started using exit(-1) to terminate the calculation because in MPI mode exit(0) left the parallel tasks running. Most of these calls are probably outside the MPI parallel part anyway, so they could be easily replaced with exit(0).

But do you know if there is a better way to terminate the calculation in MPI mode that wouldn't be interpreted as an error? There's probably only a handful of routines that actually should exit with an error code.
- Jaakko

drewejohnson
Posts: 57
Joined: Thu Oct 20, 2016 4:25 pm
Security question 1: No
Security question 2: 84

Re: Exit codes falsely imply failure

Post by drewejohnson » Wed Oct 23, 2019 10:13 pm

I think the only subcommand [that I tested at least] that could be running in parallel would be the disperse command. Would it be a safe assumption for some of the smaller subcommands [plot, quickplot, comp, etc.] that these are not running in parallel? If that is the case, I think exit(0) would be sufficient.

As for terminating MPI runs, I'm not sure I understand the question. I think MPI_Finalize and MPI_Abort might be useful. One solution might be to have a wrapped Exit(int status) function called from Die, Error, and some of the subcommands to handle terminating MPI. It looks like finalizempi.c was intended to do that, as it calls MPI_Finalize.

User avatar
Jaakko Leppänen
Site Admin
Posts: 2445
Joined: Thu Mar 18, 2010 10:43 pm
Security question 2: 0
Location: Espoo, Finland
Contact:

Re: Exit codes falsely imply failure

Post by Jaakko Leppänen » Thu Oct 24, 2019 1:02 pm

Yes, I think replacing exit(-1) with exit(0) should be OK for most cases. I'll add some proper finalization routines in the next version.
- Jaakko

Post Reply