2018-12-07 06:27:32 +08:00
|
|
|
/*! \file
|
|
|
|
|
|
|
|
Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
|
|
|
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
|
|
|
|
2015, 2016, 2017, 2018
|
|
|
|
University Corporation for Atmospheric Research/Unidata.
|
|
|
|
|
|
|
|
See \ref copyright file for more info.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-05-23 06:50:52 +08:00
|
|
|
/*
|
2018-06-12 21:30:49 +08:00
|
|
|
Create a netcdf-4 file with
|
|
|
|
a large variable for the purpose
|
|
|
|
of doing performance test on the
|
|
|
|
new NC4_get/put_vars functions.
|
2018-05-23 06:50:52 +08:00
|
|
|
|
2018-06-12 21:30:49 +08:00
|
|
|
WARNING: do not attempt to run this
|
|
|
|
under windows because of the use
|
|
|
|
of gettimeofday().
|
2018-05-23 06:50:52 +08:00
|
|
|
|
2018-06-27 05:14:31 +08:00
|
|
|
WARNING: This test can only be run manually
|
|
|
|
and should not be run as part of the testsuite.
|
|
|
|
|
2018-05-23 06:50:52 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include "netcdf.h"
|
2018-06-12 21:30:49 +08:00
|
|
|
#include "nc4dispatch.h"
|
|
|
|
#include "err_macros.h"
|
2018-05-23 06:50:52 +08:00
|
|
|
|
2018-06-12 21:30:49 +08:00
|
|
|
#define FILE "tst_varsperf_bigvars.nc"
|
2018-05-23 06:50:52 +08:00
|
|
|
#define VAR "bigvar"
|
|
|
|
#define NDIMS 2
|
|
|
|
#define DIM0 "d0"
|
|
|
|
#define DIM1 "d1"
|
2018-06-12 21:30:49 +08:00
|
|
|
#define DIMSIZE0 512
|
|
|
|
#define DIMSIZE1 512
|
2018-05-23 06:50:52 +08:00
|
|
|
#define TOTALSIZE (DIMSIZE0*DIMSIZE1)
|
|
|
|
|
|
|
|
static int data[TOTALSIZE];
|
|
|
|
static int read[TOTALSIZE];
|
|
|
|
|
2018-06-12 21:30:49 +08:00
|
|
|
int
|
2018-05-23 06:50:52 +08:00
|
|
|
buildfile(void)
|
|
|
|
{
|
2018-06-12 21:30:49 +08:00
|
|
|
int ncid, varid;
|
|
|
|
int dimids[NDIMS];
|
|
|
|
int* p;
|
|
|
|
int index;
|
2018-05-23 06:50:52 +08:00
|
|
|
|
2018-06-12 21:30:49 +08:00
|
|
|
if(nc_create(FILE, NC_NETCDF4, &ncid)) ERR;
|
2018-05-23 06:50:52 +08:00
|
|
|
|
2018-06-12 21:30:49 +08:00
|
|
|
if(nc_def_dim(ncid,DIM0,(size_t)DIMSIZE0,&dimids[0])) ERR;
|
|
|
|
if(nc_def_dim(ncid,DIM1,(size_t)DIMSIZE1,&dimids[1])) ERR;
|
|
|
|
if(nc_def_var(ncid,VAR,NC_INT,NDIMS,dimids,&varid)) ERR;
|
2018-12-07 06:27:32 +08:00
|
|
|
|
2018-06-12 21:30:49 +08:00
|
|
|
if(nc_enddef(ncid)) ERR;
|
2018-05-23 06:50:52 +08:00
|
|
|
|
2018-06-12 21:30:49 +08:00
|
|
|
for(p=data,index=0;index<TOTALSIZE;index++)
|
2018-12-07 06:27:32 +08:00
|
|
|
*p++ = index;
|
2018-05-23 06:50:52 +08:00
|
|
|
|
2018-06-12 21:30:49 +08:00
|
|
|
if(nc_put_var_int(ncid,varid,data)) ERR;
|
2018-05-23 06:50:52 +08:00
|
|
|
|
2018-06-12 21:30:49 +08:00
|
|
|
if(nc_close(ncid)) ERR;
|
|
|
|
return 0;
|
2018-05-23 06:50:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
long long
|
2018-06-12 21:30:49 +08:00
|
|
|
readfile(int default_vars)
|
2018-05-23 06:50:52 +08:00
|
|
|
{
|
2018-06-12 21:30:49 +08:00
|
|
|
int ncid, varid;
|
|
|
|
int ndims, i;
|
|
|
|
int dimids[NDIMS];
|
|
|
|
size_t dimsizes[NDIMS];
|
|
|
|
int vardims[NDIMS];
|
|
|
|
size_t start[NDIMS];
|
|
|
|
size_t count[NDIMS];
|
|
|
|
ptrdiff_t stride[NDIMS];
|
|
|
|
struct timeval starttime, endtime;
|
|
|
|
long long delta;
|
|
|
|
long long startt, endt;
|
|
|
|
|
|
|
|
memset(&starttime,0,sizeof(starttime));
|
|
|
|
memset(&endtime,0,sizeof(endtime));
|
|
|
|
|
|
|
|
/* re-open to read */
|
|
|
|
if(nc_open(FILE, NC_NETCDF4, &ncid)) ERR;
|
|
|
|
|
|
|
|
if(nc_inq_dimid(ncid,DIM0,&dimids[0])) ERR;
|
|
|
|
if(nc_inq_dimid(ncid,DIM1,&dimids[1])) ERR;
|
|
|
|
if(nc_inq_dim(ncid,dimids[0],NULL,&dimsizes[0])) ERR;
|
|
|
|
if(nc_inq_dim(ncid,dimids[1],NULL,&dimsizes[1])) ERR;
|
|
|
|
if(dimsizes[0] != DIMSIZE0) ERR;
|
|
|
|
if(dimsizes[1] != DIMSIZE1) ERR;
|
|
|
|
|
|
|
|
if(nc_inq_varid(ncid,VAR,&varid)) ERR;
|
|
|
|
if(nc_inq_varndims(ncid,varid,&ndims)) ERR;
|
|
|
|
if(ndims != NDIMS) ERR;
|
|
|
|
if(nc_inq_vardimid(ncid,varid,vardims)) ERR;
|
|
|
|
for(i=0;i<NDIMS;i++)
|
|
|
|
if (vardims[i] != dimids[i]) ERR;
|
|
|
|
|
|
|
|
/* Do the timed read */
|
|
|
|
for(i=0;i<NDIMS;i++) {
|
|
|
|
start[i] = 0;
|
|
|
|
count[i] = dimsizes[i]/2;
|
|
|
|
stride[i] = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(read,0,sizeof(read));
|
|
|
|
gettimeofday(&starttime,NULL);
|
|
|
|
|
|
|
|
if(default_vars) {
|
|
|
|
if(NCDEFAULT_get_vars(ncid,varid,start,count,stride,read,NC_INT)) ERR;
|
|
|
|
} else {
|
|
|
|
if(NC4_get_vars(ncid,varid,start,count,stride,read,NC_INT)) ERR;
|
|
|
|
}
|
|
|
|
gettimeofday(&endtime,NULL);
|
|
|
|
|
|
|
|
if(nc_close(ncid)) ERR;
|
|
|
|
|
|
|
|
/* Verify read -- Note: NDIMS dependent */
|
|
|
|
{
|
|
|
|
int d0, d1;
|
|
|
|
i = 0;
|
|
|
|
for(d0=0;d0<DIMSIZE0;d0+=stride[0]) {
|
|
|
|
for(d1=0;d1<DIMSIZE1;d1+=stride[1]) {
|
|
|
|
size_t dataindex = (d0 * DIMSIZE0) + d1;
|
|
|
|
size_t readindex = i;
|
|
|
|
if (data[dataindex] != read[readindex])
|
|
|
|
return -1;
|
|
|
|
i++;
|
2018-12-07 06:27:32 +08:00
|
|
|
}
|
2018-06-12 21:30:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the time delta */
|
|
|
|
startt = (1000000*starttime.tv_sec) + starttime.tv_usec;
|
|
|
|
endt = (1000000*endtime.tv_sec) + endtime.tv_usec;
|
|
|
|
delta = endt - startt;
|
|
|
|
return delta;
|
2018-05-23 06:50:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2018-06-12 21:30:49 +08:00
|
|
|
long long defaultdelta, nc4delta, factor;
|
|
|
|
|
|
|
|
printf("testing speed of vars improvements...\n");
|
|
|
|
if (buildfile()) ERR;
|
|
|
|
if ((defaultdelta = readfile(1)) == -1)
|
|
|
|
return 1;
|
|
|
|
if ((nc4delta = readfile(0)) == -1)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Print results to the millisec */
|
2018-12-07 06:27:32 +08:00
|
|
|
factor = defaultdelta / nc4delta;
|
2018-06-12 21:30:49 +08:00
|
|
|
printf("NCDEFAULT time=%lld NC4 time=%lld Speedup=%lld\n",
|
|
|
|
defaultdelta, nc4delta, factor);
|
|
|
|
SUMMARIZE_ERR;
|
|
|
|
FINAL_RESULTS;
|
2018-05-23 06:50:52 +08:00
|
|
|
}
|