Skip to content

Commit

Permalink
using new EXIT macro for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jun 24, 2019
1 parent 1886bc8 commit d95813a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 17 additions & 2 deletions src/clib/pio_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,28 @@
#include <pio.h>

/**
* Handle non-MPI errors by printing error message and goto exit.
* Handle non-MPI errors by printing error message and goto exit. This
* is used in test code.
*/
#define BAIL(e) do { \
fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \
goto exit; \
} while (0)

/**
* Handle non-MPI errors by calling pio_err(), setting return code,
* and goto exit. This is used in library code.
*/
#define EXIT(ios, e) do { \
ret = pio_err(NULL, NULL, e, __FILE__, __LINE__); \
goto exit; \
} while (0)

/**
* Same as the EXIT macro, but uses NULL for iosystem.
*/
#define EXIT1(e) EXIT(NULL, e)

/**
* Handle non-MPI errors by finalizing the MPI library and exiting
* with an exit code.
Expand All @@ -35,7 +50,7 @@
* Handle MPI errors. This should only be used with MPI library
* function calls. Print error message, finalize MPI and return error
* code.
*/
*/
#define MPIERR(e) do { \
MPI_Error_string(e, err_buffer, &resultlen); \
fprintf(stderr, "MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \
Expand Down
8 changes: 5 additions & 3 deletions src/clib/pio_rearrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ create_mpi_datatypes(MPI_Datatype mpitype, int msgcnt,
int *displace;

if (!(displace = malloc(sizeof(int) * len)))
return pio_err(NULL, NULL, PIO_ENOMEM, __FILE__, __LINE__);
EXIT1(PIO_ENOMEM);

LOG((3, "blocksize = %d i = %d mcount[%d] = %d len = %d", blocksize, i, i,
mcount[i], len));
Expand Down Expand Up @@ -412,12 +412,14 @@ create_mpi_datatypes(MPI_Datatype mpitype, int msgcnt,
}
}

LOG((3, "done with create_mpi_datatypes()"));

exit:
/* Free resources. */
if (lindex)
free(lindex);

LOG((3, "done with create_mpi_datatypes()"));
return PIO_NOERR;
return ret;
}

/**
Expand Down

0 comments on commit d95813a

Please sign in to comment.