Skip to content

Commit c58d469

Browse files
committed
Hands-on update
1 parent 255a4c7 commit c58d469

18 files changed

+1102
-137
lines changed

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#=============================================================================
2323

2424
cmake_minimum_required(VERSION 3.9)
25-
project(pdi_examples LANGUAGES C)
25+
project(pdi_examples LANGUAGES C CXX)
2626

2727
find_package(MPI REQUIRED COMPONENTS C)
2828
find_package(paraconf REQUIRED)
@@ -53,3 +53,6 @@ target_link_libraries(ex7 m MPI::MPI_C paraconf::paraconf PDI::pdi)
5353

5454
add_executable(ex8 ex8.c)
5555
target_link_libraries(ex8 m MPI::MPI_C paraconf::paraconf PDI::pdi)
56+
57+
add_executable(ex9 ex9.c)
58+
target_link_libraries(ex9 m MPI::MPI_C paraconf::paraconf PDI::pdi)

README.md

+95-112
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,21 @@
11
\page Hands_on Hands-on
22

3-
# Environment
4-
5-
This hands-on has been tested on the
6-
[Poincare](https://groupes.renater.fr/wiki/poincare/) machine but it should be
7-
easy to adapt to another machine.
8-
9-
## Poincare machine
3+
# Setup
104

11-
You should load the file `/gpfslocal/pub/pdi/training-env.bash` in your
12-
environment.
13-
To do that, you must source it in every shell you open.
5+
After %PDI \ref Installation installation, you can proceed with getting the sources for the
6+
hands-on tutorial from [gitlab](https://github.com/pdidev/PDI-hands-on).
147

158
```bash
16-
$ source /gpfslocal/pub/pdi/training-env.bash
17-
(load) gnu version 7.3.0
18-
Using gnu compiler to configure openmpi wrappers...
19-
(load) openmpi version 2.1.3_gnu73
20-
(load) hdf5 version 1.10.2_gnu73_openmpi2
21-
(load) PDI version 0.4.0_gnu73_openmpi2
22-
(load) git version 2.19.1
23-
(load) cmake version 3.9.4
24-
PDI training environment loaded!
25-
$ pdi
26-
PDI training environment is available!
9+
git clone https://github.com/pdidev/PDI-hands-on.git
2710
```
2811

29-
# Setup
30-
31-
When %PDI is correctly loaded, you can proceed with getting the sources for the
32-
hands-on tutorial from
33-
[gitlab](https://gitlab.maisondelasimulation.fr/PDI/PDI_hands-on).
34-
12+
To setup your environment run
3513
```bash
36-
git clone https://gitlab.maisondelasimulation.fr/PDI/PDI_hands-on.git
14+
source pdi_path/share/pdi/env.bash
3715
```
16+
where `pdi_path` is your path to installed PDI directory.
3817

39-
Setup the compilation by detecting all dependencies (MPI, paraconf, %PDI, ...)
40-
using cmake:
18+
Next, setup the compilation by detecting all dependencies:
4119
```bash
4220
cd PDI_hands-on
4321
cmake .
@@ -47,75 +25,65 @@ Now you're ready to work, **good luck**!
4725

4826
# Tutorial
4927

50-
## Ex1. Getting started
51-
52-
Ex1 is a simple MPI stencil code.
53-
There is no output in the code yet, so we can not see its result.
54-
Examine the source code, compile it and run it.
28+
Compile exercise by:
29+
```bash
30+
make ex?
31+
```
32+
Run execise by:
5533
```bash
56-
make ex1 # compile the code
57-
llsubmit ex1.sh # run the code
34+
pdirun mpirun -n 1 ./ex?
5835
```
36+
Where `?` is the number of the exercise.
5937

60-
Play with and understand the code parameters in ex1.yml
38+
## Ex1. Getting started
6139

62-
Run the code with 3 MPI processes.
40+
Ex1 is an implementation \ref heat_algorithm mentioned in \ref PDI_example.
41+
If you didn't read it yet, it is recommended to do it before continuing.
42+
There is no input/output operations in the code yet, so we can not see its result.
6343

64-
## Ex2. Now with some PDI
44+
Play with and understand the code parameters in `ex1.yml`.
6545

66-
Ex2 is the same code as ex1 with %PDI calls added.
67-
The %PDI test plugin is used to trace %PDI calls.
46+
Set values in `ex1.yaml` to be able to run the code with 3 MPI processes.
6847

69-
Examine the source code, compile it and run it.
70-
```bash
71-
make ex2 # compile the code
72-
llsubmit ex2.sh # run the code
73-
```
48+
## Ex2. Now with some PDI
49+
50+
Ex2 is the same code as ex1 with %PDI calls added in main function. The
51+
\ref trace_plugin is used to trace %PDI calls.
7452

7553
Add the required `PDI_share` and `PDI_reclaim` calls to match the output of
76-
`ex2.out`.
54+
`ex2.log` file.
55+
56+
Notice that some share/reclaim pairs come one after the other while others are interlaced.
57+
Is one better than the other? If you do not know the answer to this question, please endure
58+
to exercise 5 :)
7759

78-
Notice that some share/reclaim pairs come one after the other while others are
79-
interlaced.
80-
Is one better than the other?
8160

8261
## Ex3. HDF5 through PDI
8362

8463
Let's take the code from ex2 and make it output some HDF5 data.
8564
No need to touch the C code here, the %PDI yaml file should be enough.
86-
We have replaced the %PDI test plugin by the Decl'HDF5 plugin.
87-
88-
Examine the yaml, compile the code and run it.
89-
```bash
90-
make ex3 # compile the code
91-
llsubmit ex3.sh # run the code
92-
```
65+
We have replaced the \ref trace_plugin by \ref Decl_HDF5_plugin.
9366

94-
We need to fill 2 sections in the yaml file:
67+
Fill 2 sections in the yaml file:
9568
* the `data` section to indicate to %PDI the type of the fields that are
9669
exposed,
97-
* the `decl_hdf5` for the configuration of the Decl'HDF5 plugin
70+
* the `decl_hdf5` for the configuration of \ref Decl_HDF5_plugin
9871

9972
Only dsize is written as of now, let's add `psize` and `pcoord` to match the
100-
content expected described in `ex3.out`.
73+
content expected described in `ex3_result.h5` (use `h5dump` command to see content of HDF5 file).
10174

10275
## Ex4. Writing some real data
10376

104-
We keep the same code and touch only the yaml file again.
77+
In this exercise each MPI process will write its local matrix
78+
to separete HDF5 file. Touch only the yaml file again.
10579

10680
This time:
107-
* we will write the real 2D data contained in `main_field`,
108-
* we will use 2 MPI processes.
81+
* write the real 2D data contained in `main_field`,
82+
* use 2 MPI processes.
10983

11084
Notice that we use a list to write multiple files in the decl_hdf5 section
11185
instead of a single mapping as before.
11286

113-
Examine the yaml, compile the code and run it.
114-
```bash
115-
make ex4 # compile the code
116-
llsubmit ex4.sh # run the code
117-
```
118-
11987
Unlike the other fields we manipulated until now, the type of `main_field` is
12088
not fully known, its size is dynamic.
12189
By moving other fields in the `metadata` section, we can reference them from
@@ -128,8 +96,7 @@ In order not to overwrite it every time it is exposed, we can add a `when`
12896
condition to restrict its output.
12997
Only write `main_field` at the second iteration (when `ii==0`).
13098

131-
Change the parallelism degree to 2 in height (don't forget to use 2 processes in
132-
ex4.sh) and try to match the expected content described in `ex4.out`.
99+
Change the parallelism degree to 2 in height and try to match the expected content described in `ex4_result.h5`.
133100

134101
## Ex5. Introducing events
135102

@@ -141,16 +108,9 @@ Since `ii` and `main_field` are shared in an interlaced way, they are both
141108
available at the same time and could be written without opening the file twice.
142109
We have to use events for that.
143110

144-
Examine the yaml and source code, compile and run.
145-
```bash
146-
make ex5 # compile the code
147-
llsubmit ex5.sh # run the code
148-
```
149-
150-
Add a `PDI_event` call to the code when both `ii` and `main_field` are
151-
available.
152-
With the test plugin, check that the event is indeed triggered at the expected
153-
time as described in `ex5-trace.out`.
111+
Call %PDI event named `loop` when both `ii` and `main_field` are shared.
112+
With the \ref trace_plugin, check that the event is indeed triggered at the expected
113+
time as described in `ex5.log`.
154114

155115
Use the `on_event` mechanism to trigger the write of `ii` and `main_field`.
156116
This mechanism can be combined with a `when` directive, in that case the write
@@ -159,21 +119,15 @@ is only executed when both mechanisms agree.
159119
Also notice the extended syntax that make it possible to write data to a dataset
160120
with a name different from the data in %PDI.
161121
Use this mechanism to write main_field at iterations 1 and 2, in two distinct
162-
groups.
163-
Match the content as expected in `ex5-hdf5.out`.
122+
groups `iter1` and `iter2`.
123+
Match the content as expected in `ex5_result.h5`.
164124

165125
## Ex6. Simplifying the code
166126

167127
As you can notice, the %PDI code is quite redundant.
168128
In this exercise, we will use `PDI_expose` and `PDI_multi_expose` to simplify
169129
the code while keeping the exact same behaviour.
170130

171-
Examine the source code, compile it and run it.
172-
```bash
173-
make ex6 # compile the code
174-
llsubmit ex6.sh # run the code
175-
```
176-
177131
There are lots of matched `PDI_share`/`PDI_reclaim` in the code.
178132
Replace these by `PDI_expose` that is the exact equivalent of a `PDI_share`
179133
followed by a matching `PDI_reclaim`.
@@ -186,57 +140,86 @@ Replace the remaining `PDI_share`/`PDI_reclaim` by `PDI_expose`s and
186140
`PDI_multi_expose`s.
187141

188142
Ensure that your code keeps the exact same behaviour by comparing its trace to
189-
`ex6.out`
143+
`ex6.log`.
190144

191-
## Ex7. writing a selection
145+
## Ex7. Writing a selection
192146

193-
In this exercise, we will only write a selection of the data to the HDF5 file.
194-
195-
Examine the yaml, compile the code and run it.
196-
```bash
197-
make ex7 # compile the code
198-
llsubmit ex7.sh # run the code
199-
```
147+
In this exercise, we will only write a selection (part) of the data to the HDF5 file.
200148

201149
As you can notice, we now independantly describe the dataset in the file.
202150
We also use two directives to specify a selection from the data to write and a
203151
selection in the dataset where to write.
204152

153+
- `memory_selection` tells what part to take from the data.
154+
- `dataset_selection` tells where to write this part of data in file.
155+
156+
Here is an example:
157+
```yaml
158+
memory_selection:
159+
size: [8, 8]
160+
subsize: [4, 4]
161+
start: [4, 4]
162+
dataset_selection:
163+
size: [8, 8]
164+
subsize: [4, 4]
165+
start: [4, 0]
166+
```
167+
The graphical representation:
168+
169+
\image html PDI_hdf5_selection.jpg
170+
171+
172+
205173
Restrict the selection to the second line from the data and write it to a
206174
one-dimensional dataset in file.
207175
Match the expected output described in `ex7.out`.
208176

177+
## Ex8. Writing an advanced selection
178+
209179
You can also add dimensions, write the 2D array excluding ghosts as a slab of a
210180
3D dataset including a dimension for the time-iteration.
181+
182+
Here is an example:
183+
```yaml
184+
memory_selection:
185+
size: [8, 8]
186+
subsize: [4, 4]
187+
start: [4, 4]
188+
dataset_selection:
189+
size: [3, 8, 8]
190+
subsize: [1, 4, 4]
191+
start: [$ii, 4, 0]
192+
```
193+
194+
And the graphical representation:
195+
196+
\image html PDI_hdf5_selection_advanced.jpg
197+
211198
Write iterations 1 to 3 inclusive into dimensions 0 to 2.
212-
Match the expected output described in `ex7-bis.out`.
199+
Match the expected output described in `ex8_result.h5`.
213200

214-
## Ex8. going parallel
201+
## Ex9. Going parallel
215202

216203
Running the current code in parallel should already work and yield one file per
217204
process containing the local data block.
218205
In this exercise we will write one single file with parallel HDF5 whose content
219206
should be independent from the number of processes used.
220207

221-
Examine the yaml, compile the code and run it.
222-
```bash
223-
make ex8 # compile the code
224-
llsubmit ex8.sh # run the code
225-
```
226-
227208
We loaded the `mpi` plugin to make sharing MPI communicators possible.
228209

229-
By uncommenting the `communicator` directive of the Decl'HDF5 plugin, we can now
210+
By uncommenting the `communicator` directive of \ref Decl_HDF5_plugin, we can now
230211
switch to parallel I/O.
231212
* Change the file name so all processes open the same file.
232213
* Change the dataset dimension to take the full parallel size into account.
233214
* Ensure the dataset selection of each process does not overlap with the others.
234-
* Try to match the output from `ex8.out` that should be independant from the number of processes used.
215+
* Try to match the output from `ex9.out` that should be independant from the number of processes used.
216+
217+
Here is graphical representation:
218+
219+
\image html PDI_hdf5_parallel.jpg
220+
235221

236222
# What next ?
237223

238224
You can experiment with other \ref Plugins "plugins".
239225
Why not try \ref FlowVR_plugin "FlowVR" for example?
240-
241-
Take a look at the examples in the %PDI repository:
242-
`https://gitlab.maisondelasimulation.fr/jbigot/pdi/tree/0.5/example`

ex2.log

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[PDI][Trace-plugin][15:11:44] *** info: Welcome!
2+
[PDI][15:11:44] *** warning: Data is not defined in specification tree
3+
[PDI][15:11:44] *** info: Initialization successful
4+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: ii
5+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: ii
6+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: pcoord
7+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: pcoord
8+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: dsize
9+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: dsize
10+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: psize
11+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: psize
12+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: main_field
13+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: main_field
14+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: ii
15+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: main_field
16+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: main_field
17+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: ii
18+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: ii
19+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: main_field
20+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: main_field
21+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: ii
22+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: ii
23+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: main_field
24+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: main_field
25+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: ii
26+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: main_field
27+
[PDI][Trace-plugin][15:11:44] *** info: =>> data becoming available in the store: ii
28+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: ii
29+
[PDI][Trace-plugin][15:11:44] *** info: <<= data stop being available in the store: main_field
30+
[PDI][15:11:44] *** info: Finalization
31+
[PDI][Trace-plugin][15:11:44] *** info: Goodbye!

ex2.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ parallelism: { height: 1, width: 1 }
77
# PDI configuration
88
pdi:
99
plugins:
10-
test:
10+
trace: ~

0 commit comments

Comments
 (0)