Skip to content

Commit

Permalink
got inq_attname working with async
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed May 14, 2016
1 parent 16e3799 commit 2a250cf
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 58 deletions.
46 changes: 46 additions & 0 deletions src/clib/pio_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,49 @@ int inq_att_handler(iosystem_desc_t *ios)
return PIO_NOERR;
}

/** Handle attribute inquiry operations. This code only runs on IO
* tasks.
*
* @param ios pointer to the iosystem_desc_t.
* @param msg the message sent my the comp root task.
* @return PIO_NOERR for success, error code otherwise.
*/
int inq_attname_handler(iosystem_desc_t *ios)
{
int ncid;
int varid;
int attnum;
char name[NC_MAX_NAME + 1], *namep = NULL;
char name_present;
int mpierr;
int ret;

LOG((1, "inq_att_name_handler"));

/* Get the parameters for this function that the the comp master
* task is broadcasting. */
if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm)))
return PIO_EIO;
if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm)))
return PIO_EIO;
if ((mpierr = MPI_Bcast(&attnum, 1, MPI_INT, ios->compmaster, ios->intercomm)))
return PIO_EIO;
if ((mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, 0, ios->intercomm)))
return PIO_EIO;
LOG((2, "inq_attname_handler got ncid = %d varid = %d attnum = %d name_present = %d",
ncid, varid, attnum, name_present));

/* Match NULLs in collective function call. */
if (name_present)
namep = name;

/* Call the function to learn about the attribute. */
if ((ret = PIOc_inq_attname(ncid, varid, attnum, namep)))
return ret;

return PIO_NOERR;
}

/** Handle attribute operations. This code only runs on IO tasks.
*
* @param ios pointer to the iosystem_desc_t.
Expand Down Expand Up @@ -1058,6 +1101,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys)
case PIO_MSG_INQ_ATT:
inq_att_handler(my_iosys);
break;
case PIO_MSG_INQ_ATTNAME:
inq_attname_handler(my_iosys);
break;
case PIO_MSG_INITDECOMP_DOF:
initdecomp_dof_handler(my_iosys);
break;
Expand Down
124 changes: 66 additions & 58 deletions src/clib/pio_nc_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,30 +885,18 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm);
}

/* If this is an IO task, then call the netCDF function. */
if (ios->ioproc)
{
switch (file->iotype)
{
#ifdef _NETCDF
#ifdef _NETCDF4
case PIO_IOTYPE_NETCDF4P:
ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);
break;
case PIO_IOTYPE_NETCDF4C:
#endif
case PIO_IOTYPE_NETCDF:
if (ios->io_rank == 0)
ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);
break;
#endif
#ifdef _PNETCDF
case PIO_IOTYPE_PNETCDF:
if (file->iotype == PIO_IOTYPE_PNETCDF)
ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp);
break;
#endif
default:
ierr = iotype_error(file->iotype,__FILE__,__LINE__);
}
#endif /* _PNETCDF */
#ifdef _NETCDF
if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io)
ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);
#endif /* _NETCDF */
LOG((2, "PIOc_inq netcdf call returned %d", ierr));
}

/* Handle MPI errors. */
Expand Down Expand Up @@ -963,58 +951,78 @@ int PIOc_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep)
* @param attnum the attribute ID.
* @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling
*/
int PIOc_inq_attname (int ncid, int varid, int attnum, char *name)
int PIOc_inq_attname(int ncid, int varid, int attnum, char *name)
{
int ierr = PIO_NOERR;
int msg = PIO_MSG_INQ_ATTNAME;
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 mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */
iosystem_desc_t *ios;
file_desc_t *file;

LOG((1, "PIOc_inq_attname ncid = %d varid = %d attnum = %d", ncid, varid,
attnum));

/* Find the info about this file. */
if (!(file = pio_get_file_from_id(ncid)))
return PIO_EBADID;
ios = file->iosystem;

if(ios->async_interface && ! ios->ioproc){
if(ios->compmaster)
mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm);
mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm);
/* If async is in use, and this is not an IO task, bcast the parameters. */
if (ios->async_interface)
{
if (!ios->ioproc)
{
int msg = PIO_MSG_INQ_ATTNAME;
char name_present = name ? true : false;

if(ios->compmaster)
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)
mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm);
if (!mpierr)
mpierr = MPI_Bcast(&attnum, 1, MPI_INT, ios->compmaster, ios->intercomm);
if (!mpierr)
mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm);
}

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

if(ios->ioproc){
switch(file->iotype){
#ifdef _NETCDF
#ifdef _NETCDF4
case PIO_IOTYPE_NETCDF4P:
ierr = nc_inq_attname(file->fh, varid, attnum, name);;
break;
case PIO_IOTYPE_NETCDF4C:
#endif
case PIO_IOTYPE_NETCDF:
if(ios->io_rank==0){
ierr = nc_inq_attname(file->fh, varid, attnum, name);;
}
break;
#endif
/* If this is an IO task, then call the netCDF function. */
if (ios->ioproc)
{
#ifdef _PNETCDF
case PIO_IOTYPE_PNETCDF:
if (file->iotype == PIO_IOTYPE_PNETCDF)
ierr = ncmpi_inq_attname(file->fh, varid, attnum, name);;
break;
#endif
default:
ierr = iotype_error(file->iotype,__FILE__,__LINE__);
}
#endif /* _PNETCDF */
#ifdef _NETCDF
if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io)
ierr = nc_inq_attname(file->fh, varid, attnum, name);;
#endif /* _NETCDF */
LOG((2, "PIOc_inq_attname netcdf call returned %d", ierr));
}

/* Broadcast and check the return code. */
if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm)))
return PIO_EIO;
check_netcdf(file, ierr, __FILE__, __LINE__);
if (name)
{
int slen;
if(ios->iomaster)
slen = (int) strlen(name);
mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm);
mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm);
}

/* Broadcast results to all tasks. Ignore NULL parameters. */
if (!ierr)
if (name)
{
int namelen = strlen(name);
if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->ioroot, ios->my_comm)))
check_mpi(file, mpierr, __FILE__, __LINE__);
if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->ioroot,
ios->my_comm)))
check_mpi(file, mpierr, __FILE__, __LINE__);
}

return ierr;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_intercomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose)
/* Check out the global attributes. */
nc_type atttype;
PIO_Offset attlen;
char myattname[NC_MAX_NAME + 1];
if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen)))
ERR(ret);
if (atttype != NC_INT || attlen != 1)
Expand All @@ -191,6 +192,10 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose)
ERR(ret);
if (attlen != 1)
ERR(ERR_WRONG);
if ((ret = PIOc_inq_attname(ncid, NC_GLOBAL, 0, myattname)))
ERR(ret);
if (strcmp(ATT_NAME, myattname))
ERR(ERR_WRONG);
if ((ret = PIOc_get_att_int(ncid, NC_GLOBAL, ATT_NAME, &att_data)))
ERR(ret);
if (verbose)
Expand Down

0 comments on commit 2a250cf

Please sign in to comment.