mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-02-17 16:50:18 +08:00
took out repeated definitions of timeval_subtract function
This commit is contained in:
parent
922ed6a303
commit
7a2774c8d1
@ -48,7 +48,14 @@ check_PROGRAMS += tst_create_files bm_file tst_chunks3 tst_ar4 \
|
||||
tst_ar4_3d tst_ar4_4d bm_many_objs tst_h_many_atts bm_many_atts \
|
||||
tst_files2 tst_files3 tst_ar5 tst_h_files3 tst_mem tst_knmi
|
||||
|
||||
bm_many_atts_SOURCES = bm_many_atts.c tst_utils.c
|
||||
bm_many_objs_SOURCES = bm_many_objs.c tst_utils.c
|
||||
tst_ar4_3d_SOURCES = tst_ar4_3d.c tst_utils.c
|
||||
tst_ar4_4d_SOURCES = tst_ar4_4d.c tst_utils.c
|
||||
tst_files2_SOURCES = tst_files2.c tst_utils.c
|
||||
tst_ar4_SOURCES = tst_ar4.c tst_utils.c
|
||||
tst_h_many_atts_SOURCES = tst_h_many_atts.c tst_utils.c
|
||||
bm_file_SOURCES = bm_file.c tst_utils.c
|
||||
tst_knmi_SOURCES = tst_knmi.c tst_utils.c
|
||||
TESTS += tst_ar4_3d tst_create_files run_bm_test1.sh run_bm_elena.sh \
|
||||
run_bm_test2.sh run_tst_chunks.sh run_bm_ar4.sh tst_files2 tst_files3 \
|
||||
|
@ -192,33 +192,6 @@ file_size(char* name)
|
||||
return stbuf.st_size;
|
||||
}
|
||||
|
||||
/* Subtract the `struct timeval' values X and Y, storing the result in
|
||||
RESULT. Return 1 if the difference is negative, otherwise 0. This
|
||||
function from the GNU documentation. */
|
||||
static int
|
||||
timeval_subtract (result, x, y)
|
||||
struct timeval *result, *x, *y;
|
||||
{
|
||||
/* Perform the carry for the later subtraction by updating Y. */
|
||||
if (x->tv_usec < y->tv_usec) {
|
||||
int nsec = (y->tv_usec - x->tv_usec) / MILLION + 1;
|
||||
y->tv_usec -= MILLION * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
if (x->tv_usec - y->tv_usec > MILLION) {
|
||||
int nsec = (x->tv_usec - y->tv_usec) / MILLION;
|
||||
y->tv_usec += MILLION * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
|
||||
/* Compute the time remaining to wait.
|
||||
`tv_usec' is certainly positive. */
|
||||
result->tv_sec = x->tv_sec - y->tv_sec;
|
||||
result->tv_usec = x->tv_usec - y->tv_usec;
|
||||
|
||||
/* Return 1 if result is negative. */
|
||||
return x->tv_sec < y->tv_sec;
|
||||
}
|
||||
|
||||
/* Check attribute number a of variable varid in copied file ncid2 to ensure
|
||||
* it is the same as the corresponding attribute in original file ncid1. */
|
||||
@ -325,7 +298,7 @@ cmp_file(char *file1, char *file2, int *meta_read_us, int *data_read_us,
|
||||
if ((ret = nc_open(file2, 0, &ncid2)))
|
||||
ERR1(ret);
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
*meta_read_us += (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
||||
}
|
||||
if (verbose)
|
||||
@ -449,7 +422,7 @@ cmp_file(char *file1, char *file2, int *meta_read_us, int *data_read_us,
|
||||
*data_read_us += (MPI_Wtime() - ftime) * MILLION;
|
||||
#else
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
*data_read_us += (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
||||
#endif
|
||||
if (verbose)
|
||||
@ -521,7 +494,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
|
||||
if ((ret = nc_open(file_name_in, 0, &ncid_in)))
|
||||
ERR1(ret);
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
*meta_read_us += (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
||||
}
|
||||
if (verbose)
|
||||
@ -649,7 +622,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
|
||||
*meta_write_us += (MPI_Wtime() - ftime) * MILLION;
|
||||
#else
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
*meta_write_us += (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
||||
#endif
|
||||
|
||||
@ -754,7 +727,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
|
||||
*data_read_us += (MPI_Wtime() - ftime) * MILLION;
|
||||
#else
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
*data_read_us += (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
||||
#endif
|
||||
if (verbose)
|
||||
@ -775,7 +748,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
|
||||
*data_write_us += (MPI_Wtime() - ftime) * MILLION;
|
||||
#else
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
*data_write_us += (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
||||
#endif
|
||||
if (verbose)
|
||||
|
@ -18,35 +18,6 @@ $Id $
|
||||
/* We will create this file. */
|
||||
#define FILE_NAME "bm_many_atts.nc"
|
||||
|
||||
/* Subtract the `struct timeval' values X and Y, storing the result in
|
||||
RESULT. Return 1 if the difference is negative, otherwise 0. This
|
||||
function from the GNU documentation. */
|
||||
int
|
||||
timeval_subtract (result, x, y)
|
||||
struct timeval *result, *x, *y;
|
||||
{
|
||||
/* Perform the carry for the later subtraction by updating Y. */
|
||||
if (x->tv_usec < y->tv_usec) {
|
||||
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
|
||||
y->tv_usec -= 1000000 * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
if (x->tv_usec - y->tv_usec > 1000000) {
|
||||
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
|
||||
y->tv_usec += 1000000 * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
|
||||
/* Compute the time remaining to wait.
|
||||
`tv_usec' is certainly positive. */
|
||||
result->tv_sec = x->tv_sec - y->tv_sec;
|
||||
result->tv_usec = x->tv_usec - y->tv_usec;
|
||||
|
||||
/* Return 1 if result is negative. */
|
||||
return x->tv_sec < y->tv_sec;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct timeval start_time, end_time, diff_time;
|
||||
@ -91,7 +62,7 @@ int main(int argc, char **argv)
|
||||
if (nc_put_att_int(grp, NC_GLOBAL, aname, NC_INT, 1, data)) ERR;
|
||||
if(a%100 == 0) { /* only print every 100th attribute name */
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
sec = diff_time.tv_sec + 1.0e-6 * diff_time.tv_usec;
|
||||
printf("%s/%s\t%.3g sec\n", gname, aname, sec);
|
||||
}
|
||||
|
@ -67,35 +67,6 @@ variables:
|
||||
pr:cell_method = "time: mean" ;
|
||||
|
||||
*/
|
||||
|
||||
/* Subtract the `struct timeval' values X and Y, storing the result in
|
||||
RESULT. Return 1 if the difference is negative, otherwise 0. This
|
||||
function from the GNU documentation. */
|
||||
static int
|
||||
timeval_subtract (result, x, y)
|
||||
struct timeval *result, *x, *y;
|
||||
{
|
||||
/* Perform the carry for the later subtraction by updating Y. */
|
||||
if (x->tv_usec < y->tv_usec) {
|
||||
int nsec = (y->tv_usec - x->tv_usec) / MILLION + 1;
|
||||
y->tv_usec -= MILLION * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
if (x->tv_usec - y->tv_usec > MILLION) {
|
||||
int nsec = (x->tv_usec - y->tv_usec) / MILLION;
|
||||
y->tv_usec += MILLION * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
|
||||
/* Compute the time remaining to wait.
|
||||
`tv_usec' is certainly positive. */
|
||||
result->tv_sec = x->tv_sec - y->tv_sec;
|
||||
result->tv_usec = x->tv_usec - y->tv_usec;
|
||||
|
||||
/* Return 1 if result is negative. */
|
||||
return x->tv_sec < y->tv_sec;
|
||||
}
|
||||
|
||||
#define USAGE "\
|
||||
[-v] Verbose\n\
|
||||
[-h] Print output header\n\
|
||||
@ -222,7 +193,7 @@ main(int argc, char **argv)
|
||||
if (gettimeofday(&start_time, NULL)) ERR;
|
||||
if (nc_get_vara_float(ncid, varid, start, count, ts_data)) ERR_RET;
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
read_1_us = (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
||||
|
||||
/* Read all the rest. */
|
||||
@ -231,7 +202,7 @@ main(int argc, char **argv)
|
||||
for (start[2] = 1; start[2] < LON_LEN; start[2]++)
|
||||
if (nc_get_vara_float(ncid, varid, start, count, ts_data)) ERR_RET;
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
avg_read_us = ((int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec + read_1_us) /
|
||||
(LAT_LEN * LON_LEN);
|
||||
}
|
||||
@ -249,7 +220,7 @@ main(int argc, char **argv)
|
||||
if (gettimeofday(&start_time, NULL)) ERR;
|
||||
if (nc_get_vara_float(ncid, varid, start, count, hor_data)) ERR_RET;
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
read_1_us = (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
||||
|
||||
/* Read (and time) all the rest. */
|
||||
@ -257,7 +228,7 @@ main(int argc, char **argv)
|
||||
for (start[0] = 1; start[0] < TIME_LEN; start[0]++)
|
||||
if (nc_get_vara_float(ncid, varid, start, count, hor_data)) ERR_RET;
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
avg_read_us = ((int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec +
|
||||
read_1_us) / TIME_LEN;
|
||||
}
|
||||
|
@ -19,34 +19,6 @@
|
||||
|
||||
void *last_sbrk;
|
||||
|
||||
/* Subtract the `struct timeval' values X and Y, storing the result in
|
||||
RESULT. Return 1 if the difference is negative, otherwise 0. This
|
||||
function from the GNU documentation. */
|
||||
static int
|
||||
timeval_subtract (result, x, y)
|
||||
struct timeval *result, *x, *y;
|
||||
{
|
||||
/* Perform the carry for the later subtraction by updating Y. */
|
||||
if (x->tv_usec < y->tv_usec) {
|
||||
int nsec = (y->tv_usec - x->tv_usec) / MILLION + 1;
|
||||
y->tv_usec -= MILLION * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
if (x->tv_usec - y->tv_usec > MILLION) {
|
||||
int nsec = (x->tv_usec - y->tv_usec) / MILLION;
|
||||
y->tv_usec += MILLION * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
|
||||
/* Compute the time remaining to wait.
|
||||
`tv_usec' is certainly positive. */
|
||||
result->tv_sec = x->tv_sec - y->tv_sec;
|
||||
result->tv_usec = x->tv_usec - y->tv_usec;
|
||||
|
||||
/* Return 1 if result is negative. */
|
||||
return x->tv_sec < y->tv_sec;
|
||||
}
|
||||
|
||||
/* This function uses the ps command to find the amount of memory in
|
||||
use by the process. From the ps man page:
|
||||
|
||||
@ -249,7 +221,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* How long did it take? */
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
create_us = ((int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec);
|
||||
|
||||
/* Change the cache settings. */
|
||||
@ -274,7 +246,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* How long did it take per file? */
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
open_us = ((int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec);
|
||||
|
||||
/* How much memory is in use by this process now? */
|
||||
@ -287,7 +259,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* How long did it take to close all files? */
|
||||
if (gettimeofday(&close_end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&close_diff_time, &close_end_time, &close_start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&close_diff_time, &close_end_time, &close_start_time)) ERR;
|
||||
close_us = ((int)close_diff_time.tv_sec * MILLION + (int)close_diff_time.tv_usec);
|
||||
|
||||
/* We're done with this. */
|
||||
|
@ -19,34 +19,6 @@
|
||||
#define FILE_NAME "tst_h_many_atts.h5"
|
||||
#define GRP_NAME "group1"
|
||||
|
||||
/* Subtract the `struct timeval' values X and Y, storing the result in
|
||||
RESULT. Return 1 if the difference is negative, otherwise 0. This
|
||||
function from the GNU documentation. */
|
||||
int
|
||||
timeval_subtract (result, x, y)
|
||||
struct timeval *result, *x, *y;
|
||||
{
|
||||
/* Perform the carry for the later subtraction by updating Y. */
|
||||
if (x->tv_usec < y->tv_usec) {
|
||||
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
|
||||
y->tv_usec -= 1000000 * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
if (x->tv_usec - y->tv_usec > 1000000) {
|
||||
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
|
||||
y->tv_usec += 1000000 * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
|
||||
/* Compute the time remaining to wait.
|
||||
`tv_usec' is certainly positive. */
|
||||
result->tv_sec = x->tv_sec - y->tv_sec;
|
||||
result->tv_usec = x->tv_usec - y->tv_usec;
|
||||
|
||||
/* Return 1 if result is negative. */
|
||||
return x->tv_sec < y->tv_sec;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -88,7 +60,7 @@ main()
|
||||
if((i + 1) % 1000 == 0)
|
||||
{ /* only print every 1000th attribute name */
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
sec = diff_time.tv_sec + 1.0e-6 * diff_time.tv_usec;
|
||||
printf("%i\t%.3g sec\n", i + 1, sec);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user