#include <stdio.h>
#include <inttypes.h>
#include <blosc2.h>
#define SIZE (1000 * 1000)
int main(void) {
static float data[SIZE];
static float data_out[SIZE];
static float data_dest[SIZE];
size_t isize = SIZE * sizeof(float), osize = SIZE * sizeof(float);
int dsize, csize;
int16_t nthreads, pnthreads;
int i;
for (i = 0; i < SIZE; i++) {
data[i] = (float)i;
}
printf("Blosc version info: %s (%s)\n",
BLOSC2_VERSION_STRING, BLOSC2_VERSION_DATE);
blosc2_init();
for (nthreads = 1; nthreads <= 4; nthreads++) {
pnthreads = blosc2_set_nthreads(nthreads);
printf("Using %d threads (previously using %d)\n", nthreads, pnthreads);
csize = blosc1_compress(5, 1, sizeof(float), isize, data, data_out, osize);
if (csize < 0) {
printf("Compression error. Error code: %d\n", csize);
return csize;
}
printf("Compression: %" PRId64 " -> %d (%.1fx)\n", (int64_t)isize, csize, (1. * (double)isize) /
csize);
dsize = blosc1_decompress(data_out, data_dest, isize);
if (dsize < 0) {
printf("Decompression error. Error code: %d\n", dsize);
return dsize;
}
for (i = 0; i < SIZE; i++) {
if (data[i] != data_dest[i]) {
printf("Decompressed data differs from original!\n");
return -1;
}
}
printf("Successful roundtrip!\n");
}
blosc2_destroy();
return 0;
}