Commit 100231bb authored by Lars Pastewka's avatar Lars Pastewka
Browse files

ENH: Enable multi file writes.

parent 84378f8a
Loading
Loading
Loading
Loading
+28 −7
Original line number Diff line number Diff line
@@ -88,8 +88,8 @@ DumpNetCDF::DumpNetCDF(LAMMPS *lmp, int narg, char **arg) :

  if (multiproc)
    error->all(FLERR,"Multi-processor writes are not supported.");
  if (multifile)
    error->all(FLERR,"Multiple files are not supported.");
  if (append_flag && multifile)
    error->all(FLERR,"Cannot append when writing to multiple files.");

  perat = new nc_perat_t[nfield];

@@ -224,6 +224,24 @@ DumpNetCDF::~DumpNetCDF()

void DumpNetCDF::openfile()
{
  char *filecurrent = filename;
  if (multifile && !singlefile_opened) {
    char *filestar = filecurrent;
    filecurrent = new char[strlen(filestar) + 16];
    char *ptr = strchr(filestar,'*');
    *ptr = '\0';
    if (padflag == 0)
      sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
              filestar,update->ntimestep,ptr+1);
    else {
      char bif[8],pad[16];
      strcpy(bif,BIGINT_FORMAT);
      sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
      sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
    }
    *ptr = '*';
  }

  if (thermo && !singlefile_opened) {
    if (thermovar)  delete [] thermovar;
    thermovar = new int[output->thermo->nfield];
@@ -268,14 +286,14 @@ void DumpNetCDF::openfile()
  ntotalgr = group->count(igroup);

  if (filewriter) {
    if (append_flag && access(filename, F_OK) != -1) {
    if (append_flag && !multifile && access(filecurrent, F_OK) != -1) {
      // Fixme! Perform checks if dimensions and variables conform with
      // data structure standard.

      if (singlefile_opened) return;
      singlefile_opened = 1;

      NCERRX( nc_open(filename, NC_WRITE, &ncid), filename );
      NCERRX( nc_open(filecurrent, NC_WRITE, &ncid), filecurrent );

      // dimensions
      NCERRX( nc_inq_dimid(ncid, NC_FRAME_STR, &frame_dim), NC_FRAME_STR );
@@ -348,8 +366,8 @@ void DumpNetCDF::openfile()
      if (singlefile_opened) return;
      singlefile_opened = 1;

      NCERRX( nc_create(filename, NC_64BIT_DATA, &ncid),
          filename );
      NCERRX( nc_create(filecurrent, NC_64BIT_DATA, &ncid),
              filecurrent );

      // dimensions
      NCERRX( nc_def_dim(ncid, NC_FRAME_STR, NC_UNLIMITED, &frame_dim),
@@ -601,6 +619,9 @@ void DumpNetCDF::closefile()
    // append next time DumpNetCDF::openfile is called
    append_flag = 1;
    // write to next frame upon next open
    if (multifile)
      framei = 1;
    else
      framei++;
  }
}
+29 −8
Original line number Diff line number Diff line
@@ -88,8 +88,8 @@ DumpNetCDFMPIIO::DumpNetCDFMPIIO(LAMMPS *lmp, int narg, char **arg) :

  if (multiproc)
    error->all(FLERR,"Multi-processor writes are not supported.");
  if (multifile)
    error->all(FLERR,"Multiple files are not supported.");
  if (append_flag && multifile)
    error->all(FLERR,"Cannot append when writing to multiple files.");

  perat = new nc_perat_t[nfield];

@@ -217,6 +217,24 @@ DumpNetCDFMPIIO::~DumpNetCDFMPIIO()

void DumpNetCDFMPIIO::openfile()
{
  char *filecurrent = filename;
  if (multifile && !singlefile_opened) {
    char *filestar = filecurrent;
    filecurrent = new char[strlen(filestar) + 16];
    char *ptr = strchr(filestar,'*');
    *ptr = '\0';
    if (padflag == 0)
      sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
              filestar,update->ntimestep,ptr+1);
    else {
      char bif[8],pad[16];
      strcpy(bif,BIGINT_FORMAT);
      sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
      sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
    }
    *ptr = '*';
  }

  if (thermo && !singlefile_opened) {
    if (thermovar)  delete [] thermovar;
    thermovar = new int[output->thermo->nfield];
@@ -260,7 +278,7 @@ void DumpNetCDFMPIIO::openfile()
  // get total number of atoms
  ntotalgr = group->count(igroup);

  if (append_flag && access(filename, F_OK) != -1) {
  if (append_flag && !multifile && access(filecurrent, F_OK) != -1) {
    // Fixme! Perform checks if dimensions and variables conform with
    // data structure standard.

@@ -270,8 +288,8 @@ void DumpNetCDFMPIIO::openfile()
    if (singlefile_opened) return;
    singlefile_opened = 1;

    NCERRX( ncmpi_open(MPI_COMM_WORLD, filename, NC_WRITE, MPI_INFO_NULL,
                       &ncid), filename );
    NCERRX( ncmpi_open(MPI_COMM_WORLD, filecurrent, NC_WRITE, MPI_INFO_NULL,
                       &ncid), filecurrent );

    // dimensions
    NCERRX( ncmpi_inq_dimid(ncid, NC_FRAME_STR, &frame_dim), NC_FRAME_STR );
@@ -344,8 +362,8 @@ void DumpNetCDFMPIIO::openfile()
    if (singlefile_opened) return;
    singlefile_opened = 1;

    NCERRX( ncmpi_create(MPI_COMM_WORLD, filename, NC_64BIT_DATA,
                         MPI_INFO_NULL, &ncid), filename );
    NCERRX( ncmpi_create(MPI_COMM_WORLD, filecurrent, NC_64BIT_DATA,
                         MPI_INFO_NULL, &ncid), filecurrent );

    // dimensions
    NCERRX( ncmpi_def_dim(ncid, NC_FRAME_STR, NC_UNLIMITED, &frame_dim),
@@ -577,6 +595,9 @@ void DumpNetCDFMPIIO::closefile()
    // append next time DumpNetCDFMPIIO::openfile is called
    append_flag = 1;
    // write to next frame upon next open
    if (multifile)
      framei = 1;
    else
      framei++;
  }
}