mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
d2316f866c
Primary Fixes: * Add a whole variable optimization -- used in the rare case that nc_get/put_vara covers the whole of a variable and the variable has a single chunk. * Fix chunking error when stride causes whole chunks to be skipped. * Fix some memory leaks * Add test cases * Add one performance test to nczarr_test/. This uses the timer utils from unit_test: timer_utils.[ch]. * Move ncdumpchunks utility from ncdump to nczarr_test Misc. Other Changes: * Make check for aws libraries conditional on --enable-nczarr-s3 * Remove all but one bm tests from nczarr_test until they are working. * Remove another dependency on HDF5 from supposedly non-HDF5 specific code; specifically hdf5_log_hdf5. * Make the BAIL2 macro be hdf5 specific and replace elsewhere with an HDF5 independent equivalent. * Move hdf5cache.c to libsrc4/nc4cache.c because it is used by nczarr. * Modify unit_tests so that some of them are run even if using Windows. * Misc. small bug fixes and refactors and memory leaks. * Rename some conflicting tests for cmake. * Attempted to make nc_perf work with cmake and failed.
115 lines
3.4 KiB
C
115 lines
3.4 KiB
C
/* This is part of the netCDF package. Copyright 2018 University
|
|
Corporation for Atmospheric Research/Unidata See COPYRIGHT file for
|
|
conditions of use. See www.unidata.ucar.edu for more info.
|
|
|
|
This program benchmarks creating a netCDF file with many objects.
|
|
|
|
Ed Hartnett
|
|
*/
|
|
|
|
#include <config.h>
|
|
#include <nc_tests.h>
|
|
#include "err_macros.h"
|
|
#include <netcdf.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <sys/time.h> /* Extra high precision time info. */
|
|
|
|
#include "bm_utils.h"
|
|
|
|
/* We will create this file. */
|
|
#define FILE_NAME "bm_many_objs.nc"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int stat = NC_NOERR;
|
|
long long delta;
|
|
time_t starttime, endtime;
|
|
struct timeval start_time, end_time, diff_time;
|
|
double sec;
|
|
int ncid;
|
|
int data[] = {42};
|
|
int g, grp;
|
|
char gname[16];
|
|
char* path = NULL;
|
|
int var, v, vleft, vn, numgrp, nvars;
|
|
|
|
NCCHECK(getoptions(&argc,&argv,&bmoptions));
|
|
NCCHECK(nc4_buildpath(&bmoptions,&path));
|
|
|
|
if(bmoptions.debug) {
|
|
reportoptions(&bmoptions);
|
|
reportmetaoptions(&bmoptions.meta);
|
|
}
|
|
|
|
starttime = 0;
|
|
endtime = 0;
|
|
time(&starttime);
|
|
|
|
/* create new file */
|
|
if (nc_create(path, NC_NETCDF4, &ncid)) ERR;
|
|
|
|
if (gettimeofday(&start_time, NULL))
|
|
ERR;
|
|
|
|
/* create N groups, printing time after every 1000 */
|
|
for(g = 1; g < bmoptions.meta.ngroups + 1; g++) {
|
|
sprintf(gname, "group%d", g);
|
|
if (nc_def_grp(ncid, gname, &grp)) ERR;
|
|
if (nc_def_var(grp, "var", NC_INT, 0, NULL, &var)) ERR;
|
|
if(nc_enddef (grp)) ERR;
|
|
if((stat=nc_put_var(grp, var, data)))
|
|
ERR;
|
|
if(g%1000 == 0) { /* only print every 1000th group name */
|
|
if (gettimeofday(&end_time, NULL)) 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\t%.3g sec\n", gname, sec);
|
|
}
|
|
}
|
|
nc_close(ncid);
|
|
|
|
/* create new file */
|
|
if (nc_create(path, NC_NETCDF4, &ncid)) ERR;
|
|
/* create N variables, printing time after every 1000.
|
|
* Put NC_MAX_VARS variables per group (even though netcdf4 non-classic
|
|
* format does not limit variable count), create the necessary number
|
|
* of groups to hold nitem variables. */
|
|
v = 1;
|
|
numgrp = (bmoptions.meta.nvars - 1) / NC_MAX_VARS + 1;
|
|
vleft = bmoptions.meta.nvars - (NC_MAX_VARS * (numgrp - 1));
|
|
if (gettimeofday(&start_time, NULL))
|
|
ERR;
|
|
|
|
for(g = 1; g < numgrp + 1; g++) {
|
|
sprintf(gname, "group%d", g);
|
|
if (nc_def_grp(ncid, gname, &grp)) ERR;
|
|
nvars = g < numgrp ? NC_MAX_VARS : vleft; /* leftovers on last time through */
|
|
for(vn = 1; vn < nvars + 1; vn++) {
|
|
int var;
|
|
char vname[20];
|
|
sprintf(vname, "variable%d", v);
|
|
if(nc_def_var(grp, vname, NC_INT, 0, NULL, &var)) ERR;
|
|
if(nc_put_var(grp, var, data)) ERR;
|
|
if(v%1000 == 0) { /* only print every 1000th variable name */
|
|
if (gettimeofday(&end_time, NULL)) 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, vname, sec);
|
|
}
|
|
v++;
|
|
}
|
|
}
|
|
nc_close(ncid);
|
|
|
|
time(&endtime);
|
|
/* Compute the delta 1 second resolution is fine for this */
|
|
delta = (long long)(endtime - starttime);
|
|
printf("delta.create.%s = %lld\n",formatname(&bmoptions),delta);
|
|
|
|
nullfree(path);
|
|
clearoptions(&bmoptions);
|
|
FINAL_RESULTS;
|
|
}
|