@@ -626,6 +626,74 @@ To see your `h5` file in readable file format,
626
626
you can check the section [Comparison with the `h5dump` command](#h5comparison).
627
627
628
628
629
+ # # Call a user C function
630
+
631
+ # ## Ex11. user_code plugin
632
+
633
+ In this exercise, you will learn how to call a user C function in %PDI with the
634
+ \ref user_code_plugin "user_code plugin".
635
+ Moreover, to reduce the standard output log,
636
+ we run sequentially and we reduce the number of iterations.
637
+
638
+ \attention
639
+ You need to read the section \ref important_notes_node "Important notes"
640
+ before using \ref user_code_plugin "user_code plugin".
641
+ To compile the program `ex11` with Wl,`--export-dynamic` or `-rdynamic`,
642
+ we have added the following line :
643
+ ` ` ` cmake
644
+ set_target_properties(ex11 PROPERTIES ENABLE_EXPORTS TRUE)
645
+ ` ` `
646
+ in the CMakeList.txt provided.
647
+
648
+ The objective is to write the integral of `main_field` on the file
649
+ ` integral.dat` .
650
+ This integral is computed in the C function `compute_integral`
651
+ defined in `ex11.c`.
652
+
653
+ * Examine the C file, the YAML file and compile the code.
654
+
655
+ \remark In the `compute_integral` function, the %PDI function `::PDI_access`
656
+ and `::PDI_release` are called (see \ref annotation "Code annotation").
657
+ For example,
658
+ ` ` ` c
659
+ int *iter;
660
+ PDI_access("ii", (void **)&iter, PDI_IN);
661
+ PDI_release("ii");
662
+ ` ` `
663
+ ` ::PDI_access` sets our pointer (`iter`) to the data location of `ii`.
664
+ We need to pass `PDI_IN` because data flows from PDI to our application.
665
+ We also want to use `::PDI_release`, because `::PDI_reclaim` would end
666
+ the sharing status of this descriptor and we reclaim this data later in
667
+ the main function.
668
+
669
+ The keyword `on_event` allows to call a C function inside `::PDI_event`.
670
+ You can call a user C function inside `::PDI_share`
671
+ using the keyword `on_data` in the \ref user_code_plugin "user_code plugin".
672
+
673
+ In this exercise, we only modify `ex11.yml`.
674
+
675
+ * Open the file `integral.dat` at event “initialization” for recording
676
+ the integral of the `main_field` in calling `open_file` function.
677
+
678
+ * Close the file `integral.dat` at event “finalization” in calling `close_file`
679
+ function.
680
+
681
+ * Compute the integral of `main_field` and write this to the file `integral.dat`
682
+ (using `compute_integral` function) when `main_field` is shared to %PDI.
683
+
684
+ You should be able to match the expected output described
685
+ in `integral_solution.dat`.
686
+ You can easily check if the files are the same by running :
687
+ ` ` ` bash
688
+ diff integral_solution.dat integral.dat
689
+ ` ` `
690
+
691
+ * Check that the call of C functions defined by `on_event` and `on_data` are
692
+ indeed done in the expected order in the log.
693
+
694
+ \remark The keywords `on_event` and `on_data` are also used in other plugins
695
+ to execute instructions in `::PDI_event` and `::PDI_share` respectively.
696
+
629
697
# # What next ?
630
698
631
699
In this tutorial, you used the C API of %PDI and from YAML, you used the
0 commit comments