Пример #1
0
//--------------------------------------------------------------------------
// Function:	FileAccPropList::setCore
///\brief	Modifies this file access property list to use the \c H5FD_CORE
///		driver.
///\param	increment - IN: Specifies how much memory to increase each
///				time more memory is needed, in bytes
///\param	backing_store - IN: Indicating whether to write the file
///				contents to disk when the file is closed
///\exception	H5::PropListIException
///\par Description
///		For more details on the use of \c H5FD_CORE driver, please
///		refer to
/// <A HREF="../RM_H5P.html#Property-SetFaplCore">../RM_H5P.html#Property-SetFaplCore</A>
// Programmer:  Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void FileAccPropList::setCore (size_t increment, hbool_t backing_store) const
{
   herr_t ret_value = H5Pset_fapl_core (id, increment, backing_store);
   if (ret_value < 0)
   {
      throw PropListIException ("FileAccPropList::setCore", "H5Pset_fapl_core failed");
   }
}
Пример #2
0
H5File::H5File(const std::string & _filename, const std::string & _path, const std::string & access, const bool backingStore, const size_t blockSize) : H5Object(H5Object::getRoot()), filename(_filename), path(_path), flags(getFlags(access))
{
    herr_t err;
    hid_t fapl = H5Pcreate(H5P_FILE_ACCESS);
    H5Pset_fclose_degree(fapl, H5F_CLOSE_STRONG);

    err = H5Pset_fapl_core(fapl, blockSize, (hbool_t)backingStore);
    if (err < 0)
    {
        H5Pclose(fapl);
        throw H5Exception(__LINE__, __FILE__, _("Cannot set \'core\' as driver."));
    }

    try
    {
        init(fapl);
        H5Pclose(fapl);
    }
    catch (const H5Exception & /*e*/)
    {
        H5Pclose(fapl);
        throw;
    }
}
Пример #3
0
/*-------------------------------------------------------------------------
 * Function:    test_core
 *
 * Purpose:     Tests the file handle interface for CORE driver
 *
 * Return:      Success:        0
 *              Failure:        -1
 *
 * Programmer:  Raymond Lu
 *              Tuesday, Sept 24, 2002
 *
 * Modifications:
 *
 *              Raymond Lu
 *              Wednesday, June 23, 2004
 *              Added test for H5Fget_filesize.
 *
 *              Raymond Lu, 2006-11-30
 *              Enabled the driver to read an existing file depending on
 *              the setting of the backing_store and file open flags.
 *-------------------------------------------------------------------------
 */
static herr_t
test_core(void)
{
    hid_t       file=(-1), fapl, access_fapl = -1;
    char        filename[1024];
    void        *fhandle=NULL;
    hsize_t     file_size;
    int		*points, *check, *p1, *p2;
    hid_t	dset1=-1, space1=-1;
    hsize_t	dims1[2];
    int		i, j, n;

    TESTING("CORE file driver");

    /* Set property list and file name for CORE driver */
    fapl = h5_fileaccess();
    if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, TRUE) < 0)
        TEST_ERROR;
    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);

    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR;

    /* Retrieve the access property list... */
    if ((access_fapl = H5Fget_access_plist(file)) < 0)
        TEST_ERROR;

    /* ...and close the property list */
    if (H5Pclose(access_fapl) < 0)
        TEST_ERROR;

    if(H5Fget_vfd_handle(file, H5P_DEFAULT, &fhandle) < 0)
        TEST_ERROR;
    if(fhandle==NULL)
    {
        printf("fhandle==NULL\n");
               TEST_ERROR;
    }

    /* Check file size API */
    if(H5Fget_filesize(file, &file_size) < 0)
        TEST_ERROR;

    /* There is no garantee the size of metadata in file is constant.
     * Just try to check if it's reasonable.  Why is this 4KB?
     */
    if(file_size<2*KB || file_size>6*KB)
        TEST_ERROR;

    if(H5Fclose(file) < 0)
        TEST_ERROR;


    /* Open the file with backing store off for read and write.
     * Changes won't be saved in file. */
    if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, FALSE) < 0)
        TEST_ERROR;

    if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
        TEST_ERROR;

    /* Allocate memory for data set. */
    points=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int));
    check=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int));

    /* Initialize the dset1 */
    p1 = points;
    for(i = n = 0; i < DSET1_DIM1; i++)
	for(j = 0; j < DSET1_DIM2; j++)
	    *p1++ = n++;

    /* Create the data space1 */
    dims1[0] = DSET1_DIM1;
    dims1[1] = DSET1_DIM2;
    if((space1 = H5Screate_simple(2, dims1, NULL)) < 0)
        TEST_ERROR;

    /* Create the dset1 */
    if((dset1 = H5Dcreate2(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        TEST_ERROR;

    /* Write the data to the dset1 */
    if(H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0)
        TEST_ERROR;

    if(H5Dclose(dset1) < 0)
        TEST_ERROR;

    if((dset1 = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0)
        TEST_ERROR;

    /* Read the data back from dset1 */
    if(H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check) < 0)
        TEST_ERROR;

    /* Check that the values read are the same as the values written */
    p1 = points;
    p2 = check;
    for(i = 0; i < DSET1_DIM1; i++)
	for(j = 0; j < DSET1_DIM2; j++)
	    if(*p1++ != *p2++) {
		H5_FAILED();
		printf("    Read different values than written in data set 1.\n");
		printf("    At index %d,%d\n", i, j);
        	TEST_ERROR;
	    } /* end if */

    if(H5Dclose(dset1) < 0)
        TEST_ERROR;

    if(H5Fclose(file) < 0)
        TEST_ERROR;

    /* Open the file with backing store on for read and write.
     * Changes will be saved in file. */
    if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, TRUE) < 0)
        TEST_ERROR;

    if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
        TEST_ERROR;

    /* Create the dset1 */
    if((dset1 = H5Dcreate2(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        TEST_ERROR;

    /* Write the data to the dset1 */
    if(H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0)
        TEST_ERROR;

    if(H5Dclose(dset1) < 0)
        TEST_ERROR;

    if((dset1 = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0)
        TEST_ERROR;

    /* Reallocate memory for reading buffer. */
    if(check)
	free(check);

    check = (int*)malloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int));

    /* Read the data back from dset1 */
    if(H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check) < 0)
        TEST_ERROR;

    /* Check that the values read are the same as the values written */
    p1 = points;
    p2 = check;
    for(i = 0; i < DSET1_DIM1; i++)
	for(j = 0; j < DSET1_DIM2; j++)
	    if(*p1++ != *p2++) {
		H5_FAILED();
		printf("    Read different values than written in data set 1.\n");
		printf("    At index %d,%d\n", i, j);
        	TEST_ERROR;
	    } /* end if */

    /* Check file size API */
    if(H5Fget_filesize(file, &file_size) < 0)
        TEST_ERROR;

    /* There is no garantee the size of metadata in file is constant.
     * Just try to check if it's reasonable. */
    if(file_size<64*KB || file_size>256*KB)
        TEST_ERROR;

    if(H5Sclose(space1) < 0)
        TEST_ERROR;
    if(H5Dclose(dset1) < 0)
        TEST_ERROR;
    if(H5Fclose(file) < 0)
        TEST_ERROR;
    if(points)
	free(points);
    if(check)
	free(check);

    h5_cleanup(FILENAME, fapl);

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose (fapl);
        H5Fclose(file);
    } H5E_END_TRY;
    return -1;
}
Пример #4
0
/*-------------------------------------------------------------------------
 * Function:  h5_fileaccess
 *
 * Purpose:  Returns a file access template which is the default template
 *    but with a file driver set according to the constant or
 *    environment variable HDF5_DRIVER
 *
 * Return:  Success:  A file access property list
 *
 *    Failure:  -1
 *
 * Programmer:  Robb Matzke
 *              Thursday, November 19, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
hid_t
h5_fileaccess(void)
{
    const char  *val = NULL;
    const char  *name;
    char s[1024];
    hid_t fapl = -1;

    /* First use the environment variable, then the constant */
    val = HDgetenv("HDF5_DRIVER");
#ifdef HDF5_DRIVER
    if (!val)
        val = HDF5_DRIVER;
#endif

    if ((fapl=H5Pcreate(H5P_FILE_ACCESS))<0)
        return -1;
    if (!val || !*val)
        return fapl; /*use default*/

    HDstrncpy(s, val, sizeof s);
    s[sizeof(s)-1] = '\0';
    if (NULL==(name=HDstrtok(s, " \t\n\r"))) return fapl;

    if (!HDstrcmp(name, "sec2")) {
        /* Unix read() and write() system calls */
        if (H5Pset_fapl_sec2(fapl)<0) return -1;
    } else if (!HDstrcmp(name, "stdio")) {
        /* Standard C fread() and fwrite() system calls */
        if (H5Pset_fapl_stdio(fapl)<0) return -1;
    } else if (!HDstrcmp(name, "core")) {
        /* In-memory driver settings (backing store on, 1 MB increment) */
        if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1;
    } else if (!HDstrcmp(name, "core_paged")) {
        /* In-memory driver with write tracking and paging on */
        if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1;
        if (H5Pset_core_write_tracking(fapl, TRUE, (size_t)4096)<0) return -1;
     } else if (!HDstrcmp(name, "split")) {
        /* Split meta data and raw data each using default driver */
        if (H5Pset_fapl_split(fapl,
            "-m.h5", H5P_DEFAULT,
            "-r.h5", H5P_DEFAULT)<0)
            return -1;
    } else if (!HDstrcmp(name, "multi")) {
        /* Multi-file driver, general case of the split driver */
        H5FD_mem_t memb_map[H5FD_MEM_NTYPES];
        hid_t memb_fapl[H5FD_MEM_NTYPES];
        const char *memb_name[H5FD_MEM_NTYPES];
        char sv[H5FD_MEM_NTYPES][1024];
        haddr_t memb_addr[H5FD_MEM_NTYPES];
        H5FD_mem_t  mt;

        HDmemset(memb_map, 0, sizeof memb_map);
        HDmemset(memb_fapl, 0, sizeof memb_fapl);
        HDmemset(memb_name, 0, sizeof memb_name);
        HDmemset(memb_addr, 0, sizeof memb_addr);

        HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES);
        for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t, mt)) {
          memb_fapl[mt] = H5P_DEFAULT;
            sprintf(sv[mt], "%%s-%c.h5", multi_letters[mt]);
            memb_name[mt] = sv[mt];
            memb_addr[mt] = (haddr_t)MAX(mt - 1, 0) * (HADDR_MAX / 10);
        } /* end for */

        if (H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name,
          memb_addr, FALSE)<0) {
            return -1;
        }
    } else if (!HDstrcmp(name, "family")) {
        hsize_t fam_size = 100*1024*1024; /*100 MB*/

        /* Family of files, each 1MB and using the default driver */
        if ((val=HDstrtok(NULL, " \t\n\r")))
            fam_size = (hsize_t)(HDstrtod(val, NULL) * 1024*1024);
        if (H5Pset_fapl_family(fapl, fam_size, H5P_DEFAULT)<0)
            return -1;
    } else if (!HDstrcmp(name, "log")) {
        unsigned log_flags = H5FD_LOG_LOC_IO | H5FD_LOG_ALLOC;

        /* Log file access */
        if ((val = HDstrtok(NULL, " \t\n\r")))
            log_flags = (unsigned)HDstrtol(val, NULL, 0);

        if (H5Pset_fapl_log(fapl, NULL, log_flags, (size_t)0) < 0)
            return -1;
    } else if (!HDstrcmp(name, "direct")) {
#ifdef H5_HAVE_DIRECT
        /* Linux direct read() and write() system calls.  Set memory boundary, file block size,
         * and copy buffer size to the default values. */
        if (H5Pset_fapl_direct(fapl, 1024, 4096, 8*4096)<0)
            return -1;
#endif
    } else if(!HDstrcmp(name, "latest")) {
        /* use the latest format */
        if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
            return -1;
    } else {
        /* Unknown driver */
        return -1;
    }

    return fapl;
}
Пример #5
0
int
main (int argc, char **argv)
{
  extern char* optarg;
  extern int optind, optopt;
  int c, errflg, backflg, incrflg, nopagflg, pagflg, rank, nranks;
  hid_t fapl, file, group, group1, dset;
  size_t incr, page;
  unsigned iter, level, igroup, idset, maxiter;
  char name[MAX_LEN];
  char g1name[MAX_LEN];
  char g2name[MAX_LEN];
  hsize_t dims[3] = { X, Y, Z };
  float *buf;
  double start, stop;
  double t1, t2;
  char cdum[MAX_LEN];
  int i, memtotal, memfree, buffers, cached, swapcached, active, inactive;
  float fdum;

  assert (MPI_Init (&argc, &argv) >= 0);
  assert (MPI_Comm_rank (MPI_COMM_WORLD, &rank) >= 0);
  assert (MPI_Comm_size (MPI_COMM_WORLD, &nranks) >= 0);

  /* parse arguments */

  backflg = errflg = incrflg = nopagflg = pagflg = 0;
  incr = INCREMENT;
  page = PAGE_SIZE;
  maxiter = MAX_ITER;

  while ((c = getopt(argc, argv, ":bni:t:p:")) != -1)
    {
      switch (c)
      {
      case 'b':
        backflg++;
        break;
      case 'i':
        incrflg++;
        incr = (size_t)atol(optarg);
        if (incr == 0)
          {
            fprintf(stderr,
                    "Option -%c requires a positive integer argument\n", optopt);
            errflg++;
          }
        break;
      case 'n':
        nopagflg++;
        break;
      case 'p':
        pagflg++;
        page = (size_t)atol(optarg);
        if (page == 0)
          {
            fprintf(stderr,
                    "Option -%c requires a positive integer argument\n", optopt);
            errflg++;
          }
        break;
      case 't':
        maxiter = (unsigned)atol(optarg);
        if (maxiter == 0)
          {
            fprintf(stderr,
                    "Option -%c requires a positive integer argument\n", optopt);
            errflg++;
          }
        break;
      case ':':       /* -i or -p without operand */
        fprintf(stderr,
                "Option -%c requires an operand\n", optopt);
        errflg++;
        break;
      case '?':
        fprintf(stderr, "Unrecognized option: -%c\n", optopt);
        errflg++;
        break;
      default:
        errflg++;
        break;
      }
    }
  if (errflg)
    {
      if (rank == 0)
        {
          fprintf(stderr, "usage: . . . ");

          fprintf(stderr, "usage: h5core [OPTIONS]\n");
          fprintf(stderr, "  OPTIONS\n");
          fprintf(stderr, "     -b      Write file to disk on exit\n");
          fprintf(stderr, "     -i I    Memory buffer increment size in bytes [default: 512 MB]\n");
          fprintf(stderr, "     -n      Disable write (to disk) paging\n");
          fprintf(stderr, "     -p P    Page size in bytes [default: 64 MB]\n");
          fprintf(stderr, "     -t T    Number of iterations [default: 5]\n");
          fprintf(stderr, "\n");
          fflush(stderr);
        }

      exit(2);
    }

  if ((backflg == 0) && (pagflg > 0))
    {
      if (rank == 0)
        {
          fprintf(stderr, "The -p has no effect without the -b option");
          fflush(stderr);
        }
    }

  if (pagflg && nopagflg)
    {
      if (rank == 0)
        {
          fprintf(stderr, "The -n and -p options are mutually exclusive.");
          fflush(stderr);
        }
      exit(3);
    }

  /* Let's go! */

  fapl = H5Pcreate (H5P_FILE_ACCESS);
  assert (fapl >= 0);
  assert (H5Pset_libver_bounds (fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) >= 0);
  assert (H5Pset_fapl_core (fapl, incr, (hbool_t) backflg) >= 0);
  if (nopagflg == 0)  /* the user didn't disable paging */
    {
      assert (H5Pset_core_write_tracking (fapl, 1, page) >= 0);
    }

  if (rank == 0)
    {
      printf("\n");
      printf("Write to disk: %s\n", (backflg > 0) ? "YES" : "NO");
      printf("Increment size: %ld [bytes]\n", incr);

      if (nopagflg == 0)
        {
          printf("Page size: %ld [bytes]\n", page);
        }
      else
        {
          printf("Page size: PAGING DISABLED!\n");
        }

      printf("Iterations: %d\n", maxiter);
      printf("\n");
      fflush(stdout);
    }

  buf = (float *) malloc (X * Y * Z * sizeof (float));

  // Get basic memory info on each node, see how memory usage changes
  // after flushing to disk; do we end up back where we started?

  getmemory (&memtotal, &memfree, &buffers, &cached, &swapcached, &active,
             &inactive);

  if (rank == 0)
    {
      fprintf (stdout, "BEFORE RUNNING:\n");
      fflush (stdout);
    }
  for (i = 0; i < nranks; i++)
    {
      if (rank == i)
        {
          printmemory (rank, memtotal, memfree, buffers, cached, swapcached,
                       active, inactive);
        }
      MPI_Barrier (MPI_COMM_WORLD);
    }

  start = MPI_Wtime ();

  /* outer loop - simulated time */
  for (iter = 0; iter < maxiter; ++iter)
    {
      if (rank == 0)
        {
          printf ("Iteration: %u\n", iter);
          assert (fflush (stdout) == 0);
        }

      assert (sprintf (name, "rank%05dtime%04u.h5", rank, iter) > 0);
      file = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
      assert (file >= 0);

      t1 = MPI_Wtime ();

      /* time level */
      for (level = 0; level < MAX_TIME_LEVEL; ++level)
        {
          assert (sprintf (g1name, "level%03d", level) > 0);
          group = H5Gcreate2 (file, g1name, H5P_DEFAULT, H5P_DEFAULT,
                              H5P_DEFAULT);
          assert (group >= 0);

          /* group level */
          for (igroup = 0; igroup < MAX_GROUPS; ++igroup)
            {
              assert (sprintf (g2name, "group%02d", igroup) > 0);
              group1 = H5Gcreate2 (group, g2name, H5P_DEFAULT, H5P_DEFAULT,
                                   H5P_DEFAULT);
              assert (group1 >= 0);

              /* dataset level */
              for (idset = 0; idset < MAX_DATASETS; ++idset)
                {
                  assert (sprintf (name, "dataset%02d", idset) > 0);
                  assert (H5LTmake_dataset_float (group1, name, RANK, dims, buf) >= 0);

#ifdef DEBUG
                  assert (fprintf (stderr,
                                   "rank %i time %i Wrote dataset %s/%s/%s\n",
                                   rank, level, g1name, g2name, name));
                  assert (fflush (stderr) == 0);
#endif
                }

              assert (H5Gclose (group1) >= 0);
            }

          assert (H5Gclose (group) >= 0);
        }

      t2 = MPI_Wtime ();

      assert (fprintf (stdout,
                       "rank %04i Total time for buffering chunks to memory:\t %f seconds\n",
                       rank, t2 - t1));
      assert (fflush (stdout) == 0);

      MPI_Barrier (MPI_COMM_WORLD);    // To keep output less jumbled

      getmemory (&memtotal, &memfree, &buffers, &cached, &swapcached, &active,
                 &inactive);

      if (rank == 0)
        {
          fprintf (stdout, "BEFORE FLUSHING:\n");
          fflush (stdout);
        }

      for (i = 0; i < nranks; i++)
        {
          if (rank == i)
            {
              printmemory (rank, memtotal, memfree, buffers, cached, swapcached,
                           active, inactive);
            }
          MPI_Barrier (MPI_COMM_WORLD);
        }

      /* close the file */
      t1 = MPI_Wtime ();
      assert (H5Fclose (file) >= 0);
      t2 = MPI_Wtime ();

      getmemory (&memtotal, &memfree, &buffers, &cached, &swapcached, &active,
                 &inactive);

      if (rank == 0)
        {
          fprintf (stdout, "AFTER FLUSHING:\n");
          fflush (stdout);
        }

      for (i = 0; i < nranks; i++)
        {
          if (rank == i)
            {
              printmemory (rank, memtotal, memfree, buffers, cached, swapcached,
                           active, inactive);
              assert (fprintf (stdout, "rank %04i Total time for flushing to disk:\t\t %10.2f seconds\n", rank, t2 - t1));
              assert (fflush (stderr) == 0);
            }
          MPI_Barrier (MPI_COMM_WORLD);
        }
    }

  stop = MPI_Wtime ();
  MPI_Barrier (MPI_COMM_WORLD);

  if (rank == 0)
    {
      printf ("Total time: %f s\n", stop - start);
      printf ("Aggregate bandwidth per process: %f GB/s\n",
              ((float) X * Y * Z * sizeof (float)) *
              ((float) MAX_DATASETS * MAX_GROUPS * MAX_TIME_LEVEL * MAX_ITER) /
              (1024.0 * 1024.0 * 1024.0 * (stop - start)));
    }

  free ((void *) buf);

  assert (H5Pclose (fapl) >= 0);

  assert (MPI_Finalize () >= 0);

  return 0;

}
Пример #6
0
hid_t
set_vfd(parameters *param)
{
    hid_t my_fapl = -1;
    vfdtype  vfd;

    vfd = param->vfd;

    if ((my_fapl=H5Pcreate(H5P_FILE_ACCESS))<0) return -1;

    if (vfd == sec2) {
        /* Unix read() and write() system calls */
        if (H5Pset_fapl_sec2(my_fapl)<0) return -1;
    } else if (vfd == stdio) {
        /* Standard C fread() and fwrite() system calls */
        if (H5Pset_fapl_stdio(my_fapl)<0) return -1;
    } else if (vfd == core) {
        /* In-core temporary file with 1MB increment */
        if (H5Pset_fapl_core(my_fapl, (size_t)1024*1024, TRUE)<0) return -1;
    } else if (vfd == split) {
        /* Split meta data and raw data each using default driver */
        if (H5Pset_fapl_split(my_fapl,
                              "-m.h5", H5P_DEFAULT,
                              "-r.h5", H5P_DEFAULT)<0)
            return -1;
    } else if (vfd == multi) {
        /* Multi-file driver, general case of the split driver */
        H5FD_mem_t memb_map[H5FD_MEM_NTYPES];
        hid_t memb_fapl[H5FD_MEM_NTYPES];
        const char *memb_name[H5FD_MEM_NTYPES];
        char sv[H5FD_MEM_NTYPES][1024];
        haddr_t memb_addr[H5FD_MEM_NTYPES];
        H5FD_mem_t      mt;

        HDmemset(memb_map, 0, sizeof memb_map);
        HDmemset(memb_fapl, 0, sizeof memb_fapl);
        HDmemset(memb_name, 0, sizeof memb_name);
        HDmemset(memb_addr, 0, sizeof memb_addr);

        HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES);
        for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) {
            memb_fapl[mt] = H5P_DEFAULT;
            sprintf(sv[mt], "%%s-%c.h5", multi_letters[mt]);
            memb_name[mt] = sv[mt];
            memb_addr[mt] = (haddr_t)MAX(mt - 1,0) * (HADDR_MAX / 10);
        }

        if (H5Pset_fapl_multi(my_fapl, memb_map, memb_fapl, memb_name,
                              memb_addr, FALSE)<0) {
            return -1;
        }
    } else if (vfd == family) {
        hsize_t fam_size = 1*1024*1024; /*100 MB*/

        /* Family of files, each 1MB and using the default driver */
        /* if ((val=HDstrtok(NULL, " \t\n\r")))
            fam_size = (hsize_t)(HDstrtod(val, NULL) * 1024*1024); */
        if (H5Pset_fapl_family(my_fapl, fam_size, H5P_DEFAULT)<0)
            return -1;
    } else if (vfd == direct) {
#ifdef H5_HAVE_DIRECT
        /* Linux direct read() and write() system calls.  Set memory boundary, file block size,
         * and copy buffer size to the default values. */
        if (H5Pset_fapl_direct(my_fapl, 1024, 4096, 8*4096)<0) return -1;
#endif
    } else {
        /* Unknown driver */
        return -1;
    }

    return my_fapl;
}
Пример #7
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	To create HDF5 files with non-zero status_flags in the superblock
 *		via flushing and exiting without closing the library.
 *
 *		Due to file locking, status_flag in the superblock will be 
 *		nonzero after H5Fcreate.  The library will clear status_flags
 *		on file closing.  This program, after "H5Fcreate" the files,
 *		exits without going through library closing. Thus, status_flags
 *		for these files are not cleared and users cannot open them.
 *
 *		These files are used by "h5clear" to see if the tool clears
 *		status_flags properly so users can open the files afterwards.
 *
 * Return:	Success:	0
 *		Failure:	1
 *
 * Programmer:	Vailin Choi; July 2013
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t fid;			/* File ID */
    hid_t fapl, new_fapl;	/* File access property lists */
    char fname[512];		/* File name */
    hbool_t new_format;		/* To use latest library format or not */
    int fd;			/* File descriptor */
    uint8_t super_vers;		/* Superblock version */
    ssize_t bytes_written;	/* The # of bytes written to the file */

    /* Create a copy of the file access property list */
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
	goto error;

    /* Copy the file access property list */
    if((new_fapl = H5Pcopy(fapl)) < 0)
	goto error;
    /* Set to latest library format */
    if(H5Pset_libver_bounds(new_fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
	goto error;

    /* Create file with/without latest library format */
    for(new_format = FALSE; new_format <= TRUE; new_format++) {
	hid_t fapl2, my_fapl;	/* File access property lists */

	/* Set to use the appropriate file access property list */
	if(new_format)
	    fapl2 = new_fapl;
	else
	    fapl2 = fapl;
	/*
	 * Create a sec2 file
	 */
	if((my_fapl = H5Pcopy(fapl2)) < 0)
	    goto error;
	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[0]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) 
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;
    
	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/*
	 * Create a core file
	 */
	/* Create a copy of file access property list */
	if((my_fapl = H5Pcopy(fapl2)) < 0)
	    goto error;

	/* Setup the fapl for the family file driver */
	if(H5Pset_fapl_core(my_fapl, (size_t)CORE_INCREMENT, TRUE) < 0)
	    goto error;

	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[1]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) 
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;

	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/*
	 * Create a family file
	 */
	/* Create a copy of file access property list */
	if((my_fapl = H5Pcopy(fapl2)) < 0)
	    goto error;

	/* Setup the fapl for the family file driver */
	if(H5Pset_fapl_family(my_fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0)
	    goto error;

	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[2]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) 
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;

	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/*
	 * Create a split file
	 */
	 /* Create a copy of file access property list */
	my_fapl = H5Pcopy(fapl2);

	/* Setup the fapl for the split file driver */
	H5Pset_fapl_split(my_fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT);

	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[3]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0)
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;

	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/* 
	 * Create a sec2 file but change its superblock version # 
	 */
	/* Create a copy of file access property list */
	if((my_fapl = H5Pcopy(fapl2)) < 0)
	    goto error;
	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[4]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) 
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;
    
	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/* Open the test file via system call "open" */
	if((fd = HDopen(fname, O_RDWR, 0666)) < 0) {
	    HDfprintf(stdout, "cannot open the file\n");
	    goto error;
	}

	/* Position the file to superblock version via system call "lseek" */
	if(HDlseek(fd, (off_t)SUPER_VERS_OFF, SEEK_SET) < 0) {
	    HDfprintf(stdout, "cannot lseek the file superblock version\n");
	    goto error;
	}

	/* Change to an incorrect superblock version */
	super_vers = SUPER_VERS_LATEST + 1;
	/* Write to the file via system call "write" */
	if((bytes_written = HDwrite(fd, &super_vers, (size_t)SUPER_VERS_SIZE)) < 0) {
	    HDfprintf(stdout, "cannot write to the file with incorrect superblock version\n");
	    goto error;
	}

	/* Close the file via system call "close" */
	if(HDclose(fd) < 0) {
	    HDfprintf(stdout, "cannot close the file\n");
	    goto error;
	}

    } /* end for */

    /* Close the property lists */
    if(H5Pclose(fapl) < 0)
	goto error;
    if(H5Pclose(new_fapl) < 0)
	goto error;

    fflush(stdout);
    fflush(stderr);

    /* Not going through library closing by calling _exit(0) with success */
    HD_exit(0);

error:

    /* Exit with failure */
    HD_exit(1);
}