Skip to content

Commit

Permalink
now pio_init_logging() checks are returns error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jun 13, 2019
1 parent 2af631f commit a2897a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/clib/pio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ extern "C" {
int pioc_change_def(int ncid, int is_enddef);

/* Initialize and finalize logging. */
void pio_init_logging(void);
int pio_init_logging(void);
void pio_finalize_logging(void );

/* Write a netCDF decomp file. */
Expand Down
6 changes: 4 additions & 2 deletions src/clib/pioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ PIOc_Init_Intracomm(MPI_Comm comp_comm, int num_iotasks, int stride, int base,
int ret; /* Return code for function calls. */

/* Turn on the logging system. */
pio_init_logging();
if ((ret = pio_init_logging()))
return pio_err(NULL, NULL, ret, __FILE__, __LINE__);

/* Find the number of computation tasks. */
if ((mpierr = MPI_Comm_size(comp_comm, &num_comptasks)))
Expand Down Expand Up @@ -1420,7 +1421,8 @@ PIOc_init_async(MPI_Comm world, int num_io_procs, int *io_proc_list,
my_proc_list = (int**) malloc(component_count * sizeof(int*));

/* Turn on the logging system for PIO. */
pio_init_logging();
if ((ret = pio_init_logging()))
return pio_err(NULL, NULL, ret, __FILE__, __LINE__);
LOG((1, "PIOc_init_async num_io_procs = %d component_count = %d", num_io_procs,
component_count));

Expand Down
15 changes: 12 additions & 3 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,28 @@ PIOc_set_log_level(int level)
/**
* Initialize logging. Open log file, if not opened yet, or increment
* ref count if already open.
*
* @author Jayesh Krishna
*/
void
int
pio_init_logging(void)
{
int mpierr;
int ret = PIO_NOERR;

#if PIO_ENABLE_LOGGING
char log_filename[PIO_MAX_NAME];

if (!LOG_FILE)
{
/* Create a filename with the rank in it. */
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if ((mpierr = MPI_Comm_rank(MPI_COMM_WORLD, &my_rank)))
return check_mpi(NULL, NULL, mpierr, __FILE__, __LINE__);
sprintf(log_filename, "pio_log_%d.log", my_rank);

/* Open a file for this rank to log messages. */
LOG_FILE = fopen(log_filename, "w");
if (!(LOG_FILE = fopen(log_filename, "w")))
return PIO_EINVAL;

pio_log_ref_cnt = 1;
}
Expand All @@ -189,6 +196,8 @@ pio_init_logging(void)
pio_log_ref_cnt++;
}
#endif /* PIO_ENABLE_LOGGING */

return ret;
}

/**
Expand Down

0 comments on commit a2897a0

Please sign in to comment.