summaryrefslogtreecommitdiffstats
path: root/perform/iopipe.c
blob: aa76369a577d030f14f4a29a0a982e1b1f0c4071 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
/*
 * Copyright (C) 1998 NCSA
 *                    All rights reserved.
 *
 * Programmer:  Robb Matzke <matzke@llnl.gov>
 *              Thursday, March 12, 1998
 */

/* See H5private.h for how to include headers */
#undef NDEBUG
#include "hdf5.h"

#ifdef H5_HAVE_WINSOCK_H
#include <Winsock.h>
#endif 

/*Winsock.h includes windows.h, due to the different value of
WINVER, windows.h should be put before H5private.h. Kent yang 6/21/2001*/

#include "H5private.h"

#ifdef H5_STDC_HEADERS
#   include <assert.h>
#   include <fcntl.h>
#   include <stdio.h>
#   include <string.h>
#   include <stdlib.h>
#endif

#ifdef H5_HAVE_UNISTD_H
#   include <sys/types.h>
#   include <unistd.h>
#endif

#if defined(H5_TIME_WITH_SYS_TIME)
#   include <sys/time.h>
#   include <time.h>
#elif defined(H5_HAVE_SYS_TIME_H)
#   include <sys/time.h>
#else
#   include <time.h>
#endif

#ifdef H5_HAVE_SYS_RESOURCE_H
#   include <sys/resource.h>
#endif



#if defined (__MWERKS__)
#ifdef H5_HAVE_SYS_TIMEB 
#undef H5_HAVE_SYS_TIMEB
#endif
#ifdef H5_HAVE_SYSTEM 
#undef H5_HAVE_SYSTEM
#endif
#endif /* __MWERKS__*/


#ifdef H5_HAVE_SYS_TIMEB 
#include <sys/timeb.h>
#endif


#define RAW_FILE_NAME	"iopipe.raw"
#define HDF5_FILE_NAME	"iopipe.h5"
#define HEADING		"%-16s"
#define PROGRESS	'='

#if 0
/* 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:
 *
 *-------------------------------------------------------------------------
 */
#ifdef H5_HAVE_GETRUSAGE
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)
#else /* H5_HAVE_GETRUSAGE */
static void
print_stats (const char *prefix,
	     struct timeval *r_start, struct timeval *r_stop,
	     struct timeval *t_start, struct timeval *t_stop,
	     size_t nbytes)
#endif /* H5_HAVE_GETRUSAGE */
{
    double	e_time, bw;
#ifdef H5_HAVE_GETRUSAGE
    double	u_time, s_time;

    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);
#endif
#ifndef H5_HAVE_SYS_TIMEB
    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);
#else
    e_time = ((double)(t_stop->tv_sec)+
	      (double)(t_stop->tv_usec)/1000.0) -
	     ((double)(t_start->tv_sec)+
	      (double)(t_start->tv_usec)/1000.0);
#endif
    bw = (double)nbytes / e_time;
    
#ifdef H5_HAVE_GETRUSAGE
    printf (HEADING "%1.2fuser %1.2fsystem %1.2felapsed %1.2fMB/s\n", 
	    prefix, u_time, s_time, e_time, bw/(1024*1024));
#else
    printf (HEADING "%1.2felapsed %1.2fMB/s\n", 
	    prefix, e_time, bw/(1024*1024));
#endif

}


/*-------------------------------------------------------------------------
 * Function:	synchronize
 *
 * Purpose:	
 *
 * Return:	void
 *
 * Programmer:	Robb Matzke
 *              Thursday, March 12, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static void
synchronize (void)
{
#ifdef H5_HAVE_SYSTEM
#ifdef WIN32
#ifdef __WATCOMC__
	flushall();
#else /* __WATCOMC__ */
	_flushall();
#endif /* __WATCOMC__ */
#else
    system ("sync");
    system ("df >/dev/null");
#endif
#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;
#ifdef H5_HAVE_GETRUSAGE
    struct rusage	r_start, r_stop;
#else 
    struct timeval r_start, r_stop;
#endif    
    struct timeval	t_start, t_stop;
    int			i, fd;
    hssize_t		n;
    off_t		offset;
    hssize_t		start[2];
    hsize_t		count[2];


#ifdef H5_HAVE_SYS_TIMEB
	struct _timeb *tbstart = malloc(sizeof(struct _timeb));
	struct _timeb *tbstop = malloc(sizeof(struct _timeb));
#endif
    /*
     * The extra cast in the following statement is a bug workaround for the
     * Win32 version 5.0 compiler.
     * 1998-11-06 ptl
     */
    printf ("I/O request size is %1.1fMB\n",
	    (double)(hssize_t)(size[0]*size[1])/1024.0*1024);
    
    /* Open the files */
    file = H5Fcreate (HDF5_FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    assert (file>=0);
    fd = HDopen (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 ();
#ifdef H5_HAVE_GETRUSAGE
printf("Before getrusage() call\n");
    getrusage (RUSAGE_SELF, &r_start);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_start, NULL);
#else 
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstart);
#endif
#endif   
    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]));
    }
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_stop);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_stop, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstop);
	t_start.tv_sec = tbstart->time;
	t_start.tv_usec = tbstart->millitm;
	t_stop.tv_sec = tbstop->time;
	t_stop.tv_usec = tbstop->millitm;
#endif	
#endif 
    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 ();
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_start);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_start, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstart);
#endif
#endif 
    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);
    }
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_stop);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_stop, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstop);
	t_start.tv_sec = tbstart->time;
	t_start.tv_usec = tbstart->millitm;
	t_stop.tv_sec = tbstop->time;
	t_stop.tv_usec = tbstop->millitm;
#endif	
#endif 
    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 ();
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_start);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_start, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstart);
#endif
#endif 
    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]);
    }
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_stop);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_stop, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstop);
	t_start.tv_sec = tbstart->time;
	t_start.tv_usec = tbstart->millitm;
	t_stop.tv_sec = tbstop->time;
	t_stop.tv_usec = tbstop->millitm;
#endif	
#endif 
    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 ();
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_start);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_start, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstart);
#endif
#endif 
    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);
    }
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_stop);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_stop, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstop);
	t_start.tv_sec = tbstart->time;
	t_start.tv_usec = tbstart->millitm;
	t_stop.tv_sec = tbstop->time;
	t_stop.tv_usec = tbstop->millitm;
#endif	
#endif 
    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 ();
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_start);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_start, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstart);
#endif
#endif 
    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]);
    }
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_stop);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_stop, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstop);
	t_start.tv_sec = tbstart->time;
	t_start.tv_usec = tbstart->millitm;
	t_stop.tv_sec = tbstop->time;
	t_stop.tv_usec = tbstop->millitm;
#endif	
#endif 
    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 ();
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_start);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_start, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstart);
#endif	
#endif 
    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);
    }
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_stop);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_stop, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstop);
	t_start.tv_sec = tbstart->time;
	t_start.tv_usec = tbstart->millitm;
	t_stop.tv_sec = tbstop->time;
	t_stop.tv_usec = tbstop->millitm;
#endif
#endif 
    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 = H5Sselect_hyperslab (file_space, H5S_SELECT_SET, start, NULL, count, NULL);
    assert (status>=0);
    synchronize ();
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_start);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_start, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstart);
#endif	
#endif 
    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);
    }
#ifdef H5_HAVE_GETRUSAGE
    getrusage (RUSAGE_SELF, &r_stop);
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
    gettimeofday (&t_stop, NULL);
#else
#ifdef H5_HAVE_SYS_TIMEB
	_ftime(tbstop);
	t_start.tv_sec = tbstart->time;
	t_start.tv_usec = tbstart->millitm;
	t_stop.tv_sec = tbstop->time;
	t_stop.tv_usec = tbstop->millitm;
#endif	
#endif 
    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 */
    HDclose (fd);
    H5Dclose (dset);
    H5Sclose (file_space);
    H5Fclose (file);
    
    return 0;
}