1 | /** |
---|
2 | * @file sz_int64.c |
---|
3 | * @author Sheng Di |
---|
4 | * @date Aug, 2017 |
---|
5 | * @brief sz_int64, 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_int64.h" |
---|
24 | #include "utility.h" |
---|
25 | |
---|
26 | unsigned int optimize_intervals_int64_1D(int64_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 - 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 | |
---|
69 | unsigned int optimize_intervals_int64_2D(int64_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 - 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 | |
---|
115 | unsigned int optimize_intervals_int64_3D(int64_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 - 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 | |
---|
170 | unsigned int optimize_intervals_int64_4D(int64_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 - 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 | |
---|
225 | TightDataPointStorageI* SZ_compress_int64_1D_MDQ(int64_t *oriData, size_t dataLength, double realPrecision, int64_t valueRangeSize, int64_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_int64_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 | int64_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 | compressInt64Value(spaceFillingValue[0], minValue, byteSize, bytes); |
---|
249 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
250 | listAdd_int(last3CmprsData, spaceFillingValue[0]); |
---|
251 | |
---|
252 | type[1] = 0; |
---|
253 | compressInt64Value(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; |
---|
262 | int64_t predAbsErr; |
---|
263 | double interval = 2*realPrecision; |
---|
264 | |
---|
265 | for(i=2;i<dataLength;i++) |
---|
266 | { |
---|
267 | // if(i==2869438) |
---|
268 | // printf("i=%d\n", i); |
---|
269 | curData = spaceFillingValue[i]; |
---|
270 | //pred = 2*last3CmprsData[0] - last3CmprsData[1]; |
---|
271 | pred = last3CmprsData[0]; |
---|
272 | predAbsErr = llabs(curData - pred); |
---|
273 | if(predAbsErr<checkRadius) |
---|
274 | { |
---|
275 | state = (predAbsErr/realPrecision+1)/2; |
---|
276 | if(curData>=pred) |
---|
277 | { |
---|
278 | type[i] = exe_params->intvRadius+state; |
---|
279 | pred = pred + state*interval; |
---|
280 | } |
---|
281 | else //curData<pred |
---|
282 | { |
---|
283 | type[i] = exe_params->intvRadius-state; |
---|
284 | pred = pred - state*interval; |
---|
285 | } |
---|
286 | /* if(type[i]==0) |
---|
287 | printf("err:type[%d]=0\n", i);*/ |
---|
288 | listAdd_int(last3CmprsData, pred); |
---|
289 | continue; |
---|
290 | } |
---|
291 | |
---|
292 | //unpredictable data processing |
---|
293 | type[i] = 0; |
---|
294 | compressInt64Value(curData, minValue, byteSize, bytes); |
---|
295 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
296 | listAdd_int(last3CmprsData, curData); |
---|
297 | }//end of for |
---|
298 | |
---|
299 | size_t exactDataNum = exactDataByteArray->size / byteSize; |
---|
300 | |
---|
301 | TightDataPointStorageI* tdps; |
---|
302 | |
---|
303 | new_TightDataPointStorageI(&tdps, dataLength, exactDataNum, byteSize, |
---|
304 | type, exactDataByteArray->array, exactDataByteArray->size, |
---|
305 | realPrecision, minValue, quantization_intervals, SZ_INT64); |
---|
306 | |
---|
307 | //sdi:Debug |
---|
308 | /* int sum =0; |
---|
309 | for(i=0;i<dataLength;i++) |
---|
310 | if(type[i]==0) sum++; |
---|
311 | printf("opt_quantizations=%d, exactDataNum=%d, sum=%d\n",quantization_intervals, exactDataNum, sum);*/ |
---|
312 | |
---|
313 | //free memory |
---|
314 | free(type); |
---|
315 | free(exactDataByteArray); //exactDataByteArray->array has been released in free_TightDataPointStorageF(tdps); |
---|
316 | |
---|
317 | return tdps; |
---|
318 | } |
---|
319 | |
---|
320 | void SZ_compress_args_int64_StoreOriData(int64_t* oriData, size_t dataLength, TightDataPointStorageI* tdps, |
---|
321 | unsigned char** newByteData, size_t *outSize) |
---|
322 | { |
---|
323 | int intSize=sizeof(int64_t); |
---|
324 | size_t k = 0, i; |
---|
325 | tdps->isLossless = 1; |
---|
326 | size_t totalByteLength = 3 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 1 + intSize*dataLength; |
---|
327 | *newByteData = (unsigned char*)malloc(totalByteLength); |
---|
328 | |
---|
329 | unsigned char dsLengthBytes[8]; |
---|
330 | for (i = 0; i < 3; i++)//3 |
---|
331 | (*newByteData)[k++] = versionNumber[i]; |
---|
332 | |
---|
333 | if(exe_params->SZ_SIZE_TYPE==4)//1 |
---|
334 | (*newByteData)[k++] = 16; //00010000 |
---|
335 | else |
---|
336 | (*newByteData)[k++] = 80; //01010000: 01000000 indicates the SZ_SIZE_TYPE=8 |
---|
337 | |
---|
338 | convertSZParamsToBytes(confparams_cpr, &((*newByteData)[k])); |
---|
339 | k = k + MetaDataByteLength; |
---|
340 | |
---|
341 | sizeToBytes(dsLengthBytes,dataLength); //SZ_SIZE_TYPE: 4 or 8 |
---|
342 | for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++) |
---|
343 | (*newByteData)[k++] = dsLengthBytes[i]; |
---|
344 | |
---|
345 | if(sysEndianType==BIG_ENDIAN_SYSTEM) |
---|
346 | memcpy((*newByteData)+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE, oriData, dataLength*intSize); |
---|
347 | else |
---|
348 | { |
---|
349 | unsigned char* p = (*newByteData)+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE; |
---|
350 | for(i=0;i<dataLength;i++,p+=intSize) |
---|
351 | int64ToBytes_bigEndian(p, oriData[i]); |
---|
352 | } |
---|
353 | *outSize = totalByteLength; |
---|
354 | } |
---|
355 | |
---|
356 | void SZ_compress_args_int64_NoCkRngeNoGzip_1D(unsigned char** newByteData, int64_t *oriData, |
---|
357 | size_t dataLength, double realPrecision, size_t *outSize, int64_t valueRangeSize, int64_t minValue) |
---|
358 | { |
---|
359 | TightDataPointStorageI* tdps = SZ_compress_int64_1D_MDQ(oriData, dataLength, realPrecision, valueRangeSize, minValue); |
---|
360 | //TODO: return bytes.... |
---|
361 | convertTDPStoFlatBytes_int(tdps, newByteData, outSize); |
---|
362 | if(*outSize > dataLength*sizeof(int64_t)) |
---|
363 | SZ_compress_args_int64_StoreOriData(oriData, dataLength+2, tdps, newByteData, outSize); |
---|
364 | free_TightDataPointStorageI(tdps); |
---|
365 | } |
---|
366 | |
---|
367 | TightDataPointStorageI* SZ_compress_int64_2D_MDQ(int64_t *oriData, size_t r1, size_t r2, double realPrecision, int64_t valueRangeSize, int64_t minValue) |
---|
368 | { |
---|
369 | unsigned char bytes[8] = {0,0,0,0,0,0,0,0}; |
---|
370 | int byteSize = computeByteSizePerIntValue(valueRangeSize); |
---|
371 | |
---|
372 | unsigned int quantization_intervals; |
---|
373 | if(exe_params->optQuantMode==1) |
---|
374 | { |
---|
375 | quantization_intervals = optimize_intervals_int64_2D(oriData, r1, r2, realPrecision); |
---|
376 | updateQuantizationInfo(quantization_intervals); |
---|
377 | } |
---|
378 | else |
---|
379 | quantization_intervals = exe_params->intvCapacity; |
---|
380 | size_t i,j; |
---|
381 | int64_t pred1D, pred2D, curValue; |
---|
382 | int64_t diff = 0.0; |
---|
383 | double itvNum = 0; |
---|
384 | int64_t *P0, *P1; |
---|
385 | |
---|
386 | size_t dataLength = r1*r2; |
---|
387 | |
---|
388 | P0 = (int64_t*)malloc(r2*sizeof(int64_t)); |
---|
389 | memset(P0, 0, r2*sizeof(int64_t)); |
---|
390 | P1 = (int64_t*)malloc(r2*sizeof(int64_t)); |
---|
391 | memset(P1, 0, r2*sizeof(int64_t)); |
---|
392 | |
---|
393 | int* type = (int*) malloc(dataLength*sizeof(int)); |
---|
394 | //type[dataLength]=0; |
---|
395 | |
---|
396 | int64_t* spaceFillingValue = oriData; // |
---|
397 | |
---|
398 | DynamicByteArray *exactDataByteArray; |
---|
399 | new_DBA(&exactDataByteArray, DynArrayInitLen); |
---|
400 | |
---|
401 | type[0] = 0; |
---|
402 | curValue = P1[0] = spaceFillingValue[0]; |
---|
403 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
404 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
405 | |
---|
406 | /* Process Row-0 data 1*/ |
---|
407 | pred1D = P1[0]; |
---|
408 | diff = spaceFillingValue[1] - pred1D; |
---|
409 | |
---|
410 | itvNum = llabs(diff)/realPrecision + 1; |
---|
411 | |
---|
412 | if (itvNum < exe_params->intvCapacity) |
---|
413 | { |
---|
414 | if (diff < 0) itvNum = -itvNum; |
---|
415 | type[1] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
416 | P1[1] = pred1D + 2 * (type[1] - exe_params->intvRadius) * realPrecision; |
---|
417 | } |
---|
418 | else |
---|
419 | { |
---|
420 | type[1] = 0; |
---|
421 | curValue = P1[1] = spaceFillingValue[1]; |
---|
422 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
423 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
424 | } |
---|
425 | |
---|
426 | /* Process Row-0 data 2 --> data r2-1 */ |
---|
427 | for (j = 2; j < r2; j++) |
---|
428 | { |
---|
429 | pred1D = 2*P1[j-1] - P1[j-2]; |
---|
430 | diff = spaceFillingValue[j] - pred1D; |
---|
431 | |
---|
432 | itvNum = llabs(diff)/realPrecision + 1; |
---|
433 | |
---|
434 | if (itvNum < exe_params->intvCapacity) |
---|
435 | { |
---|
436 | if (diff < 0) itvNum = -itvNum; |
---|
437 | type[j] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
438 | P1[j] = pred1D + 2 * (type[j] - exe_params->intvRadius) * realPrecision; |
---|
439 | } |
---|
440 | else |
---|
441 | { |
---|
442 | type[j] = 0; |
---|
443 | curValue = P1[j] = spaceFillingValue[j]; |
---|
444 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
445 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
446 | } |
---|
447 | } |
---|
448 | |
---|
449 | /* Process Row-1 --> Row-r1-1 */ |
---|
450 | size_t index; |
---|
451 | for (i = 1; i < r1; i++) |
---|
452 | { |
---|
453 | /* Process row-i data 0 */ |
---|
454 | index = i*r2; |
---|
455 | pred1D = P1[0]; |
---|
456 | diff = spaceFillingValue[index] - pred1D; |
---|
457 | |
---|
458 | itvNum = llabs(diff)/realPrecision + 1; |
---|
459 | |
---|
460 | if (itvNum < exe_params->intvCapacity) |
---|
461 | { |
---|
462 | if (diff < 0) itvNum = -itvNum; |
---|
463 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
464 | P0[0] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
465 | } |
---|
466 | else |
---|
467 | { |
---|
468 | type[index] = 0; |
---|
469 | curValue = P0[0] = spaceFillingValue[index]; |
---|
470 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
471 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
472 | } |
---|
473 | |
---|
474 | /* Process row-i data 1 --> r2-1*/ |
---|
475 | for (j = 1; j < r2; j++) |
---|
476 | { |
---|
477 | index = i*r2+j; |
---|
478 | pred2D = P0[j-1] + P1[j] - P1[j-1]; |
---|
479 | |
---|
480 | diff = spaceFillingValue[index] - pred2D; |
---|
481 | |
---|
482 | itvNum = llabs(diff)/realPrecision + 1; |
---|
483 | |
---|
484 | if (itvNum < exe_params->intvCapacity) |
---|
485 | { |
---|
486 | if (diff < 0) itvNum = -itvNum; |
---|
487 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
488 | P0[j] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
489 | } |
---|
490 | else |
---|
491 | { |
---|
492 | type[index] = 0; |
---|
493 | curValue = P0[j] = spaceFillingValue[index]; |
---|
494 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
495 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
496 | } |
---|
497 | } |
---|
498 | |
---|
499 | int64_t *Pt; |
---|
500 | Pt = P1; |
---|
501 | P1 = P0; |
---|
502 | P0 = Pt; |
---|
503 | } |
---|
504 | |
---|
505 | if(r2!=1) |
---|
506 | free(P0); |
---|
507 | free(P1); |
---|
508 | |
---|
509 | size_t exactDataNum = exactDataByteArray->size; |
---|
510 | |
---|
511 | TightDataPointStorageI* tdps; |
---|
512 | |
---|
513 | new_TightDataPointStorageI(&tdps, dataLength, exactDataNum, byteSize, |
---|
514 | type, exactDataByteArray->array, exactDataByteArray->size, |
---|
515 | realPrecision, minValue, quantization_intervals, SZ_INT64); |
---|
516 | |
---|
517 | //free memory |
---|
518 | free(type); |
---|
519 | free(exactDataByteArray); //exactDataByteArray->array has been released in free_TightDataPointStorageF(tdps); |
---|
520 | |
---|
521 | return tdps; |
---|
522 | } |
---|
523 | |
---|
524 | /** |
---|
525 | * |
---|
526 | * Note: @r1 is high dimension |
---|
527 | * @r2 is low dimension |
---|
528 | * */ |
---|
529 | void SZ_compress_args_int64_NoCkRngeNoGzip_2D(unsigned char** newByteData, int64_t *oriData, size_t r1, size_t r2, double realPrecision, size_t *outSize, |
---|
530 | int64_t valueRangeSize, int64_t minValue) |
---|
531 | { |
---|
532 | TightDataPointStorageI* tdps = SZ_compress_int64_2D_MDQ(oriData, r1, r2, realPrecision, valueRangeSize, minValue); |
---|
533 | |
---|
534 | convertTDPStoFlatBytes_int(tdps, newByteData, outSize); |
---|
535 | |
---|
536 | size_t dataLength = r1*r2; |
---|
537 | if(*outSize>dataLength*sizeof(int64_t)) |
---|
538 | SZ_compress_args_int64_StoreOriData(oriData, dataLength, tdps, newByteData, outSize); |
---|
539 | |
---|
540 | free_TightDataPointStorageI(tdps); |
---|
541 | } |
---|
542 | |
---|
543 | TightDataPointStorageI* SZ_compress_int64_3D_MDQ(int64_t *oriData, size_t r1, size_t r2, size_t r3, double realPrecision, int64_t valueRangeSize, int64_t minValue) |
---|
544 | { |
---|
545 | unsigned char bytes[8] = {0,0,0,0,0,0,0,0}; |
---|
546 | int byteSize = computeByteSizePerIntValue(valueRangeSize); |
---|
547 | |
---|
548 | unsigned int quantization_intervals; |
---|
549 | if(exe_params->optQuantMode==1) |
---|
550 | { |
---|
551 | quantization_intervals = optimize_intervals_int64_3D(oriData, r1, r2, r3, realPrecision); |
---|
552 | updateQuantizationInfo(quantization_intervals); |
---|
553 | } |
---|
554 | else |
---|
555 | quantization_intervals = exe_params->intvCapacity; |
---|
556 | size_t i,j,k; |
---|
557 | int64_t pred1D, pred2D, pred3D, curValue; |
---|
558 | int64_t diff = 0.0; |
---|
559 | double itvNum = 0; |
---|
560 | int64_t *P0, *P1; |
---|
561 | |
---|
562 | size_t dataLength = r1*r2*r3; |
---|
563 | |
---|
564 | size_t r23 = r2*r3; |
---|
565 | P0 = (int64_t*)malloc(r23*sizeof(int64_t)); |
---|
566 | P1 = (int64_t*)malloc(r23*sizeof(int64_t)); |
---|
567 | |
---|
568 | int* type = (int*) malloc(dataLength*sizeof(int)); |
---|
569 | |
---|
570 | int64_t* spaceFillingValue = oriData; // |
---|
571 | |
---|
572 | DynamicByteArray *exactDataByteArray; |
---|
573 | new_DBA(&exactDataByteArray, DynArrayInitLen); |
---|
574 | |
---|
575 | type[0] = 0; |
---|
576 | P1[0] = spaceFillingValue[0]; |
---|
577 | compressInt64Value(spaceFillingValue[0], minValue, byteSize, bytes); |
---|
578 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
579 | |
---|
580 | /* Process Row-0 data 1*/ |
---|
581 | pred1D = P1[0]; |
---|
582 | diff = spaceFillingValue[1] - pred1D; |
---|
583 | |
---|
584 | itvNum = llabs(diff)/realPrecision + 1; |
---|
585 | |
---|
586 | if (itvNum < exe_params->intvCapacity) |
---|
587 | { |
---|
588 | if (diff < 0) itvNum = -itvNum; |
---|
589 | type[1] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
590 | P1[1] = pred1D + 2 * (type[1] - exe_params->intvRadius) * realPrecision; |
---|
591 | } |
---|
592 | else |
---|
593 | { |
---|
594 | type[1] = 0; |
---|
595 | curValue = P1[1] = spaceFillingValue[1]; |
---|
596 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
597 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
598 | } |
---|
599 | |
---|
600 | /* Process Row-0 data 2 --> data r3-1 */ |
---|
601 | for (j = 2; j < r3; j++) |
---|
602 | { |
---|
603 | pred1D = 2*P1[j-1] - P1[j-2]; |
---|
604 | diff = spaceFillingValue[j] - pred1D; |
---|
605 | |
---|
606 | itvNum = llabs(diff)/realPrecision + 1; |
---|
607 | |
---|
608 | if (itvNum < exe_params->intvCapacity) |
---|
609 | { |
---|
610 | if (diff < 0) itvNum = -itvNum; |
---|
611 | type[j] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
612 | P1[j] = pred1D + 2 * (type[j] - exe_params->intvRadius) * realPrecision; |
---|
613 | } |
---|
614 | else |
---|
615 | { |
---|
616 | type[j] = 0; |
---|
617 | curValue = P1[j] = spaceFillingValue[j]; |
---|
618 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
619 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
620 | } |
---|
621 | } |
---|
622 | |
---|
623 | /* Process Row-1 --> Row-r2-1 */ |
---|
624 | size_t index; |
---|
625 | for (i = 1; i < r2; i++) |
---|
626 | { |
---|
627 | /* Process row-i data 0 */ |
---|
628 | index = i*r3; |
---|
629 | pred1D = P1[index-r3]; |
---|
630 | diff = spaceFillingValue[index] - pred1D; |
---|
631 | |
---|
632 | itvNum = llabs(diff)/realPrecision + 1; |
---|
633 | |
---|
634 | if (itvNum < exe_params->intvCapacity) |
---|
635 | { |
---|
636 | if (diff < 0) itvNum = -itvNum; |
---|
637 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
638 | P1[index] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
639 | } |
---|
640 | else |
---|
641 | { |
---|
642 | type[index] = 0; |
---|
643 | curValue = P1[index] = spaceFillingValue[index]; |
---|
644 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
645 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
646 | } |
---|
647 | |
---|
648 | /* Process row-i data 1 --> data r3-1*/ |
---|
649 | for (j = 1; j < r3; j++) |
---|
650 | { |
---|
651 | index = i*r3+j; |
---|
652 | pred2D = P1[index-1] + P1[index-r3] - P1[index-r3-1]; |
---|
653 | |
---|
654 | diff = spaceFillingValue[index] - pred2D; |
---|
655 | |
---|
656 | itvNum = llabs(diff)/realPrecision + 1; |
---|
657 | |
---|
658 | if (itvNum < exe_params->intvCapacity) |
---|
659 | { |
---|
660 | if (diff < 0) itvNum = -itvNum; |
---|
661 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
662 | P1[index] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
663 | } |
---|
664 | else |
---|
665 | { |
---|
666 | type[index] = 0; |
---|
667 | curValue = P1[index] = spaceFillingValue[index]; |
---|
668 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
669 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
670 | } |
---|
671 | } |
---|
672 | } |
---|
673 | |
---|
674 | |
---|
675 | /////////////////////////// Process layer-1 --> layer-r1-1 /////////////////////////// |
---|
676 | |
---|
677 | for (k = 1; k < r1; k++) |
---|
678 | { |
---|
679 | /* Process Row-0 data 0*/ |
---|
680 | index = k*r23; |
---|
681 | pred1D = P1[0]; |
---|
682 | diff = spaceFillingValue[index] - pred1D; |
---|
683 | |
---|
684 | itvNum = llabs(diff)/realPrecision + 1; |
---|
685 | |
---|
686 | if (itvNum < exe_params->intvCapacity) |
---|
687 | { |
---|
688 | if (diff < 0) itvNum = -itvNum; |
---|
689 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
690 | P0[0] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
691 | } |
---|
692 | else |
---|
693 | { |
---|
694 | type[index] = 0; |
---|
695 | curValue = P0[0] = spaceFillingValue[index]; |
---|
696 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
697 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
698 | } |
---|
699 | |
---|
700 | |
---|
701 | /* Process Row-0 data 1 --> data r3-1 */ |
---|
702 | for (j = 1; j < r3; j++) |
---|
703 | { |
---|
704 | //index = k*r2*r3+j; |
---|
705 | index ++; |
---|
706 | pred2D = P0[j-1] + P1[j] - P1[j-1]; |
---|
707 | diff = spaceFillingValue[index] - pred2D; |
---|
708 | |
---|
709 | itvNum = llabs(diff)/realPrecision + 1; |
---|
710 | |
---|
711 | if (itvNum < exe_params->intvCapacity) |
---|
712 | { |
---|
713 | if (diff < 0) itvNum = -itvNum; |
---|
714 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
715 | P0[j] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
716 | /* if(type[index]==0) |
---|
717 | printf("err:type[%d]=0, index4\n", index); */ |
---|
718 | } |
---|
719 | else |
---|
720 | { |
---|
721 | type[index] = 0; |
---|
722 | curValue = P0[j] = spaceFillingValue[index]; |
---|
723 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
724 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
725 | } |
---|
726 | } |
---|
727 | |
---|
728 | /* Process Row-1 --> Row-r2-1 */ |
---|
729 | size_t index2D; |
---|
730 | for (i = 1; i < r2; i++) |
---|
731 | { |
---|
732 | /* Process Row-i data 0 */ |
---|
733 | index = k*r23 + i*r3; |
---|
734 | index2D = i*r3; |
---|
735 | pred2D = P0[index2D-r3] + P1[index2D] - P1[index2D-r3]; |
---|
736 | diff = spaceFillingValue[index] - pred2D; |
---|
737 | |
---|
738 | itvNum = llabs(diff)/realPrecision + 1; |
---|
739 | |
---|
740 | if (itvNum < exe_params->intvCapacity) |
---|
741 | { |
---|
742 | if (diff < 0) itvNum = -itvNum; |
---|
743 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
744 | P0[index2D] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
745 | } |
---|
746 | else |
---|
747 | { |
---|
748 | type[index] = 0; |
---|
749 | curValue = P0[index2D] = spaceFillingValue[index]; |
---|
750 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
751 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
752 | } |
---|
753 | |
---|
754 | /* Process Row-i data 1 --> data r3-1 */ |
---|
755 | for (j = 1; j < r3; j++) |
---|
756 | { |
---|
757 | // if(k==63&&i==43&&j==27) |
---|
758 | // printf("i=%d\n", i); |
---|
759 | //index = k*r2*r3 + i*r3 + j; |
---|
760 | index ++; |
---|
761 | index2D = i*r3 + j; |
---|
762 | pred3D = P0[index2D-1] + P0[index2D-r3]+ P1[index2D] - P0[index2D-r3-1] - P1[index2D-r3] - P1[index2D-1] + P1[index2D-r3-1]; |
---|
763 | diff = spaceFillingValue[index] - pred3D; |
---|
764 | |
---|
765 | itvNum = llabs(diff)/realPrecision + 1; |
---|
766 | |
---|
767 | if (itvNum < exe_params->intvCapacity) |
---|
768 | { |
---|
769 | if (diff < 0) itvNum = -itvNum; |
---|
770 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
771 | P0[index2D] = pred3D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
772 | } |
---|
773 | else |
---|
774 | { |
---|
775 | type[index] = 0; |
---|
776 | curValue = P0[index2D] = spaceFillingValue[index]; |
---|
777 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
778 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
779 | } |
---|
780 | } |
---|
781 | } |
---|
782 | |
---|
783 | int64_t *Pt; |
---|
784 | Pt = P1; |
---|
785 | P1 = P0; |
---|
786 | P0 = Pt; |
---|
787 | } |
---|
788 | if(r23!=1) |
---|
789 | free(P0); |
---|
790 | free(P1); |
---|
791 | |
---|
792 | size_t exactDataNum = exactDataByteArray->size; |
---|
793 | |
---|
794 | TightDataPointStorageI* tdps; |
---|
795 | |
---|
796 | new_TightDataPointStorageI(&tdps, dataLength, exactDataNum, byteSize, |
---|
797 | type, exactDataByteArray->array, exactDataByteArray->size, |
---|
798 | realPrecision, minValue, quantization_intervals, SZ_INT64); |
---|
799 | |
---|
800 | //free memory |
---|
801 | free(type); |
---|
802 | free(exactDataByteArray); //exactDataByteArray->array has been released in free_TightDataPointStorageF(tdps); |
---|
803 | |
---|
804 | return tdps; |
---|
805 | } |
---|
806 | |
---|
807 | |
---|
808 | void SZ_compress_args_int64_NoCkRngeNoGzip_3D(unsigned char** newByteData, int64_t *oriData, size_t r1, size_t r2, size_t r3, double realPrecision, size_t *outSize, |
---|
809 | int64_t valueRangeSize, int64_t minValue) |
---|
810 | { |
---|
811 | TightDataPointStorageI* tdps = SZ_compress_int64_3D_MDQ(oriData, r1, r2, r3, realPrecision, valueRangeSize, minValue); |
---|
812 | |
---|
813 | convertTDPStoFlatBytes_int(tdps, newByteData, outSize); |
---|
814 | |
---|
815 | size_t dataLength = r1*r2*r3; |
---|
816 | if(*outSize>dataLength*sizeof(int64_t)) |
---|
817 | SZ_compress_args_int64_StoreOriData(oriData, dataLength, tdps, newByteData, outSize); |
---|
818 | |
---|
819 | free_TightDataPointStorageI(tdps); |
---|
820 | } |
---|
821 | |
---|
822 | |
---|
823 | TightDataPointStorageI* SZ_compress_int64_4D_MDQ(int64_t *oriData, size_t r1, size_t r2, size_t r3, size_t r4, double realPrecision, int64_t valueRangeSize, int64_t minValue) |
---|
824 | { |
---|
825 | unsigned char bytes[8] = {0,0,0,0,0,0,0,0}; |
---|
826 | int byteSize = computeByteSizePerIntValue(valueRangeSize); |
---|
827 | |
---|
828 | unsigned int quantization_intervals; |
---|
829 | if(exe_params->optQuantMode==1) |
---|
830 | { |
---|
831 | quantization_intervals = optimize_intervals_int64_4D(oriData, r1, r2, r3, r4, realPrecision); |
---|
832 | updateQuantizationInfo(quantization_intervals); |
---|
833 | } |
---|
834 | else |
---|
835 | quantization_intervals = exe_params->intvCapacity; |
---|
836 | size_t i,j,k; |
---|
837 | int64_t pred1D, pred2D, pred3D, curValue; |
---|
838 | int64_t diff = 0.0; |
---|
839 | double itvNum = 0; |
---|
840 | int64_t *P0, *P1; |
---|
841 | |
---|
842 | size_t dataLength = r1*r2*r3*r4; |
---|
843 | |
---|
844 | size_t r234 = r2*r3*r4; |
---|
845 | size_t r34 = r3*r4; |
---|
846 | |
---|
847 | P0 = (int64_t*)malloc(r34*sizeof(int64_t)); |
---|
848 | P1 = (int64_t*)malloc(r34*sizeof(int64_t)); |
---|
849 | |
---|
850 | int* type = (int*) malloc(dataLength*sizeof(int)); |
---|
851 | |
---|
852 | int64_t* spaceFillingValue = oriData; // |
---|
853 | |
---|
854 | DynamicByteArray *exactDataByteArray; |
---|
855 | new_DBA(&exactDataByteArray, DynArrayInitLen); |
---|
856 | |
---|
857 | size_t l; |
---|
858 | for (l = 0; l < r1; l++) |
---|
859 | { |
---|
860 | |
---|
861 | /////////////////////////// Process layer-0 /////////////////////////// |
---|
862 | /* Process Row-0 data 0*/ |
---|
863 | size_t index = l*r234; |
---|
864 | size_t index2D = 0; |
---|
865 | |
---|
866 | type[index] = 0; |
---|
867 | curValue = P1[index2D] = spaceFillingValue[index]; |
---|
868 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
869 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
870 | |
---|
871 | /* Process Row-0 data 1*/ |
---|
872 | index = l*r234+1; |
---|
873 | index2D = 1; |
---|
874 | |
---|
875 | pred1D = P1[index2D-1]; |
---|
876 | diff = curValue - pred1D; |
---|
877 | |
---|
878 | itvNum = llabs(diff)/realPrecision + 1; |
---|
879 | |
---|
880 | if (itvNum < exe_params->intvCapacity) |
---|
881 | { |
---|
882 | if (diff < 0) itvNum = -itvNum; |
---|
883 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
884 | P1[index2D] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
885 | } |
---|
886 | else |
---|
887 | { |
---|
888 | type[index] = 0; |
---|
889 | |
---|
890 | curValue = P1[index2D] = spaceFillingValue[0]; |
---|
891 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
892 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
893 | } |
---|
894 | |
---|
895 | /* Process Row-0 data 2 --> data r4-1 */ |
---|
896 | for (j = 2; j < r4; j++) |
---|
897 | { |
---|
898 | index = l*r234+j; |
---|
899 | index2D = j; |
---|
900 | |
---|
901 | pred1D = 2*P1[index2D-1] - P1[index2D-2]; |
---|
902 | diff = spaceFillingValue[index] - pred1D; |
---|
903 | |
---|
904 | itvNum = llabs(diff)/realPrecision + 1; |
---|
905 | |
---|
906 | if (itvNum < exe_params->intvCapacity) |
---|
907 | { |
---|
908 | if (diff < 0) itvNum = -itvNum; |
---|
909 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
910 | P1[index2D] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
911 | } |
---|
912 | else |
---|
913 | { |
---|
914 | type[index] = 0; |
---|
915 | |
---|
916 | curValue = P1[index2D] = spaceFillingValue[0]; |
---|
917 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
918 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
919 | } |
---|
920 | } |
---|
921 | |
---|
922 | /* Process Row-1 --> Row-r3-1 */ |
---|
923 | for (i = 1; i < r3; i++) |
---|
924 | { |
---|
925 | /* Process row-i data 0 */ |
---|
926 | index = l*r234+i*r4; |
---|
927 | index2D = i*r4; |
---|
928 | |
---|
929 | pred1D = P1[index2D-r4]; |
---|
930 | diff = spaceFillingValue[index] - pred1D; |
---|
931 | |
---|
932 | itvNum = llabs(diff)/realPrecision + 1; |
---|
933 | |
---|
934 | if (itvNum < exe_params->intvCapacity) |
---|
935 | { |
---|
936 | if (diff < 0) itvNum = -itvNum; |
---|
937 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
938 | P1[index2D] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
939 | } |
---|
940 | else |
---|
941 | { |
---|
942 | type[index] = 0; |
---|
943 | |
---|
944 | curValue = P1[index2D] = spaceFillingValue[0]; |
---|
945 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
946 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
947 | } |
---|
948 | |
---|
949 | /* Process row-i data 1 --> data r4-1*/ |
---|
950 | for (j = 1; j < r4; j++) |
---|
951 | { |
---|
952 | index = l*r234+i*r4+j; |
---|
953 | index2D = i*r4+j; |
---|
954 | |
---|
955 | pred2D = P1[index2D-1] + P1[index2D-r4] - P1[index2D-r4-1]; |
---|
956 | |
---|
957 | diff = spaceFillingValue[index] - pred2D; |
---|
958 | |
---|
959 | itvNum = llabs(diff)/realPrecision + 1; |
---|
960 | |
---|
961 | if (itvNum < exe_params->intvCapacity) |
---|
962 | { |
---|
963 | if (diff < 0) itvNum = -itvNum; |
---|
964 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
965 | P1[index2D] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
966 | } |
---|
967 | else |
---|
968 | { |
---|
969 | type[index] = 0; |
---|
970 | |
---|
971 | curValue = P1[index2D] = spaceFillingValue[0]; |
---|
972 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
973 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
974 | } |
---|
975 | } |
---|
976 | } |
---|
977 | |
---|
978 | |
---|
979 | /////////////////////////// Process layer-1 --> layer-r2-1 /////////////////////////// |
---|
980 | |
---|
981 | for (k = 1; k < r2; k++) |
---|
982 | { |
---|
983 | /* Process Row-0 data 0*/ |
---|
984 | index = l*r234+k*r34; |
---|
985 | index2D = 0; |
---|
986 | |
---|
987 | pred1D = P1[index2D]; |
---|
988 | diff = spaceFillingValue[index] - pred1D; |
---|
989 | |
---|
990 | itvNum = llabs(diff)/realPrecision + 1; |
---|
991 | |
---|
992 | if (itvNum < exe_params->intvCapacity) |
---|
993 | { |
---|
994 | if (diff < 0) itvNum = -itvNum; |
---|
995 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
996 | P0[index2D] = pred1D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
997 | } |
---|
998 | else |
---|
999 | { |
---|
1000 | type[index] = 0; |
---|
1001 | |
---|
1002 | curValue = P0[index2D] = spaceFillingValue[0]; |
---|
1003 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
1004 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
1005 | } |
---|
1006 | |
---|
1007 | /* Process Row-0 data 1 --> data r4-1 */ |
---|
1008 | for (j = 1; j < r4; j++) |
---|
1009 | { |
---|
1010 | index = l*r234+k*r34+j; |
---|
1011 | index2D = j; |
---|
1012 | |
---|
1013 | pred2D = P0[index2D-1] + P1[index2D] - P1[index2D-1]; |
---|
1014 | diff = spaceFillingValue[index] - pred2D; |
---|
1015 | |
---|
1016 | itvNum = llabs(diff)/realPrecision + 1; |
---|
1017 | |
---|
1018 | if (itvNum < exe_params->intvCapacity) |
---|
1019 | { |
---|
1020 | if (diff < 0) itvNum = -itvNum; |
---|
1021 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
1022 | P0[index2D] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
1023 | } |
---|
1024 | else |
---|
1025 | { |
---|
1026 | type[index] = 0; |
---|
1027 | |
---|
1028 | curValue = P0[index2D] = spaceFillingValue[0]; |
---|
1029 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
1030 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
1031 | } |
---|
1032 | } |
---|
1033 | |
---|
1034 | /* Process Row-1 --> Row-r3-1 */ |
---|
1035 | for (i = 1; i < r3; i++) |
---|
1036 | { |
---|
1037 | /* Process Row-i data 0 */ |
---|
1038 | index = l*r234+k*r34+i*r4; |
---|
1039 | index2D = i*r4; |
---|
1040 | |
---|
1041 | pred2D = P0[index2D-r4] + P1[index2D] - P1[index2D-r4]; |
---|
1042 | diff = spaceFillingValue[index] - pred2D; |
---|
1043 | |
---|
1044 | itvNum = llabs(diff)/realPrecision + 1; |
---|
1045 | |
---|
1046 | if (itvNum < exe_params->intvCapacity) |
---|
1047 | { |
---|
1048 | if (diff < 0) itvNum = -itvNum; |
---|
1049 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
1050 | P0[index2D] = pred2D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
1051 | } |
---|
1052 | else |
---|
1053 | { |
---|
1054 | type[index] = 0; |
---|
1055 | |
---|
1056 | curValue = P0[index2D] = spaceFillingValue[0]; |
---|
1057 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
1058 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
1059 | } |
---|
1060 | |
---|
1061 | /* Process Row-i data 1 --> data r4-1 */ |
---|
1062 | for (j = 1; j < r4; j++) |
---|
1063 | { |
---|
1064 | index = l*r234+k*r34+i*r4+j; |
---|
1065 | index2D = i*r4+j; |
---|
1066 | |
---|
1067 | pred3D = P0[index2D-1] + P0[index2D-r4]+ P1[index2D] - P0[index2D-r4-1] - P1[index2D-r4] - P1[index2D-1] + P1[index2D-r4-1]; |
---|
1068 | diff = spaceFillingValue[index] - pred3D; |
---|
1069 | |
---|
1070 | |
---|
1071 | itvNum = llabs(diff)/realPrecision + 1; |
---|
1072 | |
---|
1073 | if (itvNum < exe_params->intvCapacity) |
---|
1074 | { |
---|
1075 | if (diff < 0) itvNum = -itvNum; |
---|
1076 | type[index] = (int) (itvNum/2) + exe_params->intvRadius; |
---|
1077 | P0[index2D] = pred3D + 2 * (type[index] - exe_params->intvRadius) * realPrecision; |
---|
1078 | } |
---|
1079 | else |
---|
1080 | { |
---|
1081 | type[index] = 0; |
---|
1082 | |
---|
1083 | curValue = P0[index2D] = spaceFillingValue[0]; |
---|
1084 | compressInt64Value(curValue, minValue, byteSize, bytes); |
---|
1085 | memcpyDBA_Data(exactDataByteArray, bytes, byteSize); |
---|
1086 | } |
---|
1087 | } |
---|
1088 | } |
---|
1089 | |
---|
1090 | int64_t *Pt; |
---|
1091 | Pt = P1; |
---|
1092 | P1 = P0; |
---|
1093 | P0 = Pt; |
---|
1094 | } |
---|
1095 | } |
---|
1096 | |
---|
1097 | free(P0); |
---|
1098 | free(P1); |
---|
1099 | |
---|
1100 | size_t exactDataNum = exactDataByteArray->size; |
---|
1101 | |
---|
1102 | TightDataPointStorageI* tdps; |
---|
1103 | |
---|
1104 | new_TightDataPointStorageI(&tdps, dataLength, exactDataNum, byteSize, |
---|
1105 | type, exactDataByteArray->array, exactDataByteArray->size, |
---|
1106 | realPrecision, minValue, quantization_intervals, SZ_INT64); |
---|
1107 | |
---|
1108 | //free memory |
---|
1109 | free(type); |
---|
1110 | free(exactDataByteArray); //exactDataByteArray->array has been released in free_TightDataPointStorageF(tdps); |
---|
1111 | |
---|
1112 | return tdps; |
---|
1113 | } |
---|
1114 | |
---|
1115 | void SZ_compress_args_int64_NoCkRngeNoGzip_4D(unsigned char** newByteData, int64_t *oriData, size_t r1, size_t r2, size_t r3, size_t r4, double realPrecision, |
---|
1116 | size_t *outSize, int64_t valueRangeSize, int64_t minValue) |
---|
1117 | { |
---|
1118 | TightDataPointStorageI* tdps = SZ_compress_int64_4D_MDQ(oriData, r1, r2, r3, r4, realPrecision, valueRangeSize, minValue); |
---|
1119 | |
---|
1120 | convertTDPStoFlatBytes_int(tdps, newByteData, outSize); |
---|
1121 | |
---|
1122 | size_t dataLength = r1*r2*r3*r4; |
---|
1123 | if(*outSize>dataLength*sizeof(int64_t)) |
---|
1124 | SZ_compress_args_int64_StoreOriData(oriData, dataLength, tdps, newByteData, outSize); |
---|
1125 | |
---|
1126 | free_TightDataPointStorageI(tdps); |
---|
1127 | } |
---|
1128 | |
---|
1129 | void SZ_compress_args_int64_withinRange(unsigned char** newByteData, int64_t *oriData, size_t dataLength, size_t *outSize) |
---|
1130 | { |
---|
1131 | TightDataPointStorageI* tdps = (TightDataPointStorageI*) malloc(sizeof(TightDataPointStorageI)); |
---|
1132 | tdps->typeArray = NULL; |
---|
1133 | |
---|
1134 | tdps->allSameData = 1; |
---|
1135 | tdps->dataSeriesLength = dataLength; |
---|
1136 | tdps->exactDataBytes = (unsigned char*)malloc(sizeof(unsigned char)*8); |
---|
1137 | tdps->isLossless = 0; |
---|
1138 | //tdps->exactByteSize = 4; |
---|
1139 | tdps->exactDataNum = 1; |
---|
1140 | tdps->exactDataBytes_size = 8; |
---|
1141 | |
---|
1142 | int64_t value = oriData[0]; |
---|
1143 | int64ToBytes_bigEndian(tdps->exactDataBytes, value); |
---|
1144 | |
---|
1145 | size_t tmpOutSize; |
---|
1146 | convertTDPStoFlatBytes_int(tdps, newByteData, &tmpOutSize); |
---|
1147 | |
---|
1148 | *outSize = tmpOutSize;//3+1+sizeof(int64_t)+SZ_SIZE_TYPE; //8==3+1+4(int64_size) |
---|
1149 | free_TightDataPointStorageI(tdps); |
---|
1150 | } |
---|
1151 | |
---|
1152 | int SZ_compress_args_int64_wRngeNoGzip(unsigned char** newByteData, int64_t *oriData, |
---|
1153 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1, size_t *outSize, |
---|
1154 | int errBoundMode, double absErr_Bound, double relBoundRatio) |
---|
1155 | { |
---|
1156 | int status = SZ_SCES; |
---|
1157 | size_t dataLength = computeDataLength(r5,r4,r3,r2,r1); |
---|
1158 | int64_t valueRangeSize = 0; |
---|
1159 | |
---|
1160 | int64_t minValue = computeRangeSize_int(oriData, SZ_INT64, dataLength, &valueRangeSize); |
---|
1161 | double realPrecision = getRealPrecision_int(valueRangeSize, errBoundMode, absErr_Bound, relBoundRatio, &status); |
---|
1162 | |
---|
1163 | if(valueRangeSize <= realPrecision) |
---|
1164 | { |
---|
1165 | SZ_compress_args_int64_withinRange(newByteData, oriData, dataLength, outSize); |
---|
1166 | } |
---|
1167 | else |
---|
1168 | { |
---|
1169 | // SZ_compress_args_int64_NoCkRngeNoGzip_2D(newByteData, oriData, r2, r1, realPrecision, outSize); |
---|
1170 | if(r5==0&&r4==0&&r3==0&&r2==0) |
---|
1171 | { |
---|
1172 | SZ_compress_args_int64_NoCkRngeNoGzip_1D(newByteData, oriData, r1, realPrecision, outSize, valueRangeSize, minValue); |
---|
1173 | } |
---|
1174 | else if(r5==0&&r4==0&&r3==0) |
---|
1175 | { |
---|
1176 | SZ_compress_args_int64_NoCkRngeNoGzip_2D(newByteData, oriData, r2, r1, realPrecision, outSize, valueRangeSize, minValue); |
---|
1177 | } |
---|
1178 | else if(r5==0&&r4==0) |
---|
1179 | { |
---|
1180 | SZ_compress_args_int64_NoCkRngeNoGzip_3D(newByteData, oriData, r3, r2, r1, realPrecision, outSize, valueRangeSize, minValue); |
---|
1181 | } |
---|
1182 | else if(r5==0) |
---|
1183 | { |
---|
1184 | SZ_compress_args_int64_NoCkRngeNoGzip_3D(newByteData, oriData, r4*r3, r2, r1, realPrecision, outSize, valueRangeSize, minValue); |
---|
1185 | } |
---|
1186 | } |
---|
1187 | return status; |
---|
1188 | } |
---|
1189 | |
---|
1190 | int SZ_compress_args_int64(unsigned char** newByteData, int64_t *oriData, |
---|
1191 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1, size_t *outSize, |
---|
1192 | int errBoundMode, double absErr_Bound, double relBoundRatio) |
---|
1193 | { |
---|
1194 | confparams_cpr->errorBoundMode = errBoundMode; |
---|
1195 | |
---|
1196 | if(errBoundMode>=PW_REL) |
---|
1197 | { |
---|
1198 | printf("Error: Current SZ version doesn't support integer data compression with point-wise relative error bound being based on pwrType=AVG\n"); |
---|
1199 | exit(0); |
---|
1200 | return SZ_NSCS; |
---|
1201 | } |
---|
1202 | int status = SZ_SCES; |
---|
1203 | size_t dataLength = computeDataLength(r5,r4,r3,r2,r1); |
---|
1204 | int64_t valueRangeSize = 0; |
---|
1205 | |
---|
1206 | int64_t minValue = (int64_t)computeRangeSize_int(oriData, SZ_INT64, dataLength, &valueRangeSize); |
---|
1207 | double realPrecision = 0; |
---|
1208 | |
---|
1209 | if(confparams_cpr->errorBoundMode==PSNR) |
---|
1210 | { |
---|
1211 | confparams_cpr->errorBoundMode = ABS; |
---|
1212 | realPrecision = confparams_cpr->absErrBound = computeABSErrBoundFromPSNR(confparams_cpr->psnr, (double)confparams_cpr->predThreshold, (double)valueRangeSize); |
---|
1213 | //printf("realPrecision=%lf\n", realPrecision); |
---|
1214 | } |
---|
1215 | else |
---|
1216 | realPrecision = getRealPrecision_int(valueRangeSize, errBoundMode, absErr_Bound, relBoundRatio, &status); |
---|
1217 | |
---|
1218 | if(valueRangeSize <= realPrecision) |
---|
1219 | { |
---|
1220 | SZ_compress_args_int64_withinRange(newByteData, oriData, dataLength, outSize); |
---|
1221 | } |
---|
1222 | else |
---|
1223 | { |
---|
1224 | size_t tmpOutSize = 0; |
---|
1225 | unsigned char* tmpByteData; |
---|
1226 | if (r2==0) |
---|
1227 | { |
---|
1228 | SZ_compress_args_int64_NoCkRngeNoGzip_1D(&tmpByteData, oriData, r1, realPrecision, &tmpOutSize, valueRangeSize, minValue); |
---|
1229 | } |
---|
1230 | else |
---|
1231 | if (r3==0) |
---|
1232 | { |
---|
1233 | SZ_compress_args_int64_NoCkRngeNoGzip_2D(&tmpByteData, oriData, r2, r1, realPrecision, &tmpOutSize, valueRangeSize, minValue); |
---|
1234 | } |
---|
1235 | else |
---|
1236 | if (r4==0) |
---|
1237 | { |
---|
1238 | SZ_compress_args_int64_NoCkRngeNoGzip_3D(&tmpByteData, oriData, r3, r2, r1, realPrecision, &tmpOutSize, valueRangeSize, minValue); |
---|
1239 | } |
---|
1240 | else |
---|
1241 | if (r5==0) |
---|
1242 | { |
---|
1243 | SZ_compress_args_int64_NoCkRngeNoGzip_4D(&tmpByteData, oriData, r4, r3, r2, r1, realPrecision, &tmpOutSize, valueRangeSize, minValue); |
---|
1244 | } |
---|
1245 | else |
---|
1246 | { |
---|
1247 | printf("Error: doesn't support 5 dimensions for now.\n"); |
---|
1248 | status = SZ_DERR; //dimension error |
---|
1249 | } |
---|
1250 | //Call Gzip to do the further compression. |
---|
1251 | if(confparams_cpr->szMode==SZ_BEST_SPEED) |
---|
1252 | { |
---|
1253 | *outSize = tmpOutSize; |
---|
1254 | *newByteData = tmpByteData; |
---|
1255 | } |
---|
1256 | else if(confparams_cpr->szMode==SZ_BEST_COMPRESSION || confparams_cpr->szMode==SZ_DEFAULT_COMPRESSION) |
---|
1257 | { |
---|
1258 | *outSize = sz_lossless_compress(confparams_cpr->losslessCompressor, confparams_cpr->gzipMode, tmpByteData, tmpOutSize, newByteData); |
---|
1259 | free(tmpByteData); |
---|
1260 | } |
---|
1261 | else |
---|
1262 | { |
---|
1263 | printf("Error: Wrong setting of confparams_cpr->szMode in the int64_t compression.\n"); |
---|
1264 | status = SZ_MERR; //mode error |
---|
1265 | } |
---|
1266 | } |
---|
1267 | |
---|
1268 | return status; |
---|
1269 | } |
---|