source: thirdparty/SZ/sz/src/sz_uint64.c @ 9ee2ce3

Revision 9ee2ce3, 37.3 KB checked in by Hal Finkel <hfinkel@…>, 6 years ago (diff)

importing new SZ files

  • Property mode set to 100644
Line 
1/**
2 *  @file sz_uint64.c
3 *  @author Sheng Di
4 *  @date Aug, 2017
5 *  @brief sz_uint64, Compression and Decompression functions
6 *  (C) 2017 by Mathematics and Computer Science (MCS), Argonne National Laboratory.
7 *      See COPYRIGHT in top-level directory.
8 */
9
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <unistd.h>
15#include <math.h>
16#include "sz.h"
17#include "CompressElement.h"
18#include "DynamicByteArray.h"
19#include "DynamicIntArray.h"
20#include "zlib.h"
21#include "rw.h"
22#include "TightDataPointStorageI.h"
23#include "sz_uint64.h"
24#include "utility.h"
25
26unsigned int optimize_intervals_uint64_1D(uint64_t *oriData, size_t dataLength, double realPrecision)
27{       
28        size_t i = 0, radiusIndex;
29        int64_t pred_value = 0, pred_err;
30        size_t *intervals = (size_t*)malloc(confparams_cpr->maxRangeRadius*sizeof(size_t));
31        memset(intervals, 0, confparams_cpr->maxRangeRadius*sizeof(size_t));
32        size_t totalSampleSize = dataLength/confparams_cpr->sampleDistance;
33        for(i=2;i<dataLength;i++)
34        {
35                if(i%confparams_cpr->sampleDistance==0)
36                {
37                        //pred_value = 2*oriData[i-1] - oriData[i-2];
38                        pred_value = oriData[i-1];
39                        pred_err = llabs(pred_value - (int64_t)(oriData[i]));
40                        radiusIndex = (uint64_t)((pred_err/realPrecision+1)/2);
41                        if(radiusIndex>=confparams_cpr->maxRangeRadius)
42                                radiusIndex = confparams_cpr->maxRangeRadius - 1;                       
43                        intervals[radiusIndex]++;
44                }
45        }
46        //compute the appropriate number
47        size_t targetCount = totalSampleSize*confparams_cpr->predThreshold;
48        size_t sum = 0;
49        for(i=0;i<confparams_cpr->maxRangeRadius;i++)
50        {
51                sum += intervals[i];
52                if(sum>targetCount)
53                        break;
54        }
55        if(i>=confparams_cpr->maxRangeRadius)
56                i = confparams_cpr->maxRangeRadius-1;
57               
58        unsigned int accIntervals = 2*(i+1);
59        unsigned int powerOf2 = roundUpToPowerOf2(accIntervals);
60       
61        if(powerOf2<32)
62                powerOf2 = 32;
63       
64        free(intervals);
65        //printf("accIntervals=%d, powerOf2=%d\n", accIntervals, powerOf2);
66        return powerOf2;
67}
68
69unsigned int optimize_intervals_uint64_2D(uint64_t *oriData, size_t r1, size_t r2, double realPrecision)
70{       
71        size_t i,j, index;
72        size_t radiusIndex;
73        int64_t pred_value = 0, pred_err;
74        size_t *intervals = (size_t*)malloc(confparams_cpr->maxRangeRadius*sizeof(size_t));
75        memset(intervals, 0, confparams_cpr->maxRangeRadius*sizeof(size_t));
76        size_t totalSampleSize = (r1-1)*(r2-1)/confparams_cpr->sampleDistance;
77        for(i=1;i<r1;i++)
78        {
79                for(j=1;j<r2;j++)
80                {
81                        if((i+j)%confparams_cpr->sampleDistance==0)
82                        {
83                                index = i*r2+j;
84                                pred_value = oriData[index-1] + oriData[index-r2] - oriData[index-r2-1];
85                                pred_err = llabs(pred_value - (int64_t)(oriData[index]));
86                                radiusIndex = (uint64_t)((pred_err/realPrecision+1)/2);
87                                if(radiusIndex>=confparams_cpr->maxRangeRadius)
88                                        radiusIndex = confparams_cpr->maxRangeRadius - 1;
89                                intervals[radiusIndex]++;
90                        }                       
91                }
92        }
93        //compute the appropriate number
94        size_t targetCount = totalSampleSize*confparams_cpr->predThreshold;
95        size_t sum = 0;
96        for(i=0;i<confparams_cpr->maxRangeRadius;i++)
97        {
98                sum += intervals[i];
99                if(sum>targetCount)
100                        break;
101        }
102        if(i>=confparams_cpr->maxRangeRadius)
103                i = confparams_cpr->maxRangeRadius-1;
104        unsigned int accIntervals = 2*(i+1);
105        unsigned int powerOf2 = roundUpToPowerOf2(accIntervals);
106
107        if(powerOf2<32)
108                powerOf2 = 32;
109
110        free(intervals);
111        //printf("confparams_cpr->maxRangeRadius = %d, accIntervals=%d, powerOf2=%d\n", confparams_cpr->maxRangeRadius, accIntervals, powerOf2);
112        return powerOf2;
113}
114
115unsigned int optimize_intervals_uint64_3D(uint64_t *oriData, size_t r1, size_t r2, size_t r3, double realPrecision)
116{       
117        size_t i,j,k, index;
118        size_t radiusIndex;
119        size_t r23=r2*r3;
120        int64_t pred_value = 0, pred_err;
121        size_t *intervals = (size_t*)malloc(confparams_cpr->maxRangeRadius*sizeof(size_t));
122        memset(intervals, 0, confparams_cpr->maxRangeRadius*sizeof(size_t));
123        size_t totalSampleSize = (r1-1)*(r2-1)*(r3-1)/confparams_cpr->sampleDistance;
124        for(i=1;i<r1;i++)
125        {
126                for(j=1;j<r2;j++)
127                {
128                        for(k=1;k<r3;k++)
129                        {                       
130                                if((i+j+k)%confparams_cpr->sampleDistance==0)
131                                {
132                                        index = i*r23+j*r3+k;
133                                        pred_value = oriData[index-1] + oriData[index-r3] + oriData[index-r23] 
134                                        - oriData[index-1-r23] - oriData[index-r3-1] - oriData[index-r3-r23] + oriData[index-r3-r23-1];
135                                        pred_err = llabs(pred_value - (int64_t)(oriData[index]));
136                                        radiusIndex = (pred_err/realPrecision+1)/2;
137                                        if(radiusIndex>=confparams_cpr->maxRangeRadius)
138                                        {
139                                                radiusIndex = confparams_cpr->maxRangeRadius - 1;
140                                                //printf("radiusIndex=%d\n", radiusIndex);
141                                        }
142                                        intervals[radiusIndex]++;
143                                }
144                        }
145                }
146        }
147        //compute the appropriate number
148        size_t targetCount = totalSampleSize*confparams_cpr->predThreshold;
149        size_t sum = 0;
150        for(i=0;i<confparams_cpr->maxRangeRadius;i++)
151        {
152                sum += intervals[i];
153                if(sum>targetCount)
154                        break;
155        }
156        if(i>=confparams_cpr->maxRangeRadius)
157                i = confparams_cpr->maxRangeRadius-1;
158        unsigned int accIntervals = 2*(i+1);
159        unsigned int powerOf2 = roundUpToPowerOf2(accIntervals);
160
161        if(powerOf2<32)
162                powerOf2 = 32;
163       
164        free(intervals);
165        //printf("targetCount=%d, sum=%d, totalSampleSize=%d, ratio=%f, accIntervals=%d, powerOf2=%d\n", targetCount, sum, totalSampleSize, (double)sum/(double)totalSampleSize, accIntervals, powerOf2);
166        return powerOf2;
167}
168
169
170unsigned int optimize_intervals_uint64_4D(uint64_t *oriData, size_t r1, size_t r2, size_t r3, size_t r4, double realPrecision)
171{
172        size_t i,j,k,l, index;
173        size_t radiusIndex;
174        size_t r234=r2*r3*r4;
175        size_t r34=r3*r4;
176        int64_t pred_value = 0, pred_err;
177        size_t *intervals = (size_t*)malloc(confparams_cpr->maxRangeRadius*sizeof(size_t));
178        memset(intervals, 0, confparams_cpr->maxRangeRadius*sizeof(size_t));
179        size_t totalSampleSize = (r1-1)*(r2-1)*(r3-1)*(r4-1)/confparams_cpr->sampleDistance;
180        for(i=1;i<r1;i++)
181        {
182                for(j=1;j<r2;j++)
183                {
184                        for(k=1;k<r3;k++)
185                        {
186                                for (l=1;l<r4;l++)
187                                {
188                                        if((i+j+k+l)%confparams_cpr->sampleDistance==0)
189                                        {
190                                                index = i*r234+j*r34+k*r4+l;
191                                                pred_value = oriData[index-1] + oriData[index-r3] + oriData[index-r34]
192                                                                - oriData[index-1-r34] - oriData[index-r4-1] - oriData[index-r4-r34] + oriData[index-r4-r34-1];
193                                                pred_err = llabs(pred_value - (int64_t)(oriData[index]));
194                                                radiusIndex = (uint64_t)((pred_err/realPrecision+1)/2);
195                                                if(radiusIndex>=confparams_cpr->maxRangeRadius)
196                                                        radiusIndex = confparams_cpr->maxRangeRadius - 1;
197                                                intervals[radiusIndex]++;
198                                        }
199                                }
200                        }
201                }
202        }
203        //compute the appropriate number
204        size_t targetCount = totalSampleSize*confparams_cpr->predThreshold;
205        size_t sum = 0;
206        for(i=0;i<confparams_cpr->maxRangeRadius;i++)
207        {
208                sum += intervals[i];
209                if(sum>targetCount)
210                        break;
211        }
212        if(i>=confparams_cpr->maxRangeRadius)
213                i = confparams_cpr->maxRangeRadius-1;
214
215        unsigned int accIntervals = 2*(i+1);
216        unsigned int powerOf2 = roundUpToPowerOf2(accIntervals);
217
218        if(powerOf2<32)
219                powerOf2 = 32;
220
221        free(intervals);
222        return powerOf2;
223}
224
225TightDataPointStorageI* SZ_compress_uint64_1D_MDQ(uint64_t *oriData, size_t dataLength, double realPrecision, uint64_t valueRangeSize, uint64_t minValue)
226{
227        unsigned char bytes[8] = {0,0,0,0,0,0,0,0};
228        int byteSize = computeByteSizePerIntValue(valueRangeSize);
229        unsigned int quantization_intervals;
230        if(exe_params->optQuantMode==1)
231                quantization_intervals = optimize_intervals_uint64_1D(oriData, dataLength, realPrecision);
232        else
233                quantization_intervals = exe_params->intvCapacity;
234        updateQuantizationInfo(quantization_intervals); 
235        size_t i;
236
237        int* type = (int*) malloc(dataLength*sizeof(int));
238               
239        uint64_t* spaceFillingValue = oriData; //
240       
241        DynamicByteArray *exactDataByteArray;
242        new_DBA(&exactDataByteArray, DynArrayInitLen);
243               
244        int64_t last3CmprsData[3] = {0,0,0};
245                               
246        //add the first data   
247        type[0] = 0;
248        compressUInt64Value(spaceFillingValue[0], minValue, byteSize, bytes);
249        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
250        listAdd_int(last3CmprsData, spaceFillingValue[0]);
251               
252        type[1] = 0;
253        compressUInt64Value(spaceFillingValue[1], minValue, byteSize, bytes);
254        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
255        listAdd_int(last3CmprsData, spaceFillingValue[1]);
256        //printf("%.30G\n",last3CmprsData[0]); 
257       
258        int state;
259        double checkRadius = (exe_params->intvCapacity-1)*realPrecision;
260        int64_t curData;
261        int64_t pred, predAbsErr;
262        double interval = 2*realPrecision;
263       
264        for(i=2;i<dataLength;i++)
265        {
266//              if(i==2869438)
267//                      printf("i=%d\n", i);
268                curData = spaceFillingValue[i];
269                //pred = 2*last3CmprsData[0] - last3CmprsData[1];
270                pred = last3CmprsData[0];
271                predAbsErr = llabs(curData - pred);     
272                if(predAbsErr<checkRadius)
273                {
274                        state = (predAbsErr/realPrecision+1)/2;
275                        if(curData>=pred)
276                        {
277                                type[i] = exe_params->intvRadius+state;
278                                pred = pred + state*interval;
279                        }
280                        else //curData<pred
281                        {
282                                type[i] = exe_params->intvRadius-state;
283                                pred = pred - state*interval;
284                        }
285/*                      if(type[i]==0)
286                                printf("err:type[%d]=0\n", i);*/
287                        listAdd_int(last3CmprsData, pred);                                     
288                        continue;
289                }
290               
291                //unpredictable data processing         
292                type[i] = 0;
293                compressUInt64Value(curData, minValue, byteSize, bytes);
294                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
295                listAdd_int(last3CmprsData, curData);
296        }//end of for
297               
298        size_t exactDataNum = exactDataByteArray->size / byteSize;
299       
300        TightDataPointStorageI* tdps;   
301                       
302        new_TightDataPointStorageI(&tdps, dataLength, exactDataNum, byteSize, 
303                        type, exactDataByteArray->array, exactDataByteArray->size, 
304                        realPrecision, minValue, quantization_intervals, SZ_UINT64);
305
306//sdi:Debug
307/*      int sum =0;
308        for(i=0;i<dataLength;i++)
309                if(type[i]==0) sum++;
310        printf("opt_quantizations=%d, exactDataNum=%d, sum=%d\n",quantization_intervals, exactDataNum, sum);*/
311       
312        //free memory
313        free(type);     
314        free(exactDataByteArray); //exactDataByteArray->array has been released in free_TightDataPointStorageF(tdps);
315       
316        return tdps;
317}
318
319void SZ_compress_args_uint64_StoreOriData(uint64_t* oriData, size_t dataLength, TightDataPointStorageI* tdps, 
320unsigned char** newByteData, size_t *outSize)
321{
322        int intSize=sizeof(uint64_t);   
323        size_t k = 0, i;
324        tdps->isLossless = 1;
325        size_t totalByteLength = 3 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 1 + intSize*dataLength;
326        *newByteData = (unsigned char*)malloc(totalByteLength);
327       
328        unsigned char dsLengthBytes[8];
329        for (i = 0; i < 3; i++)//3
330                (*newByteData)[k++] = versionNumber[i];
331
332        if(exe_params->SZ_SIZE_TYPE==4)//1
333                (*newByteData)[k++] = 16; //00010000
334        else
335                (*newByteData)[k++] = 80;       //01010000: 01000000 indicates the SZ_SIZE_TYPE=8
336       
337        convertSZParamsToBytes(confparams_cpr, &((*newByteData)[k]));
338        k = k + MetaDataByteLength;             
339       
340        sizeToBytes(dsLengthBytes,dataLength); //SZ_SIZE_TYPE: 4 or 8   
341        for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
342                (*newByteData)[k++] = dsLengthBytes[i];
343               
344        if(sysEndianType==BIG_ENDIAN_SYSTEM)
345                memcpy((*newByteData)+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE, oriData, dataLength*intSize);
346        else
347        {
348                unsigned char* p = (*newByteData)+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE;
349                for(i=0;i<dataLength;i++,p+=intSize)
350                        int64ToBytes_bigEndian(p, oriData[i]);
351        }       
352        *outSize = totalByteLength;
353}
354
355void SZ_compress_args_uint64_NoCkRngeNoGzip_1D(unsigned char** newByteData, uint64_t *oriData, 
356size_t dataLength, double realPrecision, size_t *outSize, uint64_t valueRangeSize, uint64_t minValue)
357{
358        TightDataPointStorageI* tdps = SZ_compress_uint64_1D_MDQ(oriData, dataLength, realPrecision, valueRangeSize, minValue);
359        //TODO: return bytes....
360        convertTDPStoFlatBytes_int(tdps, newByteData, outSize);
361        if(*outSize > dataLength*sizeof(uint64_t))
362                SZ_compress_args_uint64_StoreOriData(oriData, dataLength+2, tdps, newByteData, outSize);
363        free_TightDataPointStorageI(tdps);
364}
365
366TightDataPointStorageI* SZ_compress_uint64_2D_MDQ(uint64_t *oriData, size_t r1, size_t r2, double realPrecision, uint64_t valueRangeSize, uint64_t minValue)
367{
368        unsigned char bytes[8] = {0,0,0,0,0,0,0,0};
369        int byteSize = computeByteSizePerIntValue(valueRangeSize);
370       
371        unsigned int quantization_intervals;
372        if(exe_params->optQuantMode==1)
373        {
374                quantization_intervals = optimize_intervals_uint64_2D(oriData, r1, r2, realPrecision);
375                updateQuantizationInfo(quantization_intervals);
376        }       
377        else
378                quantization_intervals = exe_params->intvCapacity;
379        size_t i,j; 
380        int64_t pred1D, pred2D, curValue;
381        int64_t diff = 0.0;
382        double itvNum = 0;
383        uint64_t *P0, *P1;
384               
385        size_t dataLength = r1*r2;     
386       
387        P0 = (uint64_t*)malloc(r2*sizeof(uint64_t));
388        memset(P0, 0, r2*sizeof(uint64_t));
389        P1 = (uint64_t*)malloc(r2*sizeof(uint64_t));
390        memset(P1, 0, r2*sizeof(uint64_t));
391               
392        int* type = (int*) malloc(dataLength*sizeof(int));
393        //type[dataLength]=0;
394               
395        uint64_t* spaceFillingValue = oriData; //
396       
397        DynamicByteArray *exactDataByteArray;
398        new_DBA(&exactDataByteArray, DynArrayInitLen); 
399
400        type[0] = 0;
401        curValue = P1[0] = spaceFillingValue[0];
402        compressUInt64Value(curValue, minValue, byteSize, bytes);
403        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
404
405        /* Process Row-0 data 1*/
406        pred1D = P1[0];
407        diff = (int64_t)(spaceFillingValue[1]) - (int64_t)(pred1D);
408
409        itvNum =  llabs(diff)/realPrecision + 1;
410
411        if (itvNum < exe_params->intvCapacity)
412        {
413                if (diff < 0) itvNum = -itvNum;
414                type[1] = (int) (itvNum/2) + exe_params->intvRadius;
415                P1[1] = pred1D + 2 * (type[1] - exe_params->intvRadius) * realPrecision;
416        }
417        else
418        {
419                type[1] = 0;
420                curValue = P1[1] = spaceFillingValue[1];
421                compressUInt64Value(curValue, minValue, byteSize, bytes);
422                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
423        }
424
425    /* Process Row-0 data 2 --> data r2-1 */
426        for (j = 2; j < r2; j++)
427        {
428                pred1D = 2*P1[j-1] - P1[j-2];
429                diff = (int64_t)(spaceFillingValue[j]) - (int64_t)(pred1D);
430
431                itvNum = llabs(diff)/realPrecision + 1;
432
433                if (itvNum < exe_params->intvCapacity)
434                {
435                        if (diff < 0) itvNum = -itvNum;
436                        type[j] = (int) (itvNum/2) + exe_params->intvRadius;
437                        P1[j] = pred1D + 2 * (type[j] - exe_params->intvRadius) * realPrecision;
438                }
439                else
440                {
441                        type[j] = 0;
442                        curValue = P1[j] = spaceFillingValue[j];
443                        compressUInt64Value(curValue, minValue, byteSize, bytes);
444                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
445                }
446        }
447
448        /* Process Row-1 --> Row-r1-1 */
449        size_t index;
450        for (i = 1; i < r1; i++)
451        {       
452                /* Process row-i data 0 */
453                index = i*r2;
454                pred1D = P1[0];
455                diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred1D);
456
457                itvNum = llabs(diff)/realPrecision + 1;
458
459                if (itvNum < exe_params->intvCapacity)
460                {
461                        if (diff < 0) itvNum = -itvNum;
462                        type[index] = (int) (itvNum/2) + exe_params->intvRadius;
463                        P0[0] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
464                }
465                else
466                {
467                        type[index] = 0;
468                        curValue = P0[0] = spaceFillingValue[index];
469                        compressUInt64Value(curValue, minValue, byteSize, bytes);
470                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
471                }
472                                                                       
473                /* Process row-i data 1 --> r2-1*/
474                for (j = 1; j < r2; j++)
475                {
476                        index = i*r2+j;
477                        pred2D = P0[j-1] + P1[j] - P1[j-1];
478
479                        diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred2D);
480
481                        itvNum = llabs(diff)/realPrecision + 1;
482
483                        if (itvNum < exe_params->intvCapacity)
484                        {
485                                if (diff < 0) itvNum = -itvNum;
486                                type[index] = (int) (itvNum/2) + exe_params->intvRadius;
487                                P0[j] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
488                        }
489                        else
490                        {
491                                type[index] = 0;
492                                curValue = P0[j] = spaceFillingValue[index];
493                                compressUInt64Value(curValue, minValue, byteSize, bytes);
494                                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
495                        }
496                }
497
498                uint64_t *Pt;
499                Pt = P1;
500                P1 = P0;
501                P0 = Pt;
502        }
503       
504        if(r2!=1)
505                free(P0);
506        free(P1);                       
507       
508        size_t exactDataNum = exactDataByteArray->size;
509       
510        TightDataPointStorageI* tdps;   
511                       
512        new_TightDataPointStorageI(&tdps, dataLength, exactDataNum, byteSize, 
513                        type, exactDataByteArray->array, exactDataByteArray->size, 
514                        realPrecision, minValue, quantization_intervals, SZ_UINT64);
515                       
516        //free memory
517        free(type);     
518        free(exactDataByteArray); //exactDataByteArray->array has been released in free_TightDataPointStorageF(tdps);
519       
520        return tdps;   
521}
522
523/**
524 *
525 * Note: @r1 is high dimension
526 *               @r2 is low dimension
527 * */
528void SZ_compress_args_uint64_NoCkRngeNoGzip_2D(unsigned char** newByteData, uint64_t *oriData, size_t r1, size_t r2, double realPrecision, size_t *outSize, 
529int64_t valueRangeSize, uint64_t minValue)
530{
531        TightDataPointStorageI* tdps = SZ_compress_uint64_2D_MDQ(oriData, r1, r2, realPrecision, valueRangeSize, minValue);
532
533        convertTDPStoFlatBytes_int(tdps, newByteData, outSize);
534
535        size_t dataLength = r1*r2;
536        if(*outSize>dataLength*sizeof(uint64_t))
537                SZ_compress_args_uint64_StoreOriData(oriData, dataLength, tdps, newByteData, outSize);
538       
539        free_TightDataPointStorageI(tdps);     
540}
541
542TightDataPointStorageI* SZ_compress_uint64_3D_MDQ(uint64_t *oriData, size_t r1, size_t r2, size_t r3, double realPrecision, uint64_t valueRangeSize, uint64_t minValue)
543{
544        unsigned char bytes[8] = {0,0,0,0,0,0,0,0};
545        int byteSize = computeByteSizePerIntValue(valueRangeSize);
546       
547        unsigned int quantization_intervals;
548        if(exe_params->optQuantMode==1)
549        {
550                quantization_intervals = optimize_intervals_uint64_3D(oriData, r1, r2, r3, realPrecision);
551                updateQuantizationInfo(quantization_intervals);
552        }       
553        else
554                quantization_intervals = exe_params->intvCapacity;
555        size_t i,j,k; 
556        int64_t pred1D, pred2D, pred3D, curValue;
557        int64_t diff = 0.0;
558        double itvNum = 0;
559        uint64_t *P0, *P1;
560               
561        size_t dataLength = r1*r2*r3;           
562
563        size_t r23 = r2*r3;
564        P0 = (uint64_t*)malloc(r23*sizeof(uint64_t));
565        P1 = (uint64_t*)malloc(r23*sizeof(uint64_t));
566
567        int* type = (int*) malloc(dataLength*sizeof(int));
568
569        uint64_t* spaceFillingValue = oriData; //
570       
571        DynamicByteArray *exactDataByteArray;
572        new_DBA(&exactDataByteArray, DynArrayInitLen); 
573
574        type[0] = 0;
575        P1[0] = spaceFillingValue[0];
576        compressUInt64Value(spaceFillingValue[0], minValue, byteSize, bytes);
577        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
578
579        /* Process Row-0 data 1*/
580        pred1D = P1[0];
581        diff = (int64_t)(spaceFillingValue[1]) - (int64_t)(pred1D);
582
583        itvNum = llabs(diff)/realPrecision + 1;
584
585        if (itvNum < exe_params->intvCapacity)
586        {
587                if (diff < 0) itvNum = -itvNum;
588                type[1] = (int) (itvNum/2) + exe_params->intvRadius;
589                P1[1] = pred1D + 2 * (type[1] - exe_params->intvRadius) * realPrecision;
590        }
591        else
592        {
593                type[1] = 0;
594                curValue = P1[1] = spaceFillingValue[1];
595                compressUInt64Value(curValue, minValue, byteSize, bytes);
596                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
597        }
598
599    /* Process Row-0 data 2 --> data r3-1 */
600        for (j = 2; j < r3; j++)
601        {
602                pred1D = 2*P1[j-1] - P1[j-2];
603                diff = (int64_t)(spaceFillingValue[j]) - (int64_t)(pred1D);
604
605                itvNum = llabs(diff)/realPrecision + 1;
606
607                if (itvNum < exe_params->intvCapacity)
608                {
609                        if (diff < 0) itvNum = -itvNum;
610                        type[j] = (int) (itvNum/2) + exe_params->intvRadius;
611                        P1[j] = pred1D + 2 * (type[j] - exe_params->intvRadius) * realPrecision;
612                }
613                else
614                {
615                        type[j] = 0;
616                        curValue = P1[j] = spaceFillingValue[j];
617                        compressUInt64Value(curValue, minValue, byteSize, bytes);
618                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
619                }
620        }
621
622        /* Process Row-1 --> Row-r2-1 */
623        size_t index;
624        for (i = 1; i < r2; i++)
625        {
626                /* Process row-i data 0 */
627                index = i*r3;   
628                pred1D = P1[index-r3];
629                diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred1D);
630
631                itvNum = llabs(diff)/realPrecision + 1;
632
633                if (itvNum < exe_params->intvCapacity)
634                {
635                        if (diff < 0) itvNum = -itvNum;
636                        type[index] = (int) (itvNum/2) + exe_params->intvRadius;
637                        P1[index] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
638                }
639                else
640                {
641                        type[index] = 0;
642                        curValue = P1[index] = spaceFillingValue[index];
643                        compressUInt64Value(curValue, minValue, byteSize, bytes);
644                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
645                }
646
647                /* Process row-i data 1 --> data r3-1*/
648                for (j = 1; j < r3; j++)
649                {
650                        index = i*r3+j;
651                        pred2D = P1[index-1] + P1[index-r3] - P1[index-r3-1];
652
653                        diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred2D);
654
655                        itvNum = llabs(diff)/realPrecision + 1;
656
657                        if (itvNum < exe_params->intvCapacity)
658                        {
659                                if (diff < 0) itvNum = -itvNum;
660                                type[index] = (int) (itvNum/2) + exe_params->intvRadius;
661                                P1[index] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
662                        }
663                        else
664                        {
665                                type[index] = 0;
666                                curValue = P1[index] = spaceFillingValue[index];
667                                compressUInt64Value(curValue, minValue, byteSize, bytes);
668                                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
669                        }
670                }
671        }
672
673
674        ///////////////////////////     Process layer-1 --> layer-r1-1 ///////////////////////////
675
676        for (k = 1; k < r1; k++)
677        {
678                /* Process Row-0 data 0*/
679                index = k*r23;
680                pred1D = P1[0];
681                diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred1D);
682
683                itvNum = llabs(diff)/realPrecision + 1;
684
685                if (itvNum < exe_params->intvCapacity)
686                {
687                        if (diff < 0) itvNum = -itvNum;
688                        type[index] = (int) (itvNum/2) + exe_params->intvRadius;
689                        P0[0] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
690                }
691                else
692                {
693                        type[index] = 0;
694                        curValue = P0[0] = spaceFillingValue[index];
695                        compressUInt64Value(curValue, minValue, byteSize, bytes);
696                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
697                }
698
699
700            /* Process Row-0 data 1 --> data r3-1 */
701                for (j = 1; j < r3; j++)
702                {
703                        //index = k*r2*r3+j;
704                        index ++;
705                        pred2D = P0[j-1] + P1[j] - P1[j-1];
706                        diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred2D);
707
708                        itvNum = llabs(diff)/realPrecision + 1;
709
710                        if (itvNum < exe_params->intvCapacity)
711                        {
712                                if (diff < 0) itvNum = -itvNum;
713                                type[index] = (int) (itvNum/2) + exe_params->intvRadius;
714                                P0[j] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
715/*                              if(type[index]==0)
716                                        printf("err:type[%d]=0, index4\n", index);                                      */
717                        }
718                        else
719                        {
720                                type[index] = 0;
721                                curValue = P0[j] = spaceFillingValue[index];
722                                compressUInt64Value(curValue, minValue, byteSize, bytes);
723                                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
724                        }
725                }
726
727            /* Process Row-1 --> Row-r2-1 */
728                size_t index2D;
729                for (i = 1; i < r2; i++)
730                {
731                        /* Process Row-i data 0 */
732                        index = k*r23 + i*r3;
733                        index2D = i*r3;         
734                        pred2D = P0[index2D-r3] + P1[index2D] - P1[index2D-r3];
735                        diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred2D);
736
737                        itvNum = llabs(diff)/realPrecision + 1;
738
739                        if (itvNum < exe_params->intvCapacity)
740                        {
741                                if (diff < 0) itvNum = -itvNum;
742                                type[index] = (int) (itvNum/2) + exe_params->intvRadius;
743                                P0[index2D] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
744                        }
745                        else
746                        {
747                                type[index] = 0;
748                                curValue = P0[index2D] = spaceFillingValue[index];
749                                compressUInt64Value(curValue, minValue, byteSize, bytes);
750                                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
751                        }
752
753                        /* Process Row-i data 1 --> data r3-1 */
754                        for (j = 1; j < r3; j++)
755                        {
756//                              if(k==63&&i==43&&j==27)
757//                                      printf("i=%d\n", i);
758                                //index = k*r2*r3 + i*r3 + j;                   
759                                index ++;
760                                index2D = i*r3 + j;
761                                pred3D = P0[index2D-1] + P0[index2D-r3]+ P1[index2D] - P0[index2D-r3-1] - P1[index2D-r3] - P1[index2D-1] + P1[index2D-r3-1];
762                                diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred3D);
763
764                                itvNum = llabs(diff)/realPrecision + 1;
765
766                                if (itvNum < exe_params->intvCapacity)
767                                {
768                                        if (diff < 0) itvNum = -itvNum;
769                                        type[index] = (int) (itvNum/2) + exe_params->intvRadius;
770                                        P0[index2D] = pred3D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
771                                }
772                                else
773                                {
774                                        type[index] = 0;
775                                        curValue = P0[index2D] = spaceFillingValue[index];
776                                        compressUInt64Value(curValue, minValue, byteSize, bytes);
777                                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
778                                }
779                        }
780                }
781
782                uint64_t *Pt;
783                Pt = P1;
784                P1 = P0;
785                P0 = Pt;
786        }
787        if(r23!=1)
788                free(P0);
789        free(P1);
790
791        size_t exactDataNum = exactDataByteArray->size;
792       
793        TightDataPointStorageI* tdps;   
794                       
795        new_TightDataPointStorageI(&tdps, dataLength, exactDataNum, byteSize, 
796                        type, exactDataByteArray->array, exactDataByteArray->size, 
797                        realPrecision, minValue, quantization_intervals, SZ_UINT64);
798                       
799        //free memory
800        free(type);     
801        free(exactDataByteArray); //exactDataByteArray->array has been released in free_TightDataPointStorageF(tdps);
802       
803        return tdps;   
804}
805
806
807void SZ_compress_args_uint64_NoCkRngeNoGzip_3D(unsigned char** newByteData, uint64_t *oriData, size_t r1, size_t r2, size_t r3, double realPrecision, size_t *outSize, 
808uint64_t valueRangeSize, uint64_t minValue)
809{
810        TightDataPointStorageI* tdps = SZ_compress_uint64_3D_MDQ(oriData, r1, r2, r3, realPrecision, valueRangeSize, minValue);
811
812        convertTDPStoFlatBytes_int(tdps, newByteData, outSize);
813
814        size_t dataLength = r1*r2*r3;
815        if(*outSize>dataLength*sizeof(uint64_t))
816                SZ_compress_args_uint64_StoreOriData(oriData, dataLength, tdps, newByteData, outSize);
817       
818        free_TightDataPointStorageI(tdps);     
819}
820
821
822TightDataPointStorageI* SZ_compress_uint64_4D_MDQ(uint64_t *oriData, size_t r1, size_t r2, size_t r3, size_t r4, double realPrecision, uint64_t valueRangeSize, uint64_t minValue)
823{
824        unsigned char bytes[8] = {0,0,0,0,0,0,0,0};
825        int byteSize = computeByteSizePerIntValue(valueRangeSize);
826       
827        unsigned int quantization_intervals;
828        if(exe_params->optQuantMode==1)
829        {
830                quantization_intervals = optimize_intervals_uint64_4D(oriData, r1, r2, r3, r4, realPrecision);
831                updateQuantizationInfo(quantization_intervals);
832        }       
833        else
834                quantization_intervals = exe_params->intvCapacity;
835        size_t i,j,k; 
836        int64_t pred1D, pred2D, pred3D, curValue;
837        int64_t diff = 0.0;
838        double itvNum = 0;
839        uint64_t *P0, *P1;
840               
841        size_t dataLength = r1*r2*r3*r4;               
842
843        size_t r234 = r2*r3*r4;
844        size_t r34 = r3*r4;
845
846        P0 = (uint64_t*)malloc(r34*sizeof(uint64_t));
847        P1 = (uint64_t*)malloc(r34*sizeof(uint64_t));
848       
849        int* type = (int*) malloc(dataLength*sizeof(int));
850
851        uint64_t* spaceFillingValue = oriData; //
852       
853        DynamicByteArray *exactDataByteArray;
854        new_DBA(&exactDataByteArray, DynArrayInitLen); 
855
856        size_t l;
857        for (l = 0; l < r1; l++)
858        {
859
860                ///////////////////////////     Process layer-0 ///////////////////////////
861                /* Process Row-0 data 0*/
862                size_t index = l*r234;
863                size_t index2D = 0;
864
865                type[index] = 0;
866                curValue = P1[index2D] = spaceFillingValue[index];
867                compressUInt64Value(curValue, minValue, byteSize, bytes);
868                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
869
870                /* Process Row-0 data 1*/
871                index = l*r234+1;
872                index2D = 1;
873
874                pred1D = P1[index2D-1];
875                diff = (int64_t)(curValue) - (int64_t)(pred1D);
876
877                itvNum = llabs(diff)/realPrecision + 1;
878
879                if (itvNum < exe_params->intvCapacity)
880                {
881                        if (diff < 0) itvNum = -itvNum;
882                        type[index] = (int) (itvNum/2) + exe_params->intvRadius;
883                        P1[index2D] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
884                }
885                else
886                {
887                        type[index] = 0;
888
889                        curValue = P1[index2D] = spaceFillingValue[0];
890                        compressUInt64Value(curValue, minValue, byteSize, bytes);
891                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
892                }
893
894                /* Process Row-0 data 2 --> data r4-1 */
895                for (j = 2; j < r4; j++)
896                {
897                        index = l*r234+j;
898                        index2D = j;
899
900                        pred1D = 2*P1[index2D-1] - P1[index2D-2];
901                        diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred1D);
902
903                        itvNum = llabs(diff)/realPrecision + 1;
904
905                        if (itvNum < exe_params->intvCapacity)
906                        {
907                                if (diff < 0) itvNum = -itvNum;
908                                type[index] = (int) (itvNum/2) + exe_params->intvRadius;
909                                P1[index2D] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
910                        }
911                        else
912                        {
913                                type[index] = 0;
914
915                                curValue = P1[index2D] = spaceFillingValue[0];
916                                compressUInt64Value(curValue, minValue, byteSize, bytes);
917                                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
918                        }
919                }
920
921                /* Process Row-1 --> Row-r3-1 */
922                for (i = 1; i < r3; i++)
923                {
924                        /* Process row-i data 0 */
925                        index = l*r234+i*r4;
926                        index2D = i*r4;
927
928                        pred1D = P1[index2D-r4];
929                        diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred1D);
930
931                        itvNum = llabs(diff)/realPrecision + 1;
932
933                        if (itvNum < exe_params->intvCapacity)
934                        {
935                                if (diff < 0) itvNum = -itvNum;
936                                type[index] = (int) (itvNum/2) + exe_params->intvRadius;
937                                P1[index2D] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
938                        }
939                        else
940                        {
941                                type[index] = 0;
942
943                                curValue = P1[index2D] = spaceFillingValue[0];
944                                compressUInt64Value(curValue, minValue, byteSize, bytes);
945                                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
946                        }
947
948                        /* Process row-i data 1 --> data r4-1*/
949                        for (j = 1; j < r4; j++)
950                        {
951                                index = l*r234+i*r4+j;
952                                index2D = i*r4+j;
953
954                                pred2D = P1[index2D-1] + P1[index2D-r4] - P1[index2D-r4-1];
955
956                                diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred2D);
957
958                                itvNum = llabs(diff)/realPrecision + 1;
959
960                                if (itvNum < exe_params->intvCapacity)
961                                {
962                                        if (diff < 0) itvNum = -itvNum;
963                                        type[index] = (int) (itvNum/2) + exe_params->intvRadius;
964                                        P1[index2D] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
965                                }
966                                else
967                                {
968                                        type[index] = 0;
969
970                                        curValue = P1[index2D] = spaceFillingValue[0];
971                                        compressUInt64Value(curValue, minValue, byteSize, bytes);
972                                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
973                                }
974                        }
975                }
976
977
978                ///////////////////////////     Process layer-1 --> layer-r2-1 ///////////////////////////
979
980                for (k = 1; k < r2; k++)
981                {
982                        /* Process Row-0 data 0*/
983                        index = l*r234+k*r34;
984                        index2D = 0;
985
986                        pred1D = P1[index2D];
987                        diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred1D);
988
989                        itvNum = llabs(diff)/realPrecision + 1;
990
991                        if (itvNum < exe_params->intvCapacity)
992                        {
993                                if (diff < 0) itvNum = -itvNum;
994                                type[index] = (int) (itvNum/2) + exe_params->intvRadius;
995                                P0[index2D] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
996                        }
997                        else
998                        {
999                                type[index] = 0;
1000
1001                                curValue = P0[index2D] = spaceFillingValue[0];
1002                                compressUInt64Value(curValue, minValue, byteSize, bytes);
1003                                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
1004                        }
1005
1006                        /* Process Row-0 data 1 --> data r4-1 */
1007                        for (j = 1; j < r4; j++)
1008                        {
1009                                index = l*r234+k*r34+j;
1010                                index2D = j;
1011
1012                                pred2D = P0[index2D-1] + P1[index2D] - P1[index2D-1];
1013                                diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred2D);
1014
1015                                itvNum = llabs(diff)/realPrecision + 1;
1016
1017                                if (itvNum < exe_params->intvCapacity)
1018                                {
1019                                        if (diff < 0) itvNum = -itvNum;
1020                                        type[index] = (int) (itvNum/2) + exe_params->intvRadius;
1021                                        P0[index2D] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
1022                                }
1023                                else
1024                                {
1025                                        type[index] = 0;
1026
1027                                        curValue = P0[index2D] = spaceFillingValue[0];
1028                                        compressUInt64Value(curValue, minValue, byteSize, bytes);
1029                                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
1030                                }
1031                        }
1032
1033                        /* Process Row-1 --> Row-r3-1 */
1034                        for (i = 1; i < r3; i++)
1035                        {
1036                                /* Process Row-i data 0 */
1037                                index = l*r234+k*r34+i*r4;
1038                                index2D = i*r4;
1039
1040                                pred2D = P0[index2D-r4] + P1[index2D] - P1[index2D-r4];
1041                                diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred2D);
1042
1043                                itvNum = llabs(diff)/realPrecision + 1;
1044
1045                                if (itvNum < exe_params->intvCapacity)
1046                                {
1047                                        if (diff < 0) itvNum = -itvNum;
1048                                        type[index] = (int) (itvNum/2) + exe_params->intvRadius;
1049                                        P0[index2D] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
1050                                }
1051                                else
1052                                {
1053                                        type[index] = 0;
1054
1055                                        curValue = P0[index2D] = spaceFillingValue[0];
1056                                        compressUInt64Value(curValue, minValue, byteSize, bytes);
1057                                        memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
1058                                }
1059
1060                                /* Process Row-i data 1 --> data r4-1 */
1061                                for (j = 1; j < r4; j++)
1062                                {
1063                                        index = l*r234+k*r34+i*r4+j;
1064                                        index2D = i*r4+j;
1065
1066                                        pred3D = P0[index2D-1] + P0[index2D-r4]+ P1[index2D] - P0[index2D-r4-1] - P1[index2D-r4] - P1[index2D-1] + P1[index2D-r4-1];
1067                                        diff = (int64_t)(spaceFillingValue[index]) - (int64_t)(pred3D);
1068
1069
1070                                        itvNum = llabs(diff)/realPrecision + 1;
1071
1072                                        if (itvNum < exe_params->intvCapacity)
1073                                        {
1074                                                if (diff < 0) itvNum = -itvNum;
1075                                                type[index] = (int) (itvNum/2) + exe_params->intvRadius;
1076                                                P0[index2D] = pred3D + 2 * (type[index] - exe_params->intvRadius) * realPrecision;
1077                                        }
1078                                        else
1079                                        {
1080                                                type[index] = 0;
1081
1082                                                curValue = P0[index2D] = spaceFillingValue[0];
1083                                                compressUInt64Value(curValue, minValue, byteSize, bytes);
1084                                                memcpyDBA_Data(exactDataByteArray, bytes, byteSize);
1085                                        }
1086                                }
1087                        }
1088
1089                        uint64_t *Pt;
1090                        Pt = P1;
1091                        P1 = P0;
1092                        P0 = Pt;
1093                }
1094        }
1095
1096        free(P0);
1097        free(P1);
1098
1099        size_t exactDataNum = exactDataByteArray->size;
1100       
1101        TightDataPointStorageI* tdps;   
1102                       
1103        new_TightDataPointStorageI(&tdps, dataLength, exactDataNum, byteSize, 
1104                        type, exactDataByteArray->array, exactDataByteArray->size, 
1105                        realPrecision, minValue, quantization_intervals, SZ_UINT64);
1106                       
1107        //free memory
1108        free(type);     
1109        free(exactDataByteArray); //exactDataByteArray->array has been released in free_TightDataPointStorageF(tdps);
1110       
1111        return tdps;   
1112}
1113
1114void SZ_compress_args_uint64_NoCkRngeNoGzip_4D(unsigned char** newByteData, uint64_t *oriData, size_t r1, size_t r2, size_t r3, size_t r4, double realPrecision, 
1115size_t *outSize, uint64_t valueRangeSize, uint64_t minValue)
1116{
1117        TightDataPointStorageI* tdps = SZ_compress_uint64_4D_MDQ(oriData, r1, r2, r3, r4, realPrecision, valueRangeSize, minValue);
1118
1119        convertTDPStoFlatBytes_int(tdps, newByteData, outSize);
1120
1121        size_t dataLength = r1*r2*r3*r4;
1122        if(*outSize>dataLength*sizeof(uint64_t))
1123                SZ_compress_args_uint64_StoreOriData(oriData, dataLength, tdps, newByteData, outSize);
1124
1125        free_TightDataPointStorageI(tdps);
1126}
1127
1128void SZ_compress_args_uint64_withinRange(unsigned char** newByteData, uint64_t *oriData, size_t dataLength, size_t *outSize)
1129{
1130        TightDataPointStorageI* tdps = (TightDataPointStorageI*) malloc(sizeof(TightDataPointStorageI));
1131        tdps->typeArray = NULL; 
1132       
1133        tdps->allSameData = 1;
1134        tdps->dataSeriesLength = dataLength;
1135        tdps->exactDataBytes = (unsigned char*)malloc(sizeof(unsigned char)*8);
1136        tdps->isLossless = 0;
1137        //tdps->exactByteSize = 8;
1138        tdps->exactDataNum = 1;
1139        tdps->exactDataBytes_size = 8;
1140       
1141        uint64_t value = oriData[0];
1142        int64ToBytes_bigEndian(tdps->exactDataBytes, value);
1143       
1144        size_t tmpOutSize;
1145        convertTDPStoFlatBytes_int(tdps, newByteData, &tmpOutSize);
1146
1147        *outSize = tmpOutSize;//3+1+sizeof(uint64_t)+SZ_SIZE_TYPE; //8==3+1+4(uint64_size)
1148        free_TightDataPointStorageI(tdps);     
1149}
1150
1151int SZ_compress_args_uint64_wRngeNoGzip(unsigned char** newByteData, uint64_t *oriData, 
1152size_t r5, size_t r4, size_t r3, size_t r2, size_t r1, size_t *outSize, 
1153int errBoundMode, double absErr_Bound, double relBoundRatio)
1154{
1155        int status = SZ_SCES;
1156        size_t dataLength = computeDataLength(r5,r4,r3,r2,r1);
1157        int64_t valueRangeSize = 0;
1158       
1159        uint64_t minValue = computeRangeSize_int(oriData, SZ_UINT64, dataLength, &valueRangeSize);
1160        double realPrecision = getRealPrecision_int(valueRangeSize, errBoundMode, absErr_Bound, relBoundRatio, &status);
1161               
1162        if(valueRangeSize <= realPrecision)
1163        {
1164                SZ_compress_args_uint64_withinRange(newByteData, oriData, dataLength, outSize);
1165        }
1166        else
1167        {
1168//              SZ_compress_args_uint64_NoCkRngeNoGzip_2D(newByteData, oriData, r2, r1, realPrecision, outSize);
1169                if(r5==0&&r4==0&&r3==0&&r2==0)
1170                {
1171                        SZ_compress_args_uint64_NoCkRngeNoGzip_1D(newByteData, oriData, r1, realPrecision, outSize, valueRangeSize, minValue);
1172                }
1173                else if(r5==0&&r4==0&&r3==0)
1174                {
1175                        SZ_compress_args_uint64_NoCkRngeNoGzip_2D(newByteData, oriData, r2, r1, realPrecision, outSize, valueRangeSize, minValue);
1176                }
1177                else if(r5==0&&r4==0)
1178                {
1179                        SZ_compress_args_uint64_NoCkRngeNoGzip_3D(newByteData, oriData, r3, r2, r1, realPrecision, outSize, valueRangeSize, minValue);
1180                }
1181                else if(r5==0)
1182                {
1183                        SZ_compress_args_uint64_NoCkRngeNoGzip_3D(newByteData, oriData, r4*r3, r2, r1, realPrecision, outSize, valueRangeSize, minValue);
1184                }
1185        }
1186        return status;
1187}
1188
1189int SZ_compress_args_uint64(unsigned char** newByteData, uint64_t *oriData, 
1190size_t r5, size_t r4, size_t r3, size_t r2, size_t r1, size_t *outSize, 
1191int errBoundMode, double absErr_Bound, double relBoundRatio)
1192{
1193        confparams_cpr->errorBoundMode = errBoundMode;
1194       
1195        if(errBoundMode>=PW_REL)
1196        {
1197                printf("Error: Current SZ version doesn't support integer data compression with point-wise relative error bound being based on pwrType=AVG\n");
1198                exit(0);
1199                return SZ_NSCS;
1200        }
1201        int status = SZ_SCES;
1202        size_t dataLength = computeDataLength(r5,r4,r3,r2,r1);
1203        int64_t valueRangeSize = 0;
1204
1205        uint64_t minValue = (uint64_t)computeRangeSize_int(oriData, SZ_UINT64, dataLength, &valueRangeSize);
1206        double realPrecision = 0; 
1207       
1208        if(confparams_cpr->errorBoundMode==PSNR)
1209        {
1210                confparams_cpr->errorBoundMode = ABS;
1211                realPrecision = confparams_cpr->absErrBound = computeABSErrBoundFromPSNR(confparams_cpr->psnr, (double)confparams_cpr->predThreshold, (double)valueRangeSize);
1212                //printf("realPrecision=%lf\n", realPrecision);
1213        }
1214        else
1215                realPrecision = getRealPrecision_int(valueRangeSize, errBoundMode, absErr_Bound, relBoundRatio, &status);
1216
1217        if(valueRangeSize <= realPrecision)
1218        {
1219                SZ_compress_args_uint64_withinRange(newByteData, oriData, dataLength, outSize);
1220        }
1221        else
1222        {
1223                size_t tmpOutSize = 0;
1224                unsigned char* tmpByteData;
1225                if (r2==0)
1226                {
1227                        SZ_compress_args_uint64_NoCkRngeNoGzip_1D(&tmpByteData, oriData, r1, realPrecision, &tmpOutSize, valueRangeSize, minValue);
1228                }
1229                else
1230                if (r3==0)
1231                {
1232                        SZ_compress_args_uint64_NoCkRngeNoGzip_2D(&tmpByteData, oriData, r2, r1, realPrecision, &tmpOutSize, valueRangeSize, minValue);
1233                }
1234                else
1235                if (r4==0)
1236                {
1237                        SZ_compress_args_uint64_NoCkRngeNoGzip_3D(&tmpByteData, oriData, r3, r2, r1, realPrecision, &tmpOutSize, valueRangeSize, minValue);
1238                }
1239                else
1240                if (r5==0)
1241                {
1242                        SZ_compress_args_uint64_NoCkRngeNoGzip_4D(&tmpByteData, oriData, r4, r3, r2, r1, realPrecision, &tmpOutSize, valueRangeSize, minValue);
1243                }
1244                else
1245                {
1246                        printf("Error: doesn't support 5 dimensions for now.\n");
1247                        status = SZ_DERR; //dimension error
1248                }
1249                //Call Gzip to do the further compression.
1250                if(confparams_cpr->szMode==SZ_BEST_SPEED)
1251                {
1252                        *outSize = tmpOutSize;
1253                        *newByteData = tmpByteData;
1254                }
1255                else if(confparams_cpr->szMode==SZ_BEST_COMPRESSION || confparams_cpr->szMode==SZ_DEFAULT_COMPRESSION)
1256                {
1257                        *outSize = sz_lossless_compress(confparams_cpr->losslessCompressor, confparams_cpr->gzipMode, tmpByteData, tmpOutSize, newByteData);
1258                        free(tmpByteData);
1259                }
1260                else
1261                {
1262                        printf("Error: Wrong setting of confparams_cpr->szMode in the uint64_t compression.\n");
1263                        status = SZ_MERR; //mode error                 
1264                }
1265        }
1266       
1267        return status;
1268}
Note: See TracBrowser for help on using the repository browser.