Skip to content

Commit

Permalink
Merge pull request #76 from NCAR/revert-75-ejh_cleanup6
Browse files Browse the repository at this point in the history
Revert "Ejh cleanup6"
  • Loading branch information
edhartnett authored Jun 14, 2016
2 parents 2559cf4 + 1b7ffb6 commit 046fc26
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 72 deletions.
117 changes: 47 additions & 70 deletions src/clib/pio_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <pio.h>
#include <pio_internal.h>

/* Open an existing file using pio.
/* Open an existing file using pio
* @public
* @ingroup PIO_openfile
*
Expand Down Expand Up @@ -31,7 +31,10 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype,

/* Get the IO system info from the iosysid. */
if (!(ios = pio_get_iosystem_from_id(iosysid)))
{
LOG((0, "PIOc_openfile got bad iosysid %d",iosysid));
return PIO_EBADID;
}

/* Allocate space for the file info. */
if (!(file = (file_desc_t *) malloc(sizeof(*file))))
Expand Down Expand Up @@ -202,6 +205,7 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype,
* @param filename : The filename to open
* @param mode : The netcdf mode for the open operation
*/

int PIOc_createfile(const int iosysid, int *ncidp, int *iotype,
const char filename[], const int mode)
{
Expand Down Expand Up @@ -448,17 +452,14 @@ int PIOc_closefile(int ncid)
* @param iosysid : a pio system handle
* @param filename : a filename
*/
int PIOc_deletefile(const int iosysid, const char *filename)
int PIOc_deletefile(const int iosysid, const char filename[])
{
iosystem_desc_t *ios; /** Pointer to io system information. */
file_desc_t *file; /** Pointer to file information. */
int ierr = PIO_NOERR; /** Return code from function calls. */
int deleted = 0; /** Becomes true when file is deleted. */
int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */

/* Filename must be provided. */
if (!filename || strlen(filename) > NC_MAX_NAME)
return PIO_EINVAL;
int msg = PIO_MSG_DELETE_FILE;
size_t len;

/* Get the IO system info from the id. */
if (!(ios = pio_get_iosystem_from_id(iosysid)))
Expand All @@ -469,49 +470,35 @@ int PIOc_deletefile(const int iosysid, const char *filename)
{
if (!ios->ioproc)
{
int msg = PIO_MSG_DELETE_FILE;
size_t len = strlen(filename);

if(ios->compmaster)
if(ios->comp_rank==0)
mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm);

len = strlen(filename);
if (!mpierr)
mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm);
if (!mpierr)
mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm);
}

/* Handle MPI errors. */
if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->comproot, ios->my_comm)))
return check_mpi(file, mpierr2, __FILE__, __LINE__);
if (mpierr)
return check_mpi(file, mpierr, __FILE__, __LINE__);
}

/* If this is an IO task, then call the netCDF function. The
* barriers are needed to assure that no task is trying to operate
* on the file while it is being deleted. */
if (ios->ioproc)
{
if(ios->ioproc){
MPI_Barrier(ios->io_comm);
#ifdef _NETCDF
if (ios->iomaster)
if(ios->io_rank==0)
ierr = nc_delete(filename);
deleted++;
#else
#ifdef _PNETCDF
if (!deleted)
ierr = ncmpi_delete(filename, ios->info);
ierr = ncmpi_delete(filename, ios->info);
#endif
#endif
MPI_Barrier(ios->io_comm);
}

/* Broadcast and check the return code. */
if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm)))
return check_mpi(file, mpierr, __FILE__, __LINE__);
if (ierr)
return check_netcdf(file, ierr, __FILE__, __LINE__);
// Special case - always broadcast the return from the
MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm);

return ierr;
}
Expand Down Expand Up @@ -544,70 +531,60 @@ int PIOc_sync(int ncid)
{
int msg = PIO_MSG_SYNC;

if (ios->compmaster)
if(ios->comp_rank == 0)
mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm);

if (!mpierr)
mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster,
ios->intercomm);
if (mpierr)
return check_mpi(file, mpierr, __FILE__, __LINE__);

mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm);
}

/* Handle MPI errors. */
/* if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->comproot, ios->my_comm))) */
/* return check_mpi(file, mpierr2, __FILE__, __LINE__); */
/* if (mpierr) */
/* return check_mpi(file, mpierr, __FILE__, __LINE__); */
}

if (file->mode & PIO_WRITE)
{
// cn_buffer_report( *ios, true);
wmb = &file->buffer;
while(wmb)
{
wmb = &(file->buffer);
while(wmb != NULL){
// printf("%s %d %d %d\n",__FILE__,__LINE__,wmb->ioid, wmb->validvars);
if (wmb->validvars > 0)
{
if(wmb->validvars>0){
flush_buffer(ncid, wmb, true);
}
twmb = wmb;
wmb = wmb->next;
if (twmb == &file->buffer)
{
twmb->ioid = -1;
twmb->next = NULL;
}
else
{
if(twmb == &(file->buffer)){
twmb->ioid=-1;
twmb->next=NULL;
}else{
brel(twmb);
}
}
flush_output_buffer(file, true, 0);

/* If this is an IO task, then call the netCDF function. */
if (ios->ioproc)
{
#ifdef _PNETCDF
if (file->iotype == PIO_IOTYPE_PNETCDF)
ierr = ncmpi_sync(file->fh);
#endif /* _PNETCDF */
if(ios->ioproc){
switch(file->iotype){
#ifdef _NETCDF
if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io)
ierr = nc_sync(file->fh);
#endif /* _NETCDF */
#ifdef _NETCDF4
case PIO_IOTYPE_NETCDF4P:
ierr = nc_sync(file->fh);;
break;
case PIO_IOTYPE_NETCDF4C:
#endif
case PIO_IOTYPE_NETCDF:
if(ios->io_rank==0){
ierr = nc_sync(file->fh);;
}
break;
#endif
#ifdef _PNETCDF
case PIO_IOTYPE_PNETCDF:
ierr = ncmpi_sync(file->fh);;
break;
#endif
default:
ierr = iotype_error(file->iotype,__FILE__,__LINE__);
}
}

ierr = check_netcdf(file, ierr, __FILE__,__LINE__);
}

/* Broadcast and check the return code. */
/* if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) */
/* return check_mpi(file, mpierr, __FILE__, __LINE__); */
/* if (ierr) */
/* return check_netcdf(file, ierr, __FILE__, __LINE__); */

return ierr;
}

4 changes: 2 additions & 2 deletions tests/unit/test_intercomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ main(int argc, char **argv)
ERR(ret);

/* Now delete the file. */
if ((ret = PIOc_deletefile(iosysid, filename[fmt])))
ERR(ret);
/* if ((ret = PIOc_deletefile(iosysid, filename[fmt]))) */
/* ERR(ret); */
/* if ((ret = PIOc_openfile(iosysid, &ncid, &format[fmt], filename[fmt], */
/* NC_NOWRITE)) != PIO_ENFILE) */
/* ERR(ERR_AWFUL); */
Expand Down

0 comments on commit 046fc26

Please sign in to comment.