Skip to content

Commit e033e19

Browse files
authored
18 tutorial update user code plugin (ex11) (#30)
* fix #18, create user_plugin example * change name ex11 to ex_deisa * fix visibility + CMakeLists.txt * Update README.md Co-authored-by: [email protected] * Update README.md Co-authored-by: [email protected] * Update README.md Co-authored-by: [email protected] * Update ex11.yml Co-authored-by: [email protected] * Update solutions/ex11.yml Co-authored-by: [email protected] * Update README.md Co-authored-by: [email protected] * Update ex11.yml Co-authored-by: [email protected] * Add more comment in ex11 + resolve conversation * Update ex11.c Co-authored-by: [email protected] * Update ex11.c Co-authored-by: [email protected] * Update ex11.c Co-authored-by: [email protected] * small fix + add integral_solution.dat * fix bug and fix comment about ghost * small fix * uniform comment * fix typo --------- Co-authored-by: [email protected] and [email protected]
1 parent c7bc5b1 commit e033e19

14 files changed

+749
-3
lines changed

CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ target_link_libraries(ex9 m MPI::MPI_C paraconf::paraconf PDI::pdi)
6060
add_executable(ex10 ex10.c)
6161
target_link_libraries(ex10 m MPI::MPI_C paraconf::paraconf PDI::pdi)
6262

63-
add_executable(ex12 ex12.c)
64-
target_link_libraries(ex12 m MPI::MPI_C paraconf::paraconf PDI::pdi)
63+
add_executable(ex11 ex11.c)
64+
set_target_properties(ex11 PROPERTIES ENABLE_EXPORTS TRUE)
65+
target_link_libraries(ex11 m MPI::MPI_C paraconf::paraconf PDI::pdi)
6566

66-
add_subdirectory(ex11/)
67+
add_subdirectory(ex_deisa/)

README.md

+68
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,74 @@ To see your `h5` file in readable file format,
626626
you can check the section [Comparison with the `h5dump` command](#h5comparison).
627627

628628

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+
629697
## What next ?
630698

631699
In this tutorial, you used the C API of %PDI and from YAML, you used the

0 commit comments

Comments
 (0)