1999-12-11 06:38:25 +08:00
|
|
|
#include <testphdf5.h>
|
|
|
|
|
|
|
|
#define DIM 2
|
1999-12-20 22:53:44 +08:00
|
|
|
#define SIZE 32
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-12-13 07:12:57 +08:00
|
|
|
void multiple_dset_write(char *filename, int ndatasets)
|
1999-12-11 06:38:25 +08:00
|
|
|
{
|
2000-11-21 08:55:14 +08:00
|
|
|
int i, j, n, mpi_size, mpi_rank;
|
2000-11-18 04:16:09 +08:00
|
|
|
hid_t iof, plist, dataset, memspace, filespace;
|
|
|
|
hssize_t chunk_origin [DIM];
|
|
|
|
hsize_t chunk_dims [DIM], file_dims [DIM];
|
|
|
|
hsize_t count[DIM]={1,1};
|
|
|
|
double outme [SIZE][SIZE];
|
|
|
|
char dname [100];
|
1999-12-11 06:38:25 +08:00
|
|
|
|
|
|
|
|
2000-11-21 08:55:14 +08:00
|
|
|
MPI_Comm_rank (MPI_COMM_WORLD, &mpi_rank);
|
|
|
|
MPI_Comm_size (MPI_COMM_WORLD, &mpi_size);
|
1999-12-20 22:53:44 +08:00
|
|
|
|
2000-11-21 08:55:14 +08:00
|
|
|
VRFY((mpi_size <= SIZE), "mpi_size <= SIZE");
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-11-21 08:55:14 +08:00
|
|
|
chunk_origin [0] = mpi_rank * (SIZE / mpi_size);
|
2000-11-18 04:16:09 +08:00
|
|
|
chunk_origin [1] = 0;
|
2000-11-21 08:55:14 +08:00
|
|
|
chunk_dims [0] = SIZE / mpi_size;
|
2000-11-18 04:16:09 +08:00
|
|
|
chunk_dims [1] = SIZE;
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-11-18 04:16:09 +08:00
|
|
|
for (i = 0; i < DIM; i++)
|
|
|
|
file_dims [i] = SIZE;
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-11-18 04:16:09 +08:00
|
|
|
plist = H5Pcreate (H5P_FILE_ACCESS);
|
|
|
|
H5Pset_fapl_mpio(plist, MPI_COMM_WORLD, MPI_INFO_NULL);
|
|
|
|
iof = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, plist);
|
|
|
|
H5Pclose (plist);
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-11-18 04:16:09 +08:00
|
|
|
memspace = H5Screate_simple (DIM, chunk_dims, NULL);
|
|
|
|
filespace = H5Screate_simple (DIM, file_dims, NULL);
|
|
|
|
H5Sselect_hyperslab (filespace, H5S_SELECT_SET, chunk_origin, chunk_dims, count, chunk_dims);
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-12-13 07:12:57 +08:00
|
|
|
for (n = 0; n < ndatasets; n++) {
|
2000-11-18 04:16:09 +08:00
|
|
|
sprintf (dname, "dataset %d", n);
|
2000-12-13 07:12:57 +08:00
|
|
|
dataset = H5Dcreate (iof, dname, H5T_NATIVE_DOUBLE, filespace, H5P_DEFAULT);
|
|
|
|
VRFY((dataset > 0), dname);
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-11-18 04:16:09 +08:00
|
|
|
/* calculate data to write */
|
|
|
|
for (i = 0; i < SIZE; i++)
|
|
|
|
for (j = 0; j < SIZE; j++)
|
2000-11-21 08:55:14 +08:00
|
|
|
outme [i][j] = n*1000 + mpi_rank;
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-11-18 04:16:09 +08:00
|
|
|
H5Dwrite (dataset, H5T_NATIVE_DOUBLE, memspace, filespace, H5P_DEFAULT, outme);
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-11-18 04:16:09 +08:00
|
|
|
H5Dclose (dataset);
|
|
|
|
if (! ((n+1) % 10)) {
|
|
|
|
printf("created %d datasets\n", n+1);
|
|
|
|
MPI_Barrier(MPI_COMM_WORLD);
|
2000-12-13 07:12:57 +08:00
|
|
|
}
|
2000-10-10 02:23:20 +08:00
|
|
|
}
|
1999-12-11 06:38:25 +08:00
|
|
|
|
2000-11-18 04:16:09 +08:00
|
|
|
H5Sclose (filespace);
|
|
|
|
H5Sclose (memspace);
|
|
|
|
H5Fclose (iof);
|
1999-12-11 06:38:25 +08:00
|
|
|
}
|