Skip to content

Commit

Permalink
move error macros to pio_error.h
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jun 24, 2019
1 parent bdfbb41 commit 2695b4b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/clib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ lib_LTLIBRARIES = libpio.la
# for information regarding incrementing `-version-info`.
libpio_la_LDFLAGS = -version-info 2:0:1

# The header file.
# The library header file will be installed in include dir.
include_HEADERS = pio.h

# The library soure files.
libpio_la_SOURCES = bget.c pioc_sc.c pio_darray.c pio_file.c \
pio_getput_int.c pio_msg.c pio_nc.c pio_rearrange.c pioc.c \
pioc_support.c pio_darray_int.c pio_get_nc.c pio_lists.c pio_nc4.c \
pio_put_nc.c pio_spmd.c pio_get_vard.c pio_put_vard.c pio_internal.h \
bget.h uthash.h
bget.h uthash.h pio_error.h

EXTRA_DIST = CMakeLists.txt
31 changes: 31 additions & 0 deletions src/clib/pio_error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @file
* Macros to handle errors in tests or libray code.
* @author Ed Hartnett
* @date 2019
*
* @see https://github.com/NCAR/ParallelIO
*/

#ifndef __PIO_ERROR__
#define __PIO_ERROR__

#include <config.h>
#include <pio.h>

/** Handle non-MPI errors by finalizing the MPI library and goto
* exit. Finalize and goto exit. */
#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 finalizing the MPI library and exiting
* with an exit code. Finalize and return. */
#define ERR(e) do { \
fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \
MPI_Finalize(); \
return e; \
} while (0)

#endif /* __PIO_ERROR__ */
1 change: 1 addition & 0 deletions src/clib/pio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <config.h>
#include <pio.h>
#include <pio_error.h>
#include <bget.h>
#include <limits.h>
#include <math.h>
Expand Down
17 changes: 1 addition & 16 deletions tests/cunit/pio_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#ifndef _PIO_TESTS_H
#define _PIO_TESTS_H

#include <pio_error.h>
#include <unistd.h> /* Include this for the sleep function. */
#include <assert.h>

Expand Down Expand Up @@ -99,21 +99,6 @@ void test_stop_mpe_log(int state, const char *msg);
goto exit; \
} while (0)

/** Handle non-MPI errors by finalizing the MPI library and exiting
* with an exit code. Finalize and return. */
#define ERR(e) do { \
fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \
MPI_Finalize(); \
return e; \
} while (0)

/** Handle non-MPI errors by finalizing the MPI library and goto
* exit. Finalize and goto exit. */
#define BAIL(e) do { \
fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \
goto exit; \
} while (0)

/** Global err buffer for MPI. When there is an MPI error, this buffer
* is used to store the error message that is associated with the MPI
* error. */
Expand Down

0 comments on commit 2695b4b

Please sign in to comment.