Skip to content

Commit

Permalink
fixed rename_att function for async
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed May 17, 2016
1 parent 0ce232f commit a055a39
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
15 changes: 13 additions & 2 deletions src/clib/pio_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,31 +929,41 @@ int rename_att_handler(iosystem_desc_t *ios)
int ret;

LOG((1, "rename_att_handler"));
LOG((1, "rename_att_handler2"));

/* Get the parameters for this function that the he comp master
* task is broadcasting. */
LOG((1, "rename_att_handler about to get ncid"));
if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm)))
return PIO_EIO;
LOG((2, "rename_att_handler ncid = %d", ncid));
if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm)))
return PIO_EIO;
LOG((2, "rename_att_handler varid = %d", varid));
if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm)))
return PIO_EIO;
LOG((2, "rename_att_handler namelen = %d", namelen));
if (!(name = malloc((namelen + 1) * sizeof(char))))
return PIO_ENOMEM;
if ((mpierr = MPI_Bcast(name, namelen + 1, MPI_CHAR, 0, ios->intercomm)))
return PIO_EIO;
LOG((2, "rename_att_handler name = %s", name));
if ((mpierr = MPI_Bcast(&newnamelen, 1, MPI_INT, 0, ios->intercomm)))
return PIO_EIO;
LOG((2, "rename_att_handler newnamelen = %d", newnamelen));
if (!(newname = malloc((newnamelen + 1) * sizeof(char))))
return PIO_ENOMEM;
if ((mpierr = MPI_Bcast(newname, newnamelen + 1, MPI_CHAR, 0, ios->intercomm)))
return PIO_EIO;
LOG((2, "rename_var_handler got parameters namelen = %d name = %s ncid = %d varid = %d"
LOG((2, "rename_att_handler got parameters namelen = %d name = %s ncid = %d varid = %d "
"newnamelen = %d newname = %s", namelen, name, ncid, varid, newnamelen, newname));

/* Call the create file function. */
if ((ret = PIOc_rename_att(ncid, varid, name, newname)))
{
LOG((2, "rename_att_handler rename_att returned %d", ret));
return ret;
}

/* Free resources. */
free(name);
Expand Down Expand Up @@ -1224,7 +1234,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys)
LOG((3, "about to call msg MPI_Bcast"));
mpierr = MPI_Bcast(&msg, 1, MPI_INT, 0, my_iosys->io_comm);
CheckMPIReturn(mpierr, __FILE__, __LINE__);
LOG((1, "msg MPI_Bcast complete msg = %d", msg));
LOG((1, "pio_msg_handler msg MPI_Bcast complete msg = %d", msg));

/* Handle the message. This code is run on all IO tasks. */
switch (msg)
Expand Down Expand Up @@ -1261,6 +1271,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys)
break;
case PIO_MSG_RENAME_ATT:
rename_att_handler(my_iosys);
LOG((1, "rename_att_handler returned"));
break;
case PIO_MSG_DEF_DIM:
def_dim_handler(my_iosys);
Expand Down
30 changes: 21 additions & 9 deletions src/clib/pio_nc_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,15 +1299,16 @@ int PIOc_rename_var(int ncid, int varid, const char *name)
* @param ncid the ncid of the open file, obtained from
* PIOc_openfile() or PIOc_createfile().
* @param varid the variable ID.
* @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling
* @return PIO_NOERR for success, error code otherwise. See
* PIOc_Set_File_Error_Handling
*/
int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname)
{
int PIOc_rename_att (int ncid, int varid, const char *name,
const char *newname)
{
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. */
int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */

/* User must provide names of correct length. */
if (!name || strlen(name) > NC_MAX_NAME ||
Expand All @@ -1322,6 +1323,8 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname)
return PIO_EBADID;
ios = file->iosystem;

LOG((2, "PIOc_rename_att2 ncid = %d varid = %d name = %s newname = %s",
ncid, varid, name, newname));
/* If async is in use, and this is not an IO task, bcast the parameters. */
if (ios->async_interface)
{
Expand All @@ -1331,9 +1334,12 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname)
int namelen = strlen(name);
int newnamelen = strlen(newname);

if(ios->compmaster)
mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm);
LOG((2, "PIOc_rename_att sending msg"));

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

LOG((2, "PIOc_rename_att done sending msg"));
if (!mpierr)
mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm);
if (!mpierr)
Expand All @@ -1346,18 +1352,19 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname)
mpierr = MPI_Bcast(&newnamelen, 1, MPI_INT, ios->compmaster, ios->intercomm);
if (!mpierr)
mpierr = MPI_Bcast((char *)newname, newnamelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm);
LOG((2, "PIOc_rename_att Bcast file->fh = %d varid = %d namelen = %d name = %s"
"newnamelen = %s newname = %s", file->fh, varid, namelen, name, newnamelen, newname));
}


/* 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__);
}
LOG((2, "PIOc_rename_att calling netcdf function"));


/* If this is an IO task, then call the netCDF function. */
LOG((2, "PIOc_rename_att calling netcdf function"));
if (ios->ioproc)
{
#ifdef _PNETCDF
Expand All @@ -1372,10 +1379,15 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname)
}

/* Broadcast and check the return code. */
LOG((2, "PIOc_rename_att Bcasting %d", ierr));
if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm)))
{
LOG((2, "PIOc_rename_att ERROR"));
return PIO_EIO;
}
LOG((2, "PIOc_rename_att Bcast complete"));
check_netcdf(file, ierr, __FILE__, __LINE__);

LOG((2, "PIOc_rename_att succeeded"));
return ierr;
}

Expand Down
21 changes: 18 additions & 3 deletions tests/unit/test_intercomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define VAR_NAME "var_test_intercomm"

/** The name of the global attribute in the netCDF output file. */
#define FIRST_ATT_NAME "willy"
#define FIRST_ATT_NAME "willy_gatt_test_intercomm"
#define ATT_NAME "gatt_test_intercomm"
#define SHORT_ATT_NAME "short_gatt_test_intercomm"
#define FLOAT_ATT_NAME "float_gatt_test_intercomm"
Expand Down Expand Up @@ -450,8 +450,23 @@ main(int argc, char **argv)
short short_att_data = ATT_VALUE;
float float_att_data = ATT_VALUE;
double double_att_data = ATT_VALUE;
if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data)))
ERR(ret);
char attname2[NC_MAX_NAME + 1];
if (fmt == 0)
{
if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data)))
ERR(ret);
}
else
{
if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, FIRST_ATT_NAME, NC_INT, 1, &att_data)))
ERR(ret);
if ((ret = PIOc_inq_attname(ncid, NC_GLOBAL, 0, attname2)))
ERR(ret);
if (strcmp(attname2, FIRST_ATT_NAME))
ERR(ERR_WRONG);
if ((ret = PIOc_rename_att(ncid, NC_GLOBAL, FIRST_ATT_NAME, ATT_NAME)))
ERR(ret);
}
if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, NC_SHORT, 1, &short_att_data)))
ERR(ret);
if ((ret = PIOc_put_att_float(ncid, NC_GLOBAL, FLOAT_ATT_NAME, NC_FLOAT, 1, &float_att_data)))
Expand Down

0 comments on commit a055a39

Please sign in to comment.