From def84c61c11bd4011f16007e594539cfe3569ff8 Mon Sep 17 00:00:00 2001 From: "jacques.morice" Date: Thu, 21 Nov 2024 22:24:00 +0100 Subject: [PATCH] hdf5_parallel, fix #16 --- README.md | 27 +-- ex9.c | 42 +++-- ex9.h5dump | 430 +++++++++++++++++++++++++++------------------- ex9.yml | 21 ++- solutions/ex9.yml | 6 + 5 files changed, 313 insertions(+), 213 deletions(-) diff --git a/README.md b/README.md index fba05c2..7d9033b 100644 --- a/README.md +++ b/README.md @@ -344,21 +344,23 @@ the selection where to write in the file dataset. Running the code from the previous exercises in parallel should already work and yield one file per process containing the local data block. -In this exercise you will write one single file with parallel HDF5 whose content +In this exercise you will write one single file `ex9.h5`(see `ex9.yml`) with parallel HDF5 whose content should be independent from the number of processes used. -Once again, you only need to modify the YAML file in this exercise, no need to -touch the C file. + +\attention You need to do this exercise with a parallel version of HDF5 and the \ref Decl_HDF5_plugin "Decl'HDF5 plugin" compiled in parallel. + +Once again, you only need to modify the YAML file in this exercise, no need to touch the C file. * Examine the YAML file and compile the code. -The `mpi` plugin was loaded to make sharing MPI communicators possible. +* Load the `mpi` plugin to make sharing MPI communicators possible. -* Uncomment the `communicator` directive of the - \ref Decl_HDF5_plugin "Decl'HDF5 plugin" to switch to parallel I/O and change - the file name so that all processes access the same file. +* Define the `communicator` directive of the \ref Decl_HDF5_plugin "Decl'HDF5 plugin" to switch to parallel I/O for HDF5. + Set the value of the communicator to MPI_COMM_WORLD. -* Set the size of the dataset to take the global (parallel) array size into - account. +\note we have added the directive `collision_policy: write_into` of the \ref Decl_HDF5_plugin "Decl'HDF5 plugin" (see section COLLISION_POLICY). This parameter is used to define what to do when writing to a file or dataset that already exists. + +* Set the size of the dataset to take the global (parallel) array size into account. You will need to multiply the local size by the number of processes in each dimension (use `psize`). @@ -366,11 +368,14 @@ The `mpi` plugin was loaded to make sharing MPI communicators possible. You will need to make a selection in the dataset that depends on the global coordinate of the local data block (use `pcoord`). -Match the output from `ex9.h5dump`, that should be independent from the number -of processes used. You can easily check if the files are the same by running: +You should be able to match the expected output described in `ex9.h5dump`. You can easily check if the files are the same by running: ```bash diff ex9.h5dump <(h5dump ex9*.h5) ``` +To see your `h5` file in readable file format, you can check the section [Comparison with the `h5dump` command](#h5comparison). + +\warning +If you relaunch the executable, remember to delete your old `ex9.h5` file before, otherwise the data will not be changed correctly. ![graphical representation of the parallel I/O](PDI_hdf5_parallel.jpg) diff --git a/ex9.c b/ex9.c index b39225e..275e6c7 100644 --- a/ex9.c +++ b/ex9.c @@ -29,7 +29,6 @@ #include #include -// load the PDI header #include /// size of the local data as [HEIGHT, WIDTH] including ghosts & boundary constants @@ -44,13 +43,32 @@ int pcoord[2]; /// the alpha coefficient used in the computation double alpha; +double L=1.0; +double source1[4]={0.4, 0.4, 0.2, 100}; +double source2[4]={0.7, 0.8, 0.1, 200}; + /** Initialize the data all to 0 except for the left border (XX==0) initialized to 1 million * \param[out] dat the local data to initialize */ void init(double dat[dsize[0]][dsize[1]]) { for (int yy=0; yy0 & $ii<4' @@ -27,5 +32,9 @@ pdi: size: ['$dsize[0]-2', '$dsize[1]-2'] start: [1, 1] dataset_selection: - size: [1, , ] - start: ['$ii-1', , ] + #*** define the size of the dataset selection in (x,y)-direction + #... + size: [1, ..., ...] + #*** modify the start point to avoid overlapping + #... + start: ['$ii-1', ..., ...] diff --git a/solutions/ex9.yml b/solutions/ex9.yml index 2192dd1..0c5da32 100644 --- a/solutions/ex9.yml +++ b/solutions/ex9.yml @@ -14,11 +14,15 @@ pdi: data: # values for which PDI does not keep a copy main_field: { type: array, subtype: double, size: [ '$dsize[0]', '$dsize[1]' ] } plugins: + #*** load the mpi plugin mpi: decl_hdf5: file: ex9.h5 + #*** add MPI communicator communicator: $MPI_COMM_WORLD + collision_policy: write_into datasets: + #*** modify the size of datasets from local array to global array main_field: { type: array, subtype: double, size: [ 3, '$psize[0]*($dsize[0]-2)', '$psize[1]*($dsize[1]-2)' ] } write: main_field: @@ -27,5 +31,7 @@ pdi: size: ['$dsize[0]-2', '$dsize[1]-2'] start: [1, 1] dataset_selection: + #*** define the size of the dataset selection in (x,y)-direction size: [1, '$dsize[0]-2', '$dsize[1]-2'] + #*** modify the start point to avoid overlapping start: ['$ii-1', '$pcoord[0]*($dsize[0]-2)', '$pcoord[1]*($dsize[1]-2)']