33In this tutorial, you will build a PDI-enabled application step-by-step from a
44PDI-free base.
55You 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.
911Additional [ examples are available for the other plugins] ( https://gitlab.maisondelasimulation.fr/pdidev/pdi/-/tree/master/example ) .
1012
1113
@@ -58,14 +60,32 @@ pdirun mpirun -n 4 ./ex?
5860Where ` ? ` is the number of the exercise and 4 represents the number of MPI
5961processes to use.
6062
61- #### Execution with storage of the log
63+ #### Execution with storage of the log {#execution-with-storage-of-the-log}
6264
6365To store the logs for later comparison, you can use the following command (for
6466example for ex2.):
6567``` bash
6668pdirun mpirun -n 1 ./ex2 | tee ex2.result.log
6769```
6870
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+
6989Now you're ready to work, ** good luck** !
7090
7191
@@ -114,7 +134,6 @@ read this file.
114134mpirun -np 4 ./ex1
115135```
116136
117-
118137## PDI core & trace plugin
119138
120139### 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
158177` ` `
159178
160179\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+
161185Notice that some share/reclaim pairs come one after the other while others are
162186interlaced.
163187Is one better than the other?
164188If you do not know the answer to this question, just wait until ex5. :)
165189
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-
170190# # Decl'HDF5 plugin
171191
172192From 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.
191211with one MPI process.
192212To achieve this result, you will need to fill 2 sections in the YAML file :
193213
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.
196216
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".
199219
200220* Use the `h5dump` command to see the content of your HDF5 output file in the
201221same format as the h5dump file `ex3.h5dump`. You can easily check if the files
@@ -204,7 +224,7 @@ are the same by running:
204224 diff ex3.h5dump <(h5dump ex3*.h5)
205225` ` `
206226To 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 ).
208228
209229\warning
210230If you relaunch the executable, remember to delete your old `ex3.h5` file before,
237257 #...
238258 dsize: { type: array, subtype: int, size: 2 }
239259` ` `
260+ By definition, a metadata is a variable that can be used to describe other data
261+ (for example, the size of a vector).
240262You can reference them from dynamic "$-expressions" in the configuration file.
241263
242264\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:
264286 diff ex4.h5dump <(h5dump ex4-data-*.h5)
265287` ` `
266288To 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 ).
268290
269291\note A definition of `metadata` and `data` can be :
270292
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.
273295
274296- `data` : values for which PDI does not keep a copy.
275297
@@ -279,22 +301,38 @@ This exercise is done sequentially to facilitate the comparison between logs.
279301
280302# ### Ex 5.1 PDI event and on_event
281303
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.
284321
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.
291329
292330* Examine the YAML file and source code.
293331* In the C file, add a %PDI event named `loop` when both `ii` and
294332 ` main_field` are shared.
295333
296334 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
298336 matching `[Trace-plugin]` have been kept).
299337 Using the previous section [Execution with storage of the log](#execution-with-storage-of-the-log),
300338 run this exercise in saving the output log in the `ex5.result.log`.
@@ -338,7 +376,7 @@ in two distinct groups `iter1` and `iter2`.
338376` ` `
339377
340378 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 ).
342380
343381
344382# ## Ex6. Simplifying the code
@@ -366,8 +404,9 @@ then triggers an event and finally does all the reclaim in reverse order.
366404
367405* Replace the remaining `::PDI_share`/`::PDI_reclaim` by `::PDI_expose`s and
368406 ` ::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
371410 [Execution with storage of the log](#execution-with-storage-of-the-log),
372411 run this exercise in saving the output log in the `ex6.result.log`.
373412 After that you can easily check if the files are the same by running :
@@ -379,8 +418,15 @@ In summary:
379418
3804191. `::PDI_expose` is equivalent to `::PDI_share` + `::PDI_reclaim`.
381420
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`.
383427
428+ \attention
429+ The `::PDI_multi_expose` is implemented with interlaced share/reclaim pairs.
384430
385431# ## Ex7. Writing a selection
386432
@@ -407,7 +453,7 @@ You can easily check if the files are the same by running:
407453 diff ex7.h5dump <(h5dump ex7*.h5)
408454` ` `
409455To 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 ).
411457
412458
413459
@@ -449,7 +495,7 @@ You can easily check if the files are the same by running:
449495 diff ex8.h5dump <(h5dump ex8*.h5)
450496` ` `
451497To 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 ).
453499
454500
455501
@@ -495,7 +541,7 @@ You can easily check if the files are the same by running:
495541 diff ex9.h5dump <(h5dump ex9*.h5)
496542` ` `
497543To 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 ).
499545
500546\warning
501547If 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:
558604 diff ex10.h5dump <(h5dump ex10*.h5)
559605` ` `
560606To 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 ).
562608
563609\warning
564610If you relaunch the executable, remember to delete your old `ex10.h5` file before,
@@ -568,64 +614,6 @@ otherwise the data will not be changed.
568614In a more realistic setup, one would typically not write much code in the YAML
569615file directly, but would instead call functions specified in a `.py` file on the side.
570616
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-
629617# # Call a user C function
630618
631619# ## Ex11. user_code plugin
@@ -694,11 +682,70 @@ indeed done in the expected order in the log.
694682\remark The keywords `on_event` and `on_data` are also used in other plugins
695683to execute instructions in `::PDI_event` and `::PDI_share` respectively.
696684
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+
697743# # What next ?
698744
699745In 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.
702749
703750If you want to try PDI from another language (Fortran, python, ...) or if you
704751want to experiment with other \ref Plugins "PDI plugins", have a look at the
0 commit comments