File: ut_projections.c

package info (click to toggle)
netcdf-parallel 1%3A4.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 113,164 kB
  • sloc: ansic: 267,893; sh: 12,869; cpp: 5,822; yacc: 2,613; makefile: 1,813; lex: 1,216; xml: 173; awk: 2
file content (137 lines) | stat: -rw-r--r-- 3,484 bytes parent folder | download | duplicates (2)
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
/*
 *	Copyright 2018, University Corporation for Atmospheric Research
 *      See netcdf/COPYRIGHT file for copying and redistribution conditions.
 */

#include "ut_includes.h"

void ut_chunk_test(int sort, ...);

/**
Test computation of applying a slice to a sequence of chunks
*/

int
main(int argc, char** argv)
{
    int i,r,stat = NC_NOERR;
    Vardef* var = NULL;
    struct Common common;
    NCZSliceProjections slpv[NC_MAX_VAR_DIMS];
    NCZChunkRange ncrv[NC_MAX_VAR_DIMS];
    
    /* Initialize */
    memset(&slpv,0,sizeof(slpv));
    memset(&common,0,sizeof(common));

    if((stat = ut_init(argc, argv, &utoptions))) goto done;

    /* printer off for these tests */
    zutester.tests = 0;
    zutester.print = NULL;
    zutest = &zutester;

    printoptions(&utoptions);

    var = nclistget(utoptions.vardefs,0);

    fillcommon(&common,var);

    /* Compute chunk ranges */
    if((stat = NCZ_compute_chunk_ranges(var->rank,utoptions.slices,var->chunksizes,ncrv)))
	goto done;

    if((stat=NCZ_compute_all_slice_projections(
	&common,
        utoptions.slices,
        ncrv,
	slpv))) goto done;

    /* Dump Results */
    for(r=0;r<var->rank;r++) {
	NCZSliceProjections* slp = &slpv[r];
        if(r != slp->r) usage(NC_EINTERNAL);
        printf("[r=%d] %s %s\n",r,nczprint_chunkrange(slp->range),nczprint_slice(utoptions.slices[r]));
        for(i=0;i<slp->count;i++) {
            NCZProjection* proj = &slp->projections[i];
            printf("[%d] %s\n",i,nczprint_projection(*proj));
	}
    }

    /* Cleanup */
    NCZ_clearsliceprojections(var->rank,slpv);

#if 0
    /* Compute corresponding slice projections  */
    for(r=0;r<var->rank;r++) {
        if((stat = NCZ_compute_per_slice_projections(
			r,
			&utoptions.slices[r],
			&ncrv[r],
			var->dimsizes[r],
			var->chunksizes[r],
			&slpv[r]))) goto done;
    }

    /* Dump Results */
    for(r=0;r<var->rank;r++) {
	NCZSliceProjections* slp = &slpv[r];
	char *sr, *sl;
        if(r != slp->r) usage(NC_EINTERNAL);
	sr = nczprint_chunkrange(slp->range);
	sl = nczprint_slice(utoptions.slices[r]);
        printf("[r=%d] %s %s\n",r,sr,sl);
	nullfree(sr); nullfree(sl);
        for(i=0;i<slp->count;i++) {
            NCZProjection* proj = &slp->projections[i];
            printf("[%d] %s\n",i,nczprint_projection(*proj));
	}
    }
    /* Cleanup */
    NCZ_clearsliceprojections(var->rank,slpv);
#endif

done:
    fflush(stdout);
    nczprint_reclaim();
    ut_final();
    if(stat) usage(stat);
    return  0;
}

void
ut_chunk_test(int sort,...)
{
    int i;
    va_list ap;    
#if 0
    struct Common* common = NULL;    
#endif
    int rank; /* variable rank */
    NCZSlice* slices = NULL; /* the complete set of slices |slices| == R*/
    size64_t* chunksizes = NULL; /* the chunk length corresponding to the dimensions */
    NCZChunkRange* ranges = NULL; /* computed chunk ranges */

    va_start(ap,sort);
    
    switch (sort) {
    default: break; /* ignore */
    case UTEST_RANGE: /* () */
	rank = va_arg(ap,size64_t);
        slices = va_arg(ap,NCZSlice*);
	chunksizes = va_arg(ap,size64_t*);
        ranges = va_arg(ap,NCZChunkRange*);
        printf("[r=%d] Chunksizes: %s\n",rank,nczprint_vector(rank,chunksizes));
        printf("Slices: ");
	for(i=0;i<rank;i++)
	    printf(" %s",nczprint_slicesx(rank,slices,1));
	printf("\n");
        printf("Ranges: ");
	for(i=0;i<rank;i++)
	    printf(" %s",nczprint_chunkrange(ranges[i]));
	printf("\n");
	break;
    }
    va_end(ap);
}