1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
/*
Copyright 2019, UCAR/Unidata See COPYRIGHT file for copying and
redistribution conditions.
This program tests netcdf-4 parallel I/O using zlib, shuffle, and
fletcher32 fliters while writing with parallel I/O. This works for
HDF5-1.10.3 and later. In this case HDF5_SUPPORTS_PAR_FILTERS will
be defined during configure.
If szip was built into HDF5, this test will also test parallel szip
writes. If szip is present, then HAVE_H5Z_SZIP will be defined in
config.h.
Ed Hartnett, 12/19/2019
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <mpi.h>
#define FILE_NAME "tst_parallel_compress.nc"
#define NDIMS 3
#define DIMSIZE 24
#define QTR_DATA (DIMSIZE * DIMSIZE / 4)
#define NUM_PROC 4
#define NUM_SLABS 10
#define NUM_SHUFFLE_SETTINGS 2
#ifdef HAVE_H5Z_SZIP
#define NUM_COMPRESSION_FILTERS 2
#else
#define NUM_COMPRESSION_FILTERS 1
#endif
int
main(int argc, char **argv)
{
/* MPI stuff. */
int mpi_size, mpi_rank;
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Info info = MPI_INFO_NULL;
/* Netcdf-4 stuff. */
int ncid, v1id, dimids[NDIMS];
size_t start[NDIMS], count[NDIMS];
int f, i, s, res;
int *slab_data; /* one slab */
/* Initialize MPI. */
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
/* Allocate data. */
if (!(slab_data = malloc(sizeof(int) * DIMSIZE * DIMSIZE / mpi_size))) ERR;
/* Create phony data. We're going to write a 24x24 array of ints,
in 4 sets of 144. */
for (i = 0; i < DIMSIZE * DIMSIZE / mpi_size; i++)
slab_data[i] = mpi_rank;
if (!mpi_rank)
printf("\n*** Testing parallel writes with compression filters.\n");
{
for (f = 0; f < NUM_COMPRESSION_FILTERS; f++)
{
for (s = 0; s < NUM_SHUFFLE_SETTINGS; s++)
{
if (!mpi_rank)
{
printf("*** testing simple write with %s shuffle %d...",
(f ? "szip" : "zlib"), s);
}
/* nc_set_log_level(3); */
/* Create a parallel netcdf-4 file. */
if (nc_create_par(FILE_NAME, NC_NETCDF4, comm, info, &ncid)) ERR;
/* Create three dimensions. */
if (nc_def_dim(ncid, "d1", DIMSIZE, dimids)) ERR;
if (nc_def_dim(ncid, "d2", DIMSIZE, &dimids[1])) ERR;
if (nc_def_dim(ncid, "d3", NUM_SLABS, &dimids[2])) ERR;
/* Create one var. Turn on deflation. */
if ((res = nc_def_var(ncid, "v1", NC_INT, NDIMS, dimids, &v1id))) ERR;
/* Setting any filter only will work for HDF5-1.10.3 and later
* versions. */
if (!f)
res = nc_def_var_deflate(ncid, 0, s, 1, 1);
else
{
res = nc_def_var_deflate(ncid, 0, s, 0, 0);
if (!res)
res = nc_def_var_szip(ncid, 0, 32, 32);
}
#ifdef HDF5_SUPPORTS_PAR_FILTERS
if (res) ERR;
#else
if (res != NC_EINVAL) ERR;
#endif
/* Setting fletcher32 only will work for HDF5-1.10.3 and later
* versions. */
res = nc_def_var_fletcher32(ncid, 0, 1);
#ifdef HDF5_SUPPORTS_PAR_FILTERS
if (res) ERR;
#else
if (res != NC_EINVAL) ERR;
#endif
/* Write metadata to file. */
if (nc_enddef(ncid)) ERR;
/* Set up slab for this process. */
start[0] = mpi_rank * DIMSIZE/mpi_size;
start[1] = 0;
count[0] = DIMSIZE/mpi_size;
count[1] = DIMSIZE;
count[2] = 1;
/*printf("mpi_rank=%d start[0]=%d start[1]=%d count[0]=%d count[1]=%d\n",
mpi_rank, start[0], start[1], count[0], count[1]);*/
/* Should not be allowed to change access to independent,
* because filters are in use. */
if (nc_var_par_access(ncid, v1id, NC_INDEPENDENT) != NC_EINVAL) ERR;
/* Write slabs of data. */
for (start[2] = 0; start[2] < NUM_SLABS; start[2]++)
if (nc_put_vara_int(ncid, v1id, start, count, slab_data)) ERR;
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
/* Check file. */
{
int shuffle_in, deflate_in, deflate_level_in;
int options_mask_in, pixels_per_block_in;
int *slab_data_in;
/* Allocate data. */
if (!(slab_data_in = malloc(sizeof(int) * DIMSIZE * DIMSIZE / mpi_size))) ERR;
/* Reopen the file for parallel access. */
if (nc_open_par(FILE_NAME, NC_NOWRITE, comm, info, &ncid)) ERR;
/* Check state of compression. */
if (!f)
{
if (nc_inq_var_deflate(ncid, 0, &shuffle_in, &deflate_in, &deflate_level_in)) ERR;
if ((s && !shuffle_in) || (!s && shuffle_in)) ERR;
if (!deflate_in || deflate_level_in != 1) ERR;
}
else
{
if (nc_inq_var_deflate(ncid, 0, &shuffle_in, NULL, NULL)) ERR;
if ((s && !shuffle_in) || (!s && shuffle_in)) ERR;
if (nc_inq_var_szip(ncid, 0, &options_mask_in, &pixels_per_block_in)) ERR;
}
/* Use parallel I/O to read the data. */
for (start[2] = 0; start[2] < NUM_SLABS; start[2]++)
{
if (nc_get_vara_int(ncid, 0, start, count, slab_data_in)) ERR;
for (i = 0; i < DIMSIZE * DIMSIZE / mpi_size; i++)
if (slab_data_in[i] != mpi_rank) ERR;
}
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
free(slab_data_in);
}
if (!mpi_rank)
SUMMARIZE_ERR;
} /* next shuffle filter test */
} /* next compression filter (zlib and szip) */
/* Now run tests with unlimited dim. */
/* for (f = 0; f < NUM_COMPRESSION_FILTERS; f++) */
for (f = 1; f < NUM_COMPRESSION_FILTERS; f++)
{
for (s = 0; s < NUM_SHUFFLE_SETTINGS; s++)
{
if (!mpi_rank)
{
printf("*** testing write along unlim dim with %s shuffle %d...",
(f ? "szip" : "zlib"), s);
}
/* nc_set_log_level(3); */
/* Create a parallel netcdf-4 file. */
if (nc_create_par(FILE_NAME, NC_NETCDF4, comm, info, &ncid)) ERR;
/* Create three dimensions. */
if (nc_def_dim(ncid, "d1", DIMSIZE, &dimids[1])) ERR;
if (nc_def_dim(ncid, "d2", DIMSIZE, &dimids[2])) ERR;
if (nc_def_dim(ncid, "d3", NC_UNLIMITED, &dimids[0])) ERR;
/* Create one var. Turn on deflation. */
if ((res = nc_def_var(ncid, "v1", NC_INT, NDIMS, dimids, &v1id))) ERR;
/* Setting any filter only will work for HDF5-1.10.3 and later
* versions. */
if (!f)
res = nc_def_var_deflate(ncid, 0, s, 1, 1);
else
{
res = nc_def_var_deflate(ncid, 0, s, 0, 0);
if (!res)
res = nc_def_var_szip(ncid, 0, 32, 32);
}
#ifdef HDF5_SUPPORTS_PAR_FILTERS
if (res) ERR;
#else
if (res != NC_EINVAL) ERR;
#endif
/* Setting fletcher32 only will work for HDF5-1.10.3 and later
* versions. */
res = nc_def_var_fletcher32(ncid, 0, 1);
#ifdef HDF5_SUPPORTS_PAR_FILTERS
if (res) ERR;
#else
if (res != NC_EINVAL) ERR;
#endif
/* Write metadata to file. */
if (nc_enddef(ncid)) ERR;
/* Set up slab for this process. */
start[1] = mpi_rank * DIMSIZE/mpi_size;
start[2] = 0;
count[1] = DIMSIZE/mpi_size;
count[2] = DIMSIZE;
count[0] = 1;
/*printf("mpi_rank=%d start[0]=%d start[1]=%d count[0]=%d count[1]=%d\n",
mpi_rank, start[0], start[1], count[0], count[1]);*/
/* Should not be allowed to change access to independent,
* because filters are in use. */
if (nc_var_par_access(ncid, v1id, NC_INDEPENDENT) != NC_EINVAL) ERR;
/* Write slabs of data. */
for (start[0] = 0; start[0] < NUM_SLABS; start[0]++)
if (nc_put_vara_int(ncid, v1id, start, count, slab_data)) ERR;
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
/* Check file. */
{
int shuffle_in, deflate_in, deflate_level_in;
int options_mask_in, pixels_per_block_in;
int *slab_data_in;
/* Allocate data. */
if (!(slab_data_in = malloc(sizeof(int) * DIMSIZE * DIMSIZE / mpi_size))) ERR;
/* Reopen the file for parallel access. */
if (nc_open_par(FILE_NAME, NC_NOWRITE, comm, info, &ncid)) ERR;
/* Check state of compression. */
if (!f)
{
if (nc_inq_var_deflate(ncid, 0, &shuffle_in, &deflate_in, &deflate_level_in)) ERR;
if ((s && !shuffle_in) || (!s && shuffle_in)) ERR;
if (!deflate_in || deflate_level_in != 1) ERR;
}
else
{
if (nc_inq_var_deflate(ncid, 0, &shuffle_in, NULL, NULL)) ERR;
if ((s && !shuffle_in) || (!s && shuffle_in)) ERR;
if (nc_inq_var_szip(ncid, 0, &options_mask_in, &pixels_per_block_in)) ERR;
}
/* Use parallel I/O to read the data. */
for (start[0] = 0; start[0] < NUM_SLABS; start[0]++)
{
if (nc_get_vara_int(ncid, 0, start, count, slab_data_in)) ERR;
for (i = 0; i < DIMSIZE * DIMSIZE / mpi_size; i++)
if (slab_data_in[i] != mpi_rank) ERR;
}
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
free(slab_data_in);
}
if (!mpi_rank)
SUMMARIZE_ERR;
} /* next shuffle filter test */
} /* next compression filter (zlib and szip) */
free(slab_data);
}
/* Shut down MPI. */
MPI_Finalize();
if (!mpi_rank)
FINAL_RESULTS;
return 0;
}
|