2011-04-18 02:56:10 +08:00
|
|
|
/*********************************************************************
|
|
|
|
* Copyright 1993, UCAR/Unidata
|
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
*********************************************************************/
|
2013-07-28 04:54:50 +08:00
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
#include "ncdap.h"
|
2011-04-18 02:56:10 +08:00
|
|
|
#include "dapdump.h"
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
static int iscacheableconstraint(DCEconstraint* con);
|
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
/* Return 1 if we can reuse cached data to address
|
|
|
|
the current get_vara request; return 0 otherwise.
|
|
|
|
Target is in the constrained tree space.
|
|
|
|
Currently, if the target matches a cache that is not
|
|
|
|
a whole variable, then match is false.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iscached(NCDAPCOMMON* nccomm, CDFnode* target, NCcachenode** cachenodep)
|
|
|
|
{
|
|
|
|
int i,j,found,index;
|
|
|
|
NCcache* cache;
|
|
|
|
NCcachenode* cachenode;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
if(target == NULL) goto done;
|
|
|
|
|
|
|
|
/* Match the target variable against the prefetch, if any */
|
|
|
|
/* Note that prefetches are always whole variable */
|
|
|
|
cache = nccomm->cdf.cache;
|
|
|
|
cachenode = cache->prefetch;
|
|
|
|
if(cachenode!= NULL) {
|
|
|
|
for(found=0,i=0;i<nclistlength(cachenode->vars);i++) {
|
|
|
|
CDFnode* var = (CDFnode*)nclistget(cachenode->vars,i);
|
|
|
|
if(var == target) {
|
|
|
|
if(cachenodep) *cachenodep = cachenode;
|
|
|
|
found=1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*search other cache nodes starting at latest first */
|
|
|
|
index = 0;
|
|
|
|
for(i=nclistlength(cache->nodes)-1;i>=0;i--) {
|
|
|
|
cachenode = (NCcachenode*)nclistget(cache->nodes,i);
|
|
|
|
/* We currently do not try to match constraints;
|
2011-11-14 12:20:19 +08:00
|
|
|
If the cachenode is constrained by more than
|
|
|
|
simple wholevariable projections, then skip it.
|
2011-04-18 02:56:10 +08:00
|
|
|
*/
|
|
|
|
if(!cachenode->wholevariable) continue;
|
|
|
|
for(found=0,j=0;j<nclistlength(cachenode->vars);j++) {
|
|
|
|
CDFnode* var = (CDFnode*)nclistget(cachenode->vars,j);
|
|
|
|
if(var == target) {found=1;index=i;break;}
|
|
|
|
}
|
|
|
|
if(found) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(found) {
|
|
|
|
ASSERT((cachenode != NULL));
|
|
|
|
if(nclistlength(cache->nodes) > 1) {
|
|
|
|
/* Manage the cache nodes as LRU */
|
|
|
|
nclistremove(cache->nodes,index);
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(cache->nodes,(void*)cachenode);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
if(cachenodep) *cachenodep = cachenode;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
#ifdef DEBUG
|
2014-03-25 04:02:52 +08:00
|
|
|
fprintf(stderr,"iscached: search: %s\n",makecdfpathstring(target,"."));
|
2011-04-18 02:56:10 +08:00
|
|
|
if(found)
|
|
|
|
fprintf(stderr,"iscached: found: %s\n",dumpcachenode(cachenode));
|
|
|
|
else
|
|
|
|
fprintf(stderr,"iscached: notfound\n");
|
|
|
|
#endif
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2012-01-30 02:56:29 +08:00
|
|
|
/* Compute the set of prefetched data.
|
|
|
|
Notes:
|
2013-03-03 12:06:43 +08:00
|
|
|
1. All prefetches are whole variable fetches.
|
|
|
|
2. If the data set is unconstrainable, we
|
2012-01-30 02:56:29 +08:00
|
|
|
will prefetch the whole thing
|
2011-04-18 02:56:10 +08:00
|
|
|
*/
|
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
prefetchdata(NCDAPCOMMON* nccomm)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2013-03-13 04:45:58 +08:00
|
|
|
int i;
|
2013-07-28 04:20:13 +08:00
|
|
|
NCFLAGS flags;
|
2011-04-18 02:56:10 +08:00
|
|
|
NCerror ncstat = NC_NOERR;
|
2013-03-03 12:06:43 +08:00
|
|
|
NClist* allvars = nccomm->cdf.ddsroot->tree->varnodes;
|
2011-11-14 12:20:19 +08:00
|
|
|
DCEconstraint* urlconstraint = nccomm->oc.dapconstraint;
|
2011-04-18 02:56:10 +08:00
|
|
|
NClist* vars = nclistnew();
|
|
|
|
NCcachenode* cache = NULL;
|
|
|
|
DCEconstraint* newconstraint = NULL;
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
if(FLAGSET(nccomm->controls,NCF_UNCONSTRAINABLE)) {
|
|
|
|
/* If we cannot constrain and caching is enabled,
|
|
|
|
then pull in everything */
|
2013-05-02 06:31:01 +08:00
|
|
|
if(FLAGSET(nccomm->controls,NCF_CACHE)) {
|
2011-11-14 12:20:19 +08:00
|
|
|
for(i=0;i<nclistlength(allvars);i++) {
|
|
|
|
nclistpush(vars,nclistget(allvars,i));
|
|
|
|
}
|
|
|
|
} else { /* do no prefetching */
|
|
|
|
nccomm->cdf.cache->prefetch = NULL;
|
|
|
|
goto done;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
2013-03-03 12:06:43 +08:00
|
|
|
} else {
|
|
|
|
/* pull in those variables previously marked as prefetchable */
|
2011-04-18 02:56:10 +08:00
|
|
|
for(i=0;i<nclistlength(allvars);i++) {
|
|
|
|
CDFnode* var = (CDFnode*)nclistget(allvars,i);
|
2011-11-14 12:20:19 +08:00
|
|
|
|
2013-03-03 12:06:43 +08:00
|
|
|
/* Most of the important testing was already done */
|
|
|
|
if(!var->basenode->prefetchable)
|
|
|
|
continue;
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Do not attempt to prefetch any variables in the
|
|
|
|
nc_open url's projection list
|
|
|
|
*/
|
2012-08-20 05:12:35 +08:00
|
|
|
if(nclistcontains(nccomm->cdf.projectedvars,(void*)var))
|
2012-08-01 04:34:13 +08:00
|
|
|
continue;
|
|
|
|
|
2013-03-03 12:06:43 +08:00
|
|
|
/* Should be prefetchable */
|
2013-07-28 04:20:13 +08:00
|
|
|
nclistpush(vars,(void*)var);
|
2012-01-30 02:56:29 +08:00
|
|
|
if(SHOWFETCH) {
|
|
|
|
nclog(NCLOGDBG,"prefetch: %s",var->ncfullname);
|
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there are no vars, then do nothing */
|
|
|
|
if(nclistlength(vars) == 0) {
|
|
|
|
nccomm->cdf.cache->prefetch = NULL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
/* Create a single constraint consisting of the projections for the variables;
|
|
|
|
each projection is whole variable. The selections are passed on as is.
|
2013-07-28 04:20:13 +08:00
|
|
|
The exception is if we are prefetching everything.
|
2011-11-14 12:20:19 +08:00
|
|
|
*/
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
newconstraint = (DCEconstraint*)dcecreate(CES_CONSTRAINT);
|
|
|
|
newconstraint->projections = nclistnew();
|
|
|
|
newconstraint->selections = dceclonelist(urlconstraint->selections);
|
|
|
|
|
|
|
|
for(i=0;i<nclistlength(vars);i++) {
|
2013-07-28 04:20:13 +08:00
|
|
|
CDFnode* var = (CDFnode*)nclistget(vars,i);
|
2011-11-14 12:20:19 +08:00
|
|
|
DCEprojection* varprojection;
|
|
|
|
/* convert var to a projection */
|
|
|
|
ncstat = dapvar2projection(var,&varprojection);
|
|
|
|
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;}
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(newconstraint->projections,(void*)varprojection);
|
2011-11-14 12:20:19 +08:00
|
|
|
}
|
2012-01-30 02:56:29 +08:00
|
|
|
if(SHOWFETCH) {
|
|
|
|
char* s = dumpprojections(newconstraint->projections);
|
|
|
|
LOG1(NCLOGNOTE,"prefetch.final: %s",s);
|
|
|
|
nullfree(s);
|
|
|
|
}
|
2013-07-28 04:20:13 +08:00
|
|
|
|
|
|
|
flags = NCF_PREFETCH;
|
|
|
|
if(nclistlength(allvars) == nclistlength(vars)) flags |= NCF_PREFETCH_ALL;
|
2014-03-25 04:02:52 +08:00
|
|
|
ncstat = buildcachenode(nccomm,newconstraint,vars,&cache,flags);
|
|
|
|
newconstraint = NULL; /* buildcachenodetakes control of newconstraint */
|
2013-11-23 04:49:21 +08:00
|
|
|
if(ncstat != OC_NOERR) goto done;
|
|
|
|
else if(cache == NULL) goto done;
|
2013-11-21 04:37:21 +08:00
|
|
|
else
|
|
|
|
cache->wholevariable = 1; /* All prefetches are whole variable */
|
2011-11-14 12:20:19 +08:00
|
|
|
/* Make cache node be the prefetch node */
|
|
|
|
nccomm->cdf.cache->prefetch = cache;
|
2012-01-30 02:56:29 +08:00
|
|
|
if(SHOWFETCH) {
|
|
|
|
LOG0(NCLOGNOTE,"prefetch.complete");
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2012-01-30 02:56:29 +08:00
|
|
|
if(SHOWFETCH) {
|
|
|
|
char* s = NULL;
|
2011-04-18 02:56:10 +08:00
|
|
|
/* Log the set of prefetch variables */
|
|
|
|
NCbytes* buf = ncbytesnew();
|
|
|
|
ncbytescat(buf,"prefetch.vars: ");
|
|
|
|
for(i=0;i<nclistlength(vars);i++) {
|
|
|
|
CDFnode* var = (CDFnode*)nclistget(vars,i);
|
|
|
|
ncbytescat(buf," ");
|
2014-03-25 04:02:52 +08:00
|
|
|
s = makecdfpathstring(var,".");
|
2012-01-30 02:56:29 +08:00
|
|
|
ncbytescat(buf,s);
|
|
|
|
nullfree(s);
|
2013-03-03 12:06:43 +08:00
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
ncbytescat(buf,"\n");
|
|
|
|
nclog(NCLOGNOTE,"%s",ncbytescontents(buf));
|
|
|
|
ncbytesfree(buf);
|
2013-03-03 12:06:43 +08:00
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
nclistfree(vars);
|
|
|
|
dcefree((DCEnode*)newconstraint);
|
2013-11-21 04:37:21 +08:00
|
|
|
if(ncstat && cache != NULL) freenccachenode(nccomm,cache);
|
2011-04-18 02:56:10 +08:00
|
|
|
return THROW(ncstat);
|
|
|
|
}
|
|
|
|
|
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
buildcachenode(NCDAPCOMMON* nccomm,
|
2012-01-30 02:56:29 +08:00
|
|
|
DCEconstraint* constraint,
|
2011-04-18 02:56:10 +08:00
|
|
|
NClist* varlist,
|
|
|
|
NCcachenode** cachep,
|
2013-07-28 04:20:13 +08:00
|
|
|
NCFLAGS flags)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
NCerror ncstat = NC_NOERR;
|
|
|
|
OCerror ocstat = OC_NOERR;
|
2012-08-01 04:34:13 +08:00
|
|
|
OClink conn = nccomm->oc.conn;
|
|
|
|
OCddsnode ocroot = NULL;
|
2011-04-18 02:56:10 +08:00
|
|
|
CDFnode* dxdroot = NULL;
|
|
|
|
NCcachenode* cachenode = NULL;
|
|
|
|
char* ce = NULL;
|
2013-07-28 04:20:13 +08:00
|
|
|
int isprefetch = 0;
|
|
|
|
|
|
|
|
if((flags & NCF_PREFETCH) != 0)
|
|
|
|
isprefetch = 1;
|
2011-11-14 12:20:19 +08:00
|
|
|
|
2013-07-28 04:20:13 +08:00
|
|
|
if((flags & NCF_PREFETCH_ALL) == 0)
|
2014-03-25 04:02:52 +08:00
|
|
|
ce = buildconstraintstring(constraint);
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2014-03-12 01:58:22 +08:00
|
|
|
ncstat = dap_fetch(nccomm,conn,ce,OCDATADDS,&ocroot);
|
2011-04-18 02:56:10 +08:00
|
|
|
nullfree(ce);
|
2014-03-12 01:58:22 +08:00
|
|
|
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;}
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
ncstat = buildcdftree(nccomm,ocroot,OCDATA,&dxdroot);
|
2011-04-18 02:56:10 +08:00
|
|
|
if(ncstat) {THROWCHK(ncstat); goto done;}
|
|
|
|
|
2012-08-16 01:55:25 +08:00
|
|
|
/* re-struct*/
|
2011-04-18 02:56:10 +08:00
|
|
|
if(!FLAGSET(nccomm->controls,NCF_UNCONSTRAINABLE)) {
|
2014-03-25 04:02:52 +08:00
|
|
|
ncstat = restruct(nccomm,dxdroot,nccomm->cdf.fullddsroot,
|
2014-02-06 08:05:33 +08:00
|
|
|
constraint->projections);
|
2011-04-18 02:56:10 +08:00
|
|
|
if(ncstat) {THROWCHK(ncstat); goto done;}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the cache node */
|
|
|
|
cachenode = createnccachenode();
|
2013-07-28 04:20:13 +08:00
|
|
|
cachenode->isprefetch = isprefetch;
|
2011-04-18 02:56:10 +08:00
|
|
|
cachenode->vars = nclistclone(varlist);
|
|
|
|
cachenode->datadds = dxdroot;
|
2011-11-14 12:20:19 +08:00
|
|
|
/* Give the constraint over to the cachenode */
|
2011-04-18 02:56:10 +08:00
|
|
|
cachenode->constraint = constraint;
|
2011-11-14 12:20:19 +08:00
|
|
|
constraint = NULL;
|
|
|
|
cachenode->wholevariable = iscacheableconstraint(cachenode->constraint);
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
/* save the root content*/
|
|
|
|
cachenode->ocroot = ocroot;
|
2012-08-01 04:34:13 +08:00
|
|
|
ocstat = oc_data_getroot(conn,ocroot,&cachenode->content);
|
2011-04-18 02:56:10 +08:00
|
|
|
if(ocstat) {THROWCHK(ocerrtoncerr(ocstat)); goto done;}
|
|
|
|
|
|
|
|
/* capture the packet size */
|
|
|
|
ocstat = oc_raw_xdrsize(conn,ocroot,&cachenode->xdrsize);
|
|
|
|
if(ocstat) {THROWCHK(ocerrtoncerr(ocstat)); goto done;}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"buildcachenode: new cache node: %s\n",
|
|
|
|
dumpcachenode(cachenode));
|
|
|
|
#endif
|
|
|
|
/* Insert into the cache. If not caching, then
|
|
|
|
remove any previous cache node
|
|
|
|
*/
|
|
|
|
if(!isprefetch) {
|
|
|
|
NCcache* cache = nccomm->cdf.cache;
|
|
|
|
if(cache->nodes == NULL) cache->nodes = nclistnew();
|
|
|
|
/* remove cache nodes to get below the max cache size */
|
2011-06-26 06:08:32 +08:00
|
|
|
while(cache->cachesize + cachenode->xdrsize > cache->cachelimit
|
|
|
|
&& nclistlength(cache->nodes) > 0) {
|
2011-04-18 02:56:10 +08:00
|
|
|
NCcachenode* node = (NCcachenode*)nclistremove(cache->nodes,0);
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"buildcachenode: purge cache node: %s\n",
|
|
|
|
dumpcachenode(cachenode));
|
|
|
|
#endif
|
|
|
|
cache->cachesize -= node->xdrsize;
|
|
|
|
freenccachenode(nccomm,node);
|
|
|
|
}
|
|
|
|
/* Remove cache nodes to get below the max cache count */
|
|
|
|
/* If not caching, then cachecount should be 0 */
|
|
|
|
while(nclistlength(cache->nodes) > cache->cachecount) {
|
|
|
|
NCcachenode* node = (NCcachenode*)nclistremove(cache->nodes,0);
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"buildcachenode: count purge cache node: %s\n",
|
|
|
|
dumpcachenode(node));
|
|
|
|
#endif
|
|
|
|
cache->cachesize -= node->xdrsize;
|
|
|
|
freenccachenode(nccomm,node);
|
|
|
|
}
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(nccomm->cdf.cache->nodes,(void*)cachenode);
|
2011-04-18 02:56:10 +08:00
|
|
|
cache->cachesize += cachenode->xdrsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"buildcachenode: %s\n",dumpcachenode(cachenode));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
done:
|
2011-11-14 12:20:19 +08:00
|
|
|
if(constraint != NULL) dcefree((DCEnode*)constraint);
|
2011-04-18 02:56:10 +08:00
|
|
|
if(cachep) *cachep = cachenode;
|
|
|
|
if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat);
|
2013-11-23 04:49:21 +08:00
|
|
|
if(ncstat != OC_NOERR) {
|
2014-03-25 04:02:52 +08:00
|
|
|
freecdfroot(dxdroot);
|
2011-04-18 02:56:10 +08:00
|
|
|
freenccachenode(nccomm,cachenode);
|
2013-11-23 04:49:21 +08:00
|
|
|
if(cachep) *cachep = NULL;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
return THROW(ncstat);
|
|
|
|
}
|
|
|
|
|
|
|
|
NCcachenode*
|
|
|
|
createnccachenode(void)
|
|
|
|
{
|
|
|
|
NCcachenode* mem = (NCcachenode*)calloc(1,sizeof(NCcachenode));
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
freenccachenode(NCDAPCOMMON* nccomm, NCcachenode* node)
|
|
|
|
{
|
|
|
|
if(node == NULL) return;
|
2012-08-01 04:34:13 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"freecachenode: %s\n",
|
|
|
|
dumpcachenode(node));
|
|
|
|
#endif
|
2011-04-18 02:56:10 +08:00
|
|
|
oc_data_free(nccomm->oc.conn,node->content);
|
|
|
|
dcefree((DCEnode*)node->constraint);
|
2014-03-25 04:02:52 +08:00
|
|
|
freecdfroot(node->datadds);
|
2011-04-18 02:56:10 +08:00
|
|
|
nclistfree(node->vars);
|
|
|
|
nullfree(node);
|
2013-11-23 04:49:21 +08:00
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
freenccache(NCDAPCOMMON* nccomm, NCcache* cache)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if(cache == NULL) return;
|
|
|
|
freenccachenode(nccomm,cache->prefetch);
|
|
|
|
for(i=0;i<nclistlength(cache->nodes);i++) {
|
|
|
|
freenccachenode(nccomm,(NCcachenode*)nclistget(cache->nodes,i));
|
|
|
|
}
|
|
|
|
nclistfree(cache->nodes);
|
|
|
|
nullfree(cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
NCcache*
|
|
|
|
createnccache(void)
|
|
|
|
{
|
|
|
|
NCcache* c = (NCcache*)calloc(1,sizeof(NCcache));
|
|
|
|
c->cachelimit = DFALTCACHELIMIT;
|
|
|
|
c->cachesize = 0;
|
|
|
|
c->nodes = nclistnew();
|
|
|
|
c->cachecount = DFALTCACHECOUNT;
|
|
|
|
return c;
|
|
|
|
}
|
2011-11-14 12:20:19 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
iscacheableprojection(DCEprojection* proj)
|
|
|
|
{
|
|
|
|
int i,cacheable;
|
|
|
|
if(proj->discrim != CES_VAR) return 0;
|
|
|
|
cacheable = 1; /* assume so */
|
|
|
|
for(i=0;i<nclistlength(proj->var->segments);i++) {
|
|
|
|
DCEsegment* segment = (DCEsegment*)nclistget(proj->var->segments,i);
|
|
|
|
if(!iswholesegment(segment)) {cacheable = 0; break;}
|
|
|
|
}
|
|
|
|
return cacheable;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
iscacheableconstraint(DCEconstraint* con)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if(con == NULL) return 1;
|
|
|
|
if(con->selections != NULL && nclistlength(con->selections) > 0)
|
|
|
|
return 0; /* cant deal with selections */
|
|
|
|
for(i=0;i<nclistlength(con->projections);i++) {
|
|
|
|
if(!iscacheableprojection((DCEprojection*)nclistget(con->projections,i)))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2013-03-03 12:06:43 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
A variable is prefetchable if
|
|
|
|
1. it is atomic
|
|
|
|
2. it's size is sufficiently small
|
|
|
|
3. it is not contained in sequence or a dimensioned structure.
|
|
|
|
*/
|
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
markprefetch(NCDAPCOMMON* nccomm)
|
2013-03-03 12:06:43 +08:00
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
NClist* allvars = nccomm->cdf.fullddsroot->tree->varnodes;
|
|
|
|
assert(allvars != NULL);
|
|
|
|
/* mark those variables of sufficiently small size */
|
|
|
|
for(i=0;i<nclistlength(allvars);i++) {
|
|
|
|
CDFnode* var = (CDFnode*)nclistget(allvars,i);
|
|
|
|
size_t nelems;
|
|
|
|
|
|
|
|
/* If var is not atomic, then it is not prefetchable */
|
|
|
|
if(var->nctype != NC_Atomic)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* if var is under a sequence, then never prefetch */
|
|
|
|
if(dapinsequence(var))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Compute the # of elements in the variable */
|
|
|
|
for(nelems=1,j=0;j<nclistlength(var->array.dimsettrans);j++) {
|
|
|
|
CDFnode* dim = (CDFnode*)nclistget(var->array.dimsettrans,j);
|
|
|
|
nelems *= dim->dim.declsize;
|
|
|
|
}
|
2013-05-02 06:31:01 +08:00
|
|
|
if(nelems <= nccomm->cdf.smallsizelimit
|
|
|
|
&& FLAGSET(nccomm->controls,NCF_PREFETCH)) {
|
2013-03-03 12:06:43 +08:00
|
|
|
var->prefetchable = 1;
|
|
|
|
if(SHOWFETCH)
|
|
|
|
{
|
2013-03-13 04:45:58 +08:00
|
|
|
extern char* ocfqn(OCddsnode);
|
|
|
|
nclog(NCLOGDBG,"prefetchable: %s=%lu",
|
2013-03-03 12:06:43 +08:00
|
|
|
ocfqn(var->ocnode),(unsigned long)nelems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|