3
3
In this tutorial, you will build a PDI-enabled application step-by-step from a
4
4
PDI-free base.
5
5
You will end-up building the C version of the
6
- \ref PDI_example "example provided with PDI" for the the
7
- \ref trace_plugin "Trace", \ref Decl_HDF5_plugin "Decl'HDF5", and
8
- \ref pycall_plugin "Pycall" plugins.
6
+ \ref PDI_example "example provided with PDI" for the
7
+ \ref trace_plugin "Trace", \ref Decl_HDF5_plugin "Decl'HDF5",
8
+ \ref pycall_plugin "Pycall",
9
+ \ref user_code_plugin "user_code" and
10
+ \ref set_value_plugin "set_value" plugins.
9
11
Additional [ examples are available for the other plugins] ( https://gitlab.maisondelasimulation.fr/pdidev/pdi/-/tree/master/example ) .
10
12
11
13
@@ -58,14 +60,32 @@ pdirun mpirun -n 4 ./ex?
58
60
Where ` ? ` is the number of the exercise and 4 represents the number of MPI
59
61
processes to use.
60
62
61
- #### Execution with storage of the log
63
+ #### Execution with storage of the log {#execution-with-storage-of-the-log}
62
64
63
65
To store the logs for later comparison, you can use the following command (for
64
66
example for ex2.):
65
67
``` bash
66
68
pdirun mpirun -n 1 ./ex2 | tee ex2.result.log
67
69
```
68
70
71
+ ### How to compare a h5 file with a h5dump file {#compare_h5_h5dump}
72
+
73
+ Using h5dump, you can create a ` h5 ` file with a readable format using.
74
+ ``` bash
75
+ h5dump ex3.h5 > ex3.result.h5dump
76
+ ```
77
+ To compare with the h5dump file of the tutorial (for example ex3).
78
+ ``` bash
79
+ diff ex3.h5dump ex3.result.h5dump
80
+ ```
81
+ Moreover, you can see with your editor the two ` h5dump ` files.
82
+
83
+
84
+ The comparison can be done in one line without creating the ` h5dump ` file.
85
+ ``` bash
86
+ diff ex3.h5dump <( h5dump ex3* .h5)
87
+ ```
88
+
69
89
Now you're ready to work, ** good luck** !
70
90
71
91
@@ -114,7 +134,6 @@ read this file.
114
134
mpirun -np 4 ./ex1
115
135
```
116
136
117
-
118
137
## PDI core & trace plugin
119
138
120
139
### Ex2. Now with some PDI
@@ -158,15 +177,16 @@ After that you can easily check if the files are the same by running the command
158
177
` ` `
159
178
160
179
\attention
180
+ In this exercise, the shared variable and the reclaimed variable are not defined
181
+ in the YAML file (see ex3. and further for this).
182
+
183
+ # ### Note on the order of share/reclaim calls {#ShareReclaimCallsOrder}
184
+
161
185
Notice that some share/reclaim pairs come one after the other while others are
162
186
interlaced.
163
187
Is one better than the other?
164
188
If you do not know the answer to this question, just wait until ex5. :)
165
189
166
- \attention
167
- In this exercise, the shared variable and the reclaimed variable are not defined
168
- in the YAML file (see ex3. and further for this).
169
-
170
190
# # Decl'HDF5 plugin
171
191
172
192
From exercise 3 to exercise 9 included, we present the \ref Decl_HDF5_plugin
@@ -191,11 +211,11 @@ In its configuration, the `dsize` variable is defined as a metadata for %PDI.
191
211
with one MPI process.
192
212
To achieve this result, you will need to fill 2 sections in the YAML file :
193
213
194
- 1. The `data` section to indicate to %PDI the \ref datatype_node "type" of the
195
- fields that are exposed.
214
+ 1. The `data` section to indicate to %PDI the
215
+ \ref datatype_node "data_type" of the fields that are exposed.
196
216
197
- 2. The `decl_hdf5` section for the configuration of the \ref Decl_HDF5_plugin
198
- " Decl'HDF5 plugin" .
217
+ 2. The `decl_hdf5` section for the configuration of the
218
+ \ref Decl_HDF5_plugin "Decl'HDF5 plugin".
199
219
200
220
* Use the `h5dump` command to see the content of your HDF5 output file in the
201
221
same format as the h5dump file `ex3.h5dump`. You can easily check if the files
@@ -204,7 +224,7 @@ are the same by running:
204
224
diff ex3.h5dump <(h5dump ex3*.h5)
205
225
` ` `
206
226
To see your `h5` file in readable file format, you can check the section
207
- [Comparison with the `h5dump` command](#h5comparison ).
227
+ [Comparison with the `h5dump` command](#compare_h5_h5dump ).
208
228
209
229
\warning
210
230
If you relaunch the executable, remember to delete your old `ex3.h5` file before,
237
257
#...
238
258
dsize: { type: array, subtype: int, size: 2 }
239
259
` ` `
260
+ By definition, a metadata is a variable that can be used to describe other data
261
+ (for example, the size of a vector).
240
262
You can reference them from dynamic "$-expressions" in the configuration file.
241
263
242
264
\remark Also notice that this example now runs in parallel with 4 processes.
@@ -264,12 +286,12 @@ You can easily check if the files are the same by running:
264
286
diff ex4.h5dump <(h5dump ex4-data-*.h5)
265
287
` ` `
266
288
To see your `h5` file in readable file format, you can check the section
267
- [Comparison with the `h5dump` command](#h5comparison ).
289
+ [Comparison with the `h5dump` command](#compare_h5_h5dump ).
268
290
269
291
\note A definition of `metadata` and `data` can be :
270
292
271
- - `metadata` : small values for which PDI keeps a copy. These value can be referenced
272
- by using "$-expressions" in the configuration YAML file.
293
+ - `metadata` : small values for which PDI keeps a copy. These value can be
294
+ referenced by using "$-expressions" in the configuration YAML file.
273
295
274
296
- `data` : values for which PDI does not keep a copy.
275
297
@@ -279,22 +301,38 @@ This exercise is done sequentially to facilitate the comparison between logs.
279
301
280
302
# ### Ex 5.1 PDI event and on_event
281
303
282
- In ex4, two variables were written to `ex4-data-*.h5`, but the files were opened
283
- and closed for each and every write.
304
+ In ex4, two variables (`ii` and `main_field`) were written to `ex4-data-*.h5`,
305
+ but the files were opened and closed for each and every write.
306
+
307
+ Since \ref Decl_HDF5_plugin "Decl'HDF5 plugin" only sees the data appear
308
+ one after the other, it does not keep the file open.
309
+ Since `ii` and `main_field` are shared in an interlaced way,
310
+ they are both available to %PDI at the same time after the second
311
+ ` ::PDI_share` .
312
+ ` ` ` C
313
+ // share the loop counter & main field at each iteration
314
+ PDI_share("ii", &ii, PDI_OUT);
315
+ PDI_share("main_field", cur, PDI_OUT);
316
+ PDI_reclaim("main_field");
317
+ PDI_reclaim("ii");
318
+ ` ` `
319
+ Therefore at that moment, they could be written without opening the file twice.
320
+ You have to use events for that.
284
321
285
- Since Decl'HDF5 only sees the data appear one after the other, it does not keep
286
- the file open. Since `ii` and `main_field` are shared in an interlaced way, they
287
- are both available to %PDI at the same time and could be written without opening
288
- the file twice.
289
- You have to use events for that, you will modify both the C and YAML file in this
290
- exercise.
322
+ \attention
323
+ The answer to section [Note on the order of share/reclaim calls](#ShareReclaimCallsOrder)
324
+ is given here.
325
+ Interlacing share/reclaim pairs is better when we want to give access to
326
+ multiple data to %PDI or %PDI plugins at the same time.
327
+
328
+ In this section of ex5, you will modify both the C and YAML file.
291
329
292
330
* Examine the YAML file and source code.
293
331
* In the C file, add a %PDI event named `loop` when both `ii` and
294
332
` main_field` are shared.
295
333
296
334
With the \ref trace_plugin "Trace plugin", check that the event is indeed
297
- triggered at the expected time as described in `ex5.log` (only the lines
335
+ triggered at the expected time as described in `ex5.log` (only the lines
298
336
matching `[Trace-plugin]` have been kept).
299
337
Using the previous section [Execution with storage of the log](#execution-with-storage-of-the-log),
300
338
run this exercise in saving the output log in the `ex5.result.log`.
@@ -338,7 +376,7 @@ in two distinct groups `iter1` and `iter2`.
338
376
` ` `
339
377
340
378
To see your `h5` file in readable file format, you can check the section
341
- [Comparison with the `h5dump` command](#h5comparison ).
379
+ [Comparison with the `h5dump` command](#compare_h5_h5dump ).
342
380
343
381
344
382
# ## Ex6. Simplifying the code
@@ -366,8 +404,9 @@ then triggers an event and finally does all the reclaim in reverse order.
366
404
367
405
* Replace the remaining `::PDI_share`/`::PDI_reclaim` by `::PDI_expose`s and
368
406
` ::PDI_multi_expose` s and ensure that your code keeps the exact same behaviour
369
- as in previous exercise by comparing its trace to `ex6.log` (only the lines matching
370
- ` [Trace-plugin]` have been kept). Using the previous section
407
+ as in previous exercise by comparing its trace to `ex6.log`
408
+ (only the lines matching `[Trace-plugin]` have been kept).
409
+ Using the previous section
371
410
[Execution with storage of the log](#execution-with-storage-of-the-log),
372
411
run this exercise in saving the output log in the `ex6.result.log`.
373
412
After that you can easily check if the files are the same by running :
@@ -379,8 +418,15 @@ In summary:
379
418
380
419
1. `::PDI_expose` is equivalent to `::PDI_share` + `::PDI_reclaim`.
381
420
382
- 2. `::PDI_multi_expose` is equivalent to `::PDI_share` + `::PDI_event` + `::PDI_reclaim`.
421
+ 2. `::PDI_multi_expose` for one data is equivalent to
422
+ ` ::PDI_share` + `::PDI_event` + `::PDI_reclaim`.
423
+
424
+ 3. `::PDI_multi_expose` for data `A` and data `B` is equivalent to
425
+ ` ::PDI_share` ` A` + `::PDI_share` `B`+ `::PDI_event` + `::PDI_reclaim` `B`
426
+ + `::PDI_reclaim` `A`.
383
427
428
+ \attention
429
+ The `::PDI_multi_expose` is implemented with interlaced share/reclaim pairs.
384
430
385
431
# ## Ex7. Writing a selection
386
432
@@ -407,7 +453,7 @@ You can easily check if the files are the same by running:
407
453
diff ex7.h5dump <(h5dump ex7*.h5)
408
454
` ` `
409
455
To see your `h5` file in readable file format,
410
- you can check the section [Comparison with the `h5dump` command](#h5comparison ).
456
+ you can check the section [Comparison with the `h5dump` command](#compare_h5_h5dump ).
411
457
412
458

413
459
@@ -449,7 +495,7 @@ You can easily check if the files are the same by running:
449
495
diff ex8.h5dump <(h5dump ex8*.h5)
450
496
` ` `
451
497
To see your `h5` file in readable file format, you can check the section
452
- [Comparison with the `h5dump` command](#h5comparison ).
498
+ [Comparison with the `h5dump` command](#compare_h5_h5dump ).
453
499
454
500

455
501
@@ -495,7 +541,7 @@ You can easily check if the files are the same by running:
495
541
diff ex9.h5dump <(h5dump ex9*.h5)
496
542
` ` `
497
543
To see your `h5` file in readable file format,
498
- you can check the section [Comparison with the `h5dump` command](#h5comparison ).
544
+ you can check the section [Comparison with the `h5dump` command](#compare_h5_h5dump ).
499
545
500
546
\warning
501
547
If you relaunch the executable, remember to delete your old `ex9.h5` file before,
@@ -558,7 +604,7 @@ You can easily check if the files are the same by running:
558
604
diff ex10.h5dump <(h5dump ex10*.h5)
559
605
` ` `
560
606
To see your `h5` file in readable file format,
561
- you can check the section [Comparison with the `h5dump` command](#h5comparison ).
607
+ you can check the section [Comparison with the `h5dump` command](#compare_h5_h5dump ).
562
608
563
609
\warning
564
610
If you relaunch the executable, remember to delete your old `ex10.h5` file before,
@@ -568,64 +614,6 @@ otherwise the data will not be changed.
568
614
In a more realistic setup, one would typically not write much code in the YAML
569
615
file directly, but would instead call functions specified in a `.py` file on the side.
570
616
571
- # # set value of data and metadata
572
-
573
- # ## Ex12. set_value plugin
574
-
575
- The \ref set_value_plugin "set_value" plugin allows setting values to data and
576
- metadata descriptors from the YAML file.
577
- In the \ref set_value_plugin "set_value", the user can trigger action upon :
578
- ` on_init` , `on_finalize`, `on_data`, `on_event`.
579
- In this plugin, we have five different types of action :
580
- - Share data (`share`) - plugin will share new allocated data with given values.
581
- - Release data (`release`) - plugin will release shared data.
582
- - Expose data (`expose`) - plugin will expose new allocated data
583
- with given values.
584
- - Set data (`set`) - plugin will set given values to the already shared data.
585
- - Calling an event (`event`) - plugin will call an event.
586
-
587
- \note examples with keywords `share`, `release`, `expose`, `set` and `event`
588
- are given at the end of section "set_value" plugin in the website.
589
-
590
- In this exercise, we expose the integer `switch` to %PDI at each iteration.
591
- This interger is used to enable or to disable the writing of `main_field`.
592
- We want to start writing once this integer passes 50 and stop when it's below 25.
593
- For this purpose, we introduce a new logical variable `should_output`
594
- in `ex12.yml`.
595
- The value of `should_output` is defined by :
596
- ` ` ` c
597
- if(switch > 50) should_output = true
598
- if(switch < 25) should_output = false
599
- //otherwise the value of should_output doesn't change.
600
- ` ` `
601
-
602
- * At initialization of %PDI, define the `should_output` to 0 (false).
603
- * At finalization, release the variable `should_output`.
604
- * When `switch` is shared with %PDI, set the value of `should_output`
605
- according to its definition.
606
- \attention
607
- %PDI doesn't known directive `if` in YAML file. Therefore, you need to redefine
608
- the value of `should_output` according to the previous value of `should_output`
609
- and the value of `switch`.
610
-
611
- You should be able to match the expected output described in
612
- ` should_output_solution.dat` .
613
- You can easily check if the files are the same by running :
614
- ` ` ` bash
615
- diff should_output_solution.dat should_output.dat
616
- ` ` `
617
-
618
- * Enable the writing of `main_field` according to the value of `should_output`.
619
-
620
- You should be able to match the expected output described in `ex12.h5dump`.
621
- You can easily check if the files are the same by running :
622
- ` ` ` bash
623
- diff ex12.h5dump <(h5dump ex12*.h5)
624
- ` ` `
625
- To see your `h5` file in readable file format,
626
- you can check the section [Comparison with the `h5dump` command](#h5comparison).
627
-
628
-
629
617
# # Call a user C function
630
618
631
619
# ## Ex11. user_code plugin
@@ -694,11 +682,70 @@ indeed done in the expected order in the log.
694
682
\remark The keywords `on_event` and `on_data` are also used in other plugins
695
683
to execute instructions in `::PDI_event` and `::PDI_share` respectively.
696
684
685
+
686
+ # # set value of data and metadata
687
+
688
+ # ## Ex12. set_value plugin
689
+
690
+ The \ref set_value_plugin "set_value" plugin allows setting values to data and
691
+ metadata descriptors from the YAML file.
692
+ In the \ref set_value_plugin "set_value", the user can trigger action upon :
693
+ ` on_init` , `on_finalize`, `on_data`, `on_event`.
694
+ In this plugin, we have five different types of action :
695
+ - Share data (`share`) - plugin will share new allocated data with given values.
696
+ - Release data (`release`) - plugin will release shared data.
697
+ - Expose data (`expose`) - plugin will expose new allocated data
698
+ with given values.
699
+ - Set data (`set`) - plugin will set given values to the already shared data.
700
+ - Calling an event (`event`) - plugin will call an event.
701
+
702
+ \note examples with keywords `share`, `release`, `expose`, `set` and `event`
703
+ are given at the end of section "set_value" plugin in the website.
704
+
705
+ In this exercise, we expose the integer `switch` to %PDI at each iteration.
706
+ This interger is used to enable or to disable the writing of `main_field`.
707
+ We want to start writing once this integer passes 50 and stop when it's below 25.
708
+ For this purpose, we introduce a new logical variable `should_output`
709
+ in `ex12.yml`.
710
+ The value of `should_output` is defined by :
711
+ ` ` ` c
712
+ if(switch > 50) should_output = true
713
+ if(switch < 25) should_output = false
714
+ //otherwise the value of should_output doesn't change.
715
+ ` ` `
716
+
717
+ * At initialization of %PDI, define the `should_output` to 0 (false).
718
+ * At finalization, release the variable `should_output`.
719
+ * When `switch` is shared with %PDI, set the value of `should_output`
720
+ according to its definition.
721
+ \attention
722
+ %PDI doesn't known directive `if` in YAML file. Therefore, you need to redefine
723
+ the value of `should_output` according to the previous value of `should_output`
724
+ and the value of `switch`.
725
+
726
+ You should be able to match the expected output described in
727
+ ` should_output_solution.dat` .
728
+ You can easily check if the files are the same by running :
729
+ ` ` ` bash
730
+ diff should_output_solution.dat should_output.dat
731
+ ` ` `
732
+
733
+ * Enable the writing of `main_field` according to the value of `should_output`.
734
+
735
+ You should be able to match the expected output described in `ex12.h5dump`.
736
+ You can easily check if the files are the same by running :
737
+ ` ` ` bash
738
+ diff ex12.h5dump <(h5dump ex12*.h5)
739
+ ` ` `
740
+ To see your `h5` file in readable file format,
741
+ you can check the section [Comparison with the `h5dump` command](#compare_h5_h5dump).
742
+
697
743
# # What next ?
698
744
699
745
In this tutorial, you used the C API of %PDI and from YAML, you used the
700
- \ref trace_plugin "Trace", \ref Decl_HDF5_plugin "Decl'HDF5", and
701
- \ref pycall_plugin "Pycall" plugins.
746
+ \ref trace_plugin "Trace", \ref Decl_HDF5_plugin "Decl'HDF5",
747
+ \ref pycall_plugin "Pycall", \ref user_code_plugin "user_code" and
748
+ \ref set_value_plugin "set_value" plugins.
702
749
703
750
If you want to try PDI from another language (Fortran, python, ...) or if you
704
751
want to experiment with other \ref Plugins "PDI plugins", have a look at the
0 commit comments