Skip to content

Commit

Permalink
further development of async code
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed May 13, 2016
1 parent 06b279e commit 99632fd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 79 deletions.
6 changes: 4 additions & 2 deletions src/clib/pio_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int inq_type_handler(iosystem_desc_t *ios)
int mpierr;
int ret;

LOG((1, "typelen_handler"));
LOG((1, "inq_type_handler"));

/* Get the parameters for this function that the the comp master
* task is broadcasting. */
Expand All @@ -40,7 +40,7 @@ int inq_type_handler(iosystem_desc_t *ios)
return PIO_EIO;
if ((mpierr = MPI_Bcast(&size_present, 1, MPI_CHAR, 0, ios->intercomm)))
return PIO_EIO;
LOG((1, "inq_type_handler got parameters ncid = %d datatype = %d", ncid, xtype));
LOG((2, "inq_type_handler got parameters ncid = %d datatype = %d", ncid, xtype));

if (name_present)
namep = name;
Expand All @@ -51,6 +51,8 @@ int inq_type_handler(iosystem_desc_t *ios)
if ((ret = PIOc_inq_type(ncid, xtype, namep, sizep)))
return ret;

if (sizep)
LOG((2, "inq_type_handler size = %d", *sizep));
LOG((1, "inq_type_handler succeeded!"));
return PIO_NOERR;
}
Expand Down
74 changes: 6 additions & 68 deletions src/clib/pio_nc_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep)

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

/* Broadcast results to all tasks. Ignore NULL parameters. */
Expand Down Expand Up @@ -2344,11 +2344,12 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype,
if (!ios->async_interface || !ios->ioproc)
{
/* Get the length (in bytes) of the type. */
if ((ierr = PIOc_inq_type(file->fh, xtype, NULL, &typelen)))
if ((ierr = PIOc_inq_type(ncid, xtype, NULL, &typelen)))
{
check_netcdf(file, ierr, __FILE__, __LINE__);
return ierr;
}
LOG((2, "PIOc_put_att typelen = %d", ncid, typelen));
}

/* If async is in use, and this is not an IO task, bcast the parameters. */
Expand Down Expand Up @@ -2379,6 +2380,8 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype,
if (!mpierr)
mpierr = MPI_Bcast((void *)op, len * typelen, MPI_BYTE, ios->compmaster,
ios->intercomm);
LOG((2, "PIOc_put_att finished bcast ncid = %d varid = %d namelen = %d name = %s "
"len = %d typelen = %d", file->fh, varid, namelen, name, len, typelen));
}

/* Handle MPI errors. */
Expand Down Expand Up @@ -2592,72 +2595,7 @@ int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip)
int PIOc_put_att_int(int ncid, int varid, const char *name, nc_type xtype,
PIO_Offset len, const int *op)
{
int ierr;
int msg;
int mpierr;
iosystem_desc_t *ios;
file_desc_t *file;
char *errstr;
size_t namelen;

int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
printf("%d PIOc_inq_varid ncid = %d name = %s\n", my_rank, ncid, name);

errstr = NULL;
ierr = PIO_NOERR;

file = pio_get_file_from_id(ncid);
if(file == NULL)
return PIO_EBADID;
ios = file->iosystem;
msg = PIO_MSG_PUT_ATT_INT;

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);
mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm);
namelen = strlen(name);
mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm);
mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm);
mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm);
mpierr = MPI_Bcast(&len, 1, MPI_OFFSET, ios->compmaster, ios->intercomm);
mpierr = MPI_Bcast((void *)op, len, MPI_INT, ios->compmaster, ios->intercomm);
}

if(ios->ioproc){
switch(file->iotype){
#ifdef _NETCDF
#ifdef _NETCDF4
case PIO_IOTYPE_NETCDF4P:
ierr = nc_put_att_int(file->fh, varid, name, xtype, (size_t)len, op);;
break;
case PIO_IOTYPE_NETCDF4C:
#endif
case PIO_IOTYPE_NETCDF:
if(ios->io_rank==0){
ierr = nc_put_att_int(file->fh, varid, name, xtype, (size_t)len, op);;
}
break;
#endif
#ifdef _PNETCDF
case PIO_IOTYPE_PNETCDF:
ierr = ncmpi_put_att_int(file->fh, varid, name, xtype, len, op);;
break;
#endif
default:
ierr = iotype_error(file->iotype,__FILE__,__LINE__);
}
}

if(ierr != PIO_NOERR){
errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char));
sprintf(errstr,"in file %s",__FILE__);
}
ierr = check_netcdf(file, ierr, errstr,__LINE__);
if(errstr != NULL) free(errstr);
return ierr;
return PIOc_put_att(ncid, varid, name, xtype, len, op);
}

/**
Expand Down
27 changes: 18 additions & 9 deletions tests/unit/test_intercomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

/** The name of the global attribute in the netCDF output file. */
#define ATT_NAME "gatt_test_intercomm"
#define SHORT_ATT_NAME "short_gatt_test_intercomm"

/** The value of the global attribute in the netCDF output file. */
#define ATT_VALUE 42
Expand Down Expand Up @@ -85,6 +86,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose)
int varndims2, vardimids2, varnatts2;
int varid2;
int att_data;
short short_att_data;

/* Re-open the file to check it. */
if (verbose)
Expand All @@ -96,7 +98,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose)
/* Find the number of dimensions, variables, and global attributes.*/
if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)))
ERR(ret);
if (ndims != 1 || nvars != 1 || ngatts != 1 || unlimdimid != -1)
if (ndims != 1 || nvars != 1 || ngatts != 2 || unlimdimid != -1)
ERR(ERR_WRONG);

/* This should return PIO_NOERR. */
Expand All @@ -114,7 +116,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose)
ERR(ERR_WRONG);
if ((ret = PIOc_inq_natts(ncid, &ngatts2)))
ERR(ret);
if (ngatts2 != 1)
if (ngatts2 != 2)
ERR(ERR_WRONG);
if ((ret = PIOc_inq_unlimdim(ncid, &unlimdimid2)))
ERR(ret);
Expand Down Expand Up @@ -191,6 +193,15 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose)
printf("%d test_intercomm att_data = %d\n", my_rank, att_data);
if (att_data != ATT_VALUE)
ERR(ERR_WRONG);
if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, SHORT_ATT_NAME, &atttype, &attlen)))
ERR(ret);
if (atttype != NC_SHORT || attlen != 1)
ERR(ERR_WRONG);
if ((ret = PIOc_get_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, &short_att_data)))
ERR(ret);
if (short_att_data != ATT_VALUE)
ERR(ERR_WRONG);


/* Close the file. */
if (verbose)
Expand Down Expand Up @@ -387,12 +398,10 @@ main(int argc, char **argv)
printf("%d test_intercomm writing attributes %s\n", my_rank, ATT_NAME);
int att_data = ATT_VALUE;
short short_att_data = ATT_VALUE;
sleep(2);
if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &short_att_data)))
ERR(ret);
sleep(2);
if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data)))
ERR(ret);
if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, NC_SHORT, 1, &short_att_data)))
ERR(ret);

/* End define mode. */
if (verbose)
Expand All @@ -415,9 +424,9 @@ main(int argc, char **argv)
if ((ret = PIOc_closefile(ncid)))
ERR(ret);

/* /\* Check the file for correctness. *\/ */
/* if ((ret = check_file(iosysid, format[fmt], filename[fmt], my_rank, verbose))) */
/* ERR(ret); */
/* Check the file for correctness. */
if ((ret = check_file(iosysid, format[fmt], filename[fmt], my_rank, verbose)))
ERR(ret);

/* Now delete the file. */
/* if ((ret = PIOc_deletefile(iosysid, filename[fmt]))) */
Expand Down

0 comments on commit 99632fd

Please sign in to comment.