Skip to content

Initialize the mpi_errcode argument to MPI_Abort in MPAS's log_abort routine#1418

Open
mgduda wants to merge 3 commits intoMPAS-Dev:developfrom
mgduda:framework/initialize_abort_code
Open

Initialize the mpi_errcode argument to MPI_Abort in MPAS's log_abort routine#1418
mgduda wants to merge 3 commits intoMPAS-Dev:developfrom
mgduda:framework/initialize_abort_code

Conversation

@mgduda
Copy link
Contributor

@mgduda mgduda commented Mar 11, 2026

This PR initializes the mpi_errcode argument to MPI_Abort in several MPAS routines.

The mpi_errcode variable in MPAS's log_abort, mpas_dmpar_global_abort, and mpas_dmpar_abort routines that is passed as the errorcode input argument to MPI_Abort was previously uninitialized, leading to the potential use of uninitialized memory in MPI_Abort (or in routines called by MPI_Abort).

In practice, the uninitialized value in mpi_errcode caused no problems, though when running MPAS with valgrind's memcheck tool, it could lead to the generation of (possibly numerous) uninitialized memory errors in the log from memcheck.

Note that although this PR initializes the mpi_errcode variable with a value of 6, corresponding to the POSIX SIGABRT signal number, the specific value is probably not important.

Copy link
Contributor

@islas islas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use a value of 6 (SIGABRT) for mpi_errcode? It could allow for catching and cleaning up elsewhere (e.g. in a coupled situation) which may be a good or bad thing.. Same for potentially creating core dumps which most people may not find useful. All assuming the MPI implementation utilizes and forwards the errcode passed in.

SIGKILL is the most straight-forward and simplest.

Just some thoughts.

@mgduda
Copy link
Contributor Author

mgduda commented Mar 12, 2026

Sure, we can use SIGABRT. I'm not actually sure that MPI_Abort uses the errcode value to send any signals, and most likely the value provided is just used as the exit code for the process, so in that sense any non-zero value should do. But, since we are aborting, we might as well use an exit code that corresponds to SIGABRT.

I'll push an update shortly.

@mgduda
Copy link
Contributor Author

mgduda commented Mar 12, 2026

Actually, I found a couple of other places in MPAS where we call MPI_Abort without intializing errcode. In practice, I think it would be rare that we'd invoke MPI_Abort from these other places, but I'll address them with an update to this PR just to avoid future issues.

mgduda added 3 commits March 12, 2026 15:50
…routine

The mpi_errcode variable in log_abort that is passed as the errorcode input
argument to MPI_Abort was previously uninitialized, leading to the potential use
of uninitialized memory in MPI_Abort (or in routines called by MPI_Abort).

In practice, the uninitialized value in mpi_errcode caused no problems, though
when running MPAS with valgrind's memcheck tool, it could lead to the generation
of (possibly numerous) uninitialized memory errors in the log from memcheck.

This commit initializes mpi_errcode with a value of 6, corresponding to the
POSIX SIGABRT signal number, though the specific value is probably not
important.
…_abort

The mpi_errcode variable in mpas_dmpar_global_abort that is passed as the
errorcode input argument to MPI_Abort was previously uninitialized, leading to
the potential use of uninitialized memory in MPI_Abort (or in routines called by
MPI_Abort).

In practice, the uninitialized value in mpi_errcode caused no problems, though
when running MPAS with valgrind's memcheck tool, it could lead to the generation
of uninitialized memory errors in the log from memcheck.

This commit initializes mpi_errcode with a value of 6, corresponding to the
POSIX SIGABRT signal number, though the specific value is probably not
important.
The mpi_errcode variable in mpas_dmpar_abort that is passed as the errorcode
input argument to MPI_Abort was previously uninitialized, leading to the
potential use of uninitialized memory in MPI_Abort (or in routines called by
MPI_Abort).

In practice, the uninitialized value in mpi_errcode caused no problems, though
when running MPAS with valgrind's memcheck tool, it could lead to the generation
of uninitialized memory errors in the log from memcheck.

This commit initializes mpi_errcode with a value of 6, corresponding to the
POSIX SIGABRT signal number, though the specific value is probably not
important.
@mgduda mgduda force-pushed the framework/initialize_abort_code branch from f84999b to 97680bd Compare March 12, 2026 22:07
@mgduda mgduda requested a review from islas March 12, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants