bitmask
bitmask

Reputation: 34618

MPI_Finalize and assertions?

The MPI spec dictates to call MPI_Finalize in each thread before exiting. How does that work with runtime errors like assertions?

If I assert(cond) and cond evaluates to false, I have no chance to call MPI_Finalize because the normal program flow is changed. Am I supposed to catch SIGABRT, SIGSEGV and god-knows-what-else myself or does the MPI library somehow handle this itself?

Upvotes: 2

Views: 260

Answers (1)

jman
jman

Reputation: 11586

Write your own version of assert that calls MPI_Finalize after asserting.

#define MY_ASSERT(cond) do { \
    if (!cond) { \
        printf ("Assert (%s) failed at %s:%d\n", #cond, __FILE__, __LINE__); \
        MPI_finalize (); \
    } \
} while (0);

Note that in any case the other MPI processes in your job need to reach finalize too.

Upvotes: 1

Related Questions