hdf5/test/iopipe.c
Robb Matzke c01750fa74 [svn-r338] Changes since 19980407
----------------------

./src/H5B.c
./src/H5D.c
./src/H5Dprivate.h
./src/H5Dpublic.h
./src/H5F.c
./src/H5Farray.c
./src/H5Fcore.c
./src/H5Ffamily.c
./src/H5Fistore.c
./src/H5Flow.c
./src/H5Fprivate.h
./src/H5Fpublic.h
./src/H5Fsec2.c
./src/H5Fsplit.c
./src/H5Fstdio.c
./src/H5G.c
./src/H5Gent.c
./src/H5Gnode.c
./src/H5HG.c
./src/H5HL.c
./src/H5MF.c
./src/H5MFprivate.h
./src/H5O.c
./src/H5Ocont.c
./src/H5Odtype.c
./src/H5Oefl.c
./src/H5Olayout.c
./src/H5Oname.c
./src/H5Oprivate.h
./src/H5Osdspace.c
./src/H5Oshared.c
./src/H5Ostab.c
./src/H5P.c
./src/H5Ppublic.h
./src/H5S.c
./src/H5Sprivate.h
./src/H5Spublic.h
./src/H5Ssimp.c
./src/H5Tconv.c
./src/H5Tpkg.h
./src/H5V.c
./src/H5Vprivate.h
./src/H5private.h
./src/H5public.h
./src/h5ls.c
./test/cmpd_dset.c
./test/dsets.c
./test/extend.c
./test/external.c
./test/hyperslab.c
./test/iopipe.c
./test/istore.c
./test/shtype.c
./test/tfile.c
./test/th5s.c
	Anything having to do with the size of a dataset now uses the
	types `hsize_t' and `hssize_t' which must be the same size and
	at least as large as `size_t'.  This isn't fully tested yet,
	so hsize_t and hssize_t are defined as size_t and ssize_t in
	H5public.h.  Setting them to larger values will trip up gcc
	versions less than 2.8.1 on x86 platforms.

	Documented unused function formals with `__unused__' before
	the formal name.  This also has the effect of supressing
	warning messages for gcc since it's defined to be
	`__attribute__((unused))' in the H5private.h file.

./src/debug.c
./src/h5ls.c
	If the file name contains a `%' then the file is opened as a
	file family with H5P_DEFAULT for the file member access
	property list.

./src/h5ls.c
	The group name is optional, defaulting to `/'.

./src/hdf5.h
	Added some missing public header files.
1998-04-08 16:43:02 -05:00

319 lines
8.3 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (C) 1998 NCSA
* All rights reserved.
*
* Programmer: Robb Matzke <matzke@llnl.gov>
* Thursday, March 12, 1998
*/
#undef NDEBUG
#include <assert.h>
#include <fcntl.h>
#include <hdf5.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#define RAW_FILE_NAME "iopipe.raw"
#define HDF5_FILE_NAME "iopipe.h5"
#define HEADING "%-16s"
#define PROGRESS '='
#if 1
/* Normal testing */
#define REQUEST_SIZE_X 4579
#define REQUEST_SIZE_Y 4579
#define NREAD_REQUESTS 45
#define NWRITE_REQUESTS 45
#else
/* Speedy testing */
#define REQUEST_SIZE_X 1000
#define REQUEST_SIZE_Y 1000
#define NREAD_REQUESTS 45
#define NWRITE_REQUESTS 45
#endif
/*-------------------------------------------------------------------------
* Function: print_stats
*
* Purpose: Prints statistics
*
* Return: void
*
* Programmer: Robb Matzke
* Thursday, March 12, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
print_stats (const char *prefix,
struct rusage *r_start, struct rusage *r_stop,
struct timeval *t_start, struct timeval *t_stop,
size_t nbytes)
{
double u_time, s_time, e_time, bw;
u_time = ((double)(r_stop->ru_utime.tv_sec)+
(double)(r_stop->ru_utime.tv_usec)/1000000.0) -
((double)(r_start->ru_utime.tv_sec)+
(double)(r_start->ru_utime.tv_usec)/1000000.0);
s_time = ((double)(r_stop->ru_stime.tv_sec)+
(double)(r_stop->ru_stime.tv_usec)/1000000.0) -
((double)(r_start->ru_stime.tv_sec)+
(double)(r_start->ru_stime.tv_usec)/1000000.0);
e_time = ((double)(t_stop->tv_sec)+
(double)(t_stop->tv_usec)/1000000.0) -
((double)(t_start->tv_sec)+
(double)(t_start->tv_usec)/1000000.0);
bw = (double)nbytes / e_time;
printf (HEADING "%1.2fuser %1.2fsystem %1.2felapsed %1.2fMB/s\n",
prefix, u_time, s_time, e_time, bw/(1024*1024));
}
/*-------------------------------------------------------------------------
* Function: synchronize
*
* Purpose:
*
* Return: void
*
* Programmer: Robb Matzke
* Thursday, March 12, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
synchronize (void)
{
#ifdef HAVE_SYSTEM
system ("sync");
system ("df >/dev/null");
#if 0
/*
* This works well on Linux to get rid of all cached disk buffers. The
* number should be approximately the amount of RAM in MB. Do not
* include swap space in that amount or the command will fail.
*/
system ("/sbin/swapout 128");
#endif
#endif
}
/*-------------------------------------------------------------------------
* Function: main
*
* Purpose:
*
* Return: Success:
*
* Failure:
*
* Programmer: Robb Matzke
* Thursday, March 12, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
int
main (void)
{
static hsize_t size[2] = {REQUEST_SIZE_X, REQUEST_SIZE_Y};
static int nread=NREAD_REQUESTS, nwrite=NWRITE_REQUESTS;
unsigned char *the_data = NULL;
hid_t file, dset, file_space=-1;
herr_t status;
struct rusage r_start, r_stop;
struct timeval t_start, t_stop;
int i, fd;
hssize_t n;
off_t offset;
hssize_t start[2];
hsize_t count[2];
printf ("I/O request size is %1.1fMB\n",
((double)(size[0])*(double)(size[1]))/(1024.0*1024));
/* Open the files */
file = H5Fcreate (HDF5_FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
assert (file>=0);
fd = open (RAW_FILE_NAME, O_RDWR|O_CREAT|O_TRUNC, 0666);
assert (fd>=0);
/* Create the dataset */
file_space = H5Screate_simple (2, size, size);
assert (file_space>=0);
dset = H5Dcreate (file, "dset", H5T_NATIVE_UCHAR, file_space, H5P_DEFAULT);
assert (dset>=0);
the_data = malloc ((size_t)(size[0]*size[1]));
/*initial fill for lazy malloc*/
memset (the_data, 0xAA, (size_t)(size[0]*size[1]));
/* Fill raw */
synchronize ();
getrusage (RUSAGE_SELF, &r_start);
gettimeofday (&t_start, NULL);
fprintf (stderr, HEADING, "fill raw");
for (i=0; i<nwrite; i++) {
putc (PROGRESS, stderr);
fflush (stderr);
memset (the_data, 0xAA, (size_t)(size[0]*size[1]));
}
getrusage (RUSAGE_SELF, &r_stop);
gettimeofday (&t_stop, NULL);
putc ('\n', stderr);
print_stats ("fill raw",
&r_start, &r_stop, &t_start, &t_stop,
(size_t)(nread*size[0]*size[1]));
/* Fill hdf5 */
synchronize ();
getrusage (RUSAGE_SELF, &r_start);
gettimeofday (&t_start, NULL);
fprintf (stderr, HEADING, "fill hdf5");
for (i=0; i<nread; i++) {
putc (PROGRESS, stderr);
fflush (stderr);
status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space,
H5P_DEFAULT, the_data);
assert (status>=0);
}
getrusage (RUSAGE_SELF, &r_stop);
gettimeofday (&t_stop, NULL);
putc ('\n', stderr);
print_stats ("fill hdf5",
&r_start, &r_stop, &t_start, &t_stop,
(size_t)(nread*size[0]*size[1]));
/* Write the raw dataset */
synchronize ();
getrusage (RUSAGE_SELF, &r_start);
gettimeofday (&t_start, NULL);
fprintf (stderr, HEADING, "out raw");
for (i=0; i<nwrite; i++) {
putc (PROGRESS, stderr);
fflush (stderr);
offset = lseek (fd, 0, SEEK_SET);
assert (0==offset);
n = write (fd, the_data, (size_t)(size[0]*size[1]));
assert (n>=0 && (size_t)n==size[0]*size[1]);
}
getrusage (RUSAGE_SELF, &r_stop);
gettimeofday (&t_stop, NULL);
putc ('\n', stderr);
print_stats ("out raw",
&r_start, &r_stop, &t_start, &t_stop,
(size_t)(nread*size[0]*size[1]));
/* Write the hdf5 dataset */
synchronize ();
getrusage (RUSAGE_SELF, &r_start);
gettimeofday (&t_start, NULL);
fprintf (stderr, HEADING, "out hdf5");
for (i=0; i<nwrite; i++) {
putc (PROGRESS, stderr);
fflush (stderr);
status = H5Dwrite (dset, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL,
H5P_DEFAULT, the_data);
assert (status>=0);
}
getrusage (RUSAGE_SELF, &r_stop);
gettimeofday (&t_stop, NULL);
putc ('\n', stderr);
print_stats ("out hdf5",
&r_start, &r_stop, &t_start, &t_stop,
(size_t)(nread*size[0]*size[1]));
/* Read the raw dataset */
synchronize ();
getrusage (RUSAGE_SELF, &r_start);
gettimeofday (&t_start, NULL);
fprintf (stderr, HEADING, "in raw");
for (i=0; i<nread; i++) {
putc (PROGRESS, stderr);
fflush (stderr);
offset = lseek (fd, 0, SEEK_SET);
assert (0==offset);
n = read (fd, the_data, (size_t)(size[0]*size[1]));
assert (n>=0 && (size_t)n==size[0]*size[1]);
}
getrusage (RUSAGE_SELF, &r_stop);
gettimeofday (&t_stop, NULL);
putc ('\n', stderr);
print_stats ("in raw",
&r_start, &r_stop, &t_start, &t_stop,
(size_t)(nread*size[0]*size[1]));
/* Read the hdf5 dataset */
synchronize ();
getrusage (RUSAGE_SELF, &r_start);
gettimeofday (&t_start, NULL);
fprintf (stderr, HEADING, "in hdf5");
for (i=0; i<nread; i++) {
putc (PROGRESS, stderr);
fflush (stderr);
status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space,
H5P_DEFAULT, the_data);
assert (status>=0);
}
getrusage (RUSAGE_SELF, &r_stop);
gettimeofday (&t_stop, NULL);
putc ('\n', stderr);
print_stats ("in hdf5",
&r_start, &r_stop, &t_start, &t_stop,
(size_t)(nread*size[0]*size[1]));
/* Read hyperslab */
assert (size[0]>20 && size[1]>20);
start[0] = start[1] = 10;
count[0] = count[1] = size[0]-20;
status = H5Sset_hyperslab (file_space, start, count, NULL);
assert (status>=0);
synchronize ();
getrusage (RUSAGE_SELF, &r_start);
gettimeofday (&t_start, NULL);
fprintf (stderr, HEADING, "in hdf5 partial");
for (i=0; i<nread; i++) {
putc (PROGRESS, stderr);
fflush (stderr);
status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space,
H5P_DEFAULT, the_data);
assert (status>=0);
}
getrusage (RUSAGE_SELF, &r_stop);
gettimeofday (&t_stop, NULL);
putc ('\n', stderr);
print_stats ("in hdf5 partial",
&r_start, &r_stop, &t_start, &t_stop,
(size_t)(nread*count[0]*count[1]));
/* Close everything */
close (fd);
H5Dclose (dset);
H5Sclose (file_space);
H5Fclose (file);
return 0;
}