diff --git a/README.md b/README.md index a1a7af6..5529078 100644 --- a/README.md +++ b/README.md @@ -378,7 +378,6 @@ in two distinct groups `iter1` and `iter2`. To see your `h5` file in readable file format, you can check the section [Comparison with the `h5dump` command](#compare_h5_h5dump). - ### Ex6. Simplifying the code As you can notice, the %PDI code is quite redundant. @@ -428,6 +427,81 @@ In summary: \attention The `::PDI_multi_expose` is implemented with interlaced share/reclaim pairs. +\attention +When we used `::PDI_multi_expose` with multiple data, the order of appearance +of the arguments of the function corresponds to the order of the `::PDI_share`. + +\attention +To gain a better understanding of the information provided by the trace plugin, +the call order of different "share" is changed in the ex6 after the main loop. + +The order of share is important when we used a metadata. To demonstrate this, +we decompose `::PDI_multi_expose`. + +In the exercise 6, after the main loop, the data `main_field` is shared +before the variable `ii`: +```C +// end of the main loop +PDI_share("main_field", cur, PDI_OUT); // event "on_data" for "main_field" +PDI_share("ii", &ii, PDI_OUT); // update the metadata ii in PDI to 4 +PDI_event("finalization"); +PDI_reclaim("ii"); +PDI_reclaim("main_field"); +``` + +At the end of the main loop, `ii` is equal to 4. Therefore, `cur` corresponds +to the value of `main_field` at iteration 4. + +As `ii` is a metadata, the value is stored by pdi. This value correspond to +the last value of `ii` shared with pdi. Hence, at the end of the main loop, +this value is equal to the value of the previous iteration 3. + +In `::PDI_share`, an event "on_data" on the shared data is automatically +performed. An example of this event is +```yaml +decl_hdf5: + - file: ex6-final-iteration.h5 + write: [ main_field ] + when: '$ii=4' +``` +This event is done when we call +```C +PDI_share("main_field", cur, PDI_OUT); // event "on_data" for "main_field" +``` +But at this moment, the value of `ii` in pdi is still the value of the previous iteration 3. +Therefore, the file `ex6-final-iteration.h5` is not writing on the disk. + +To solve this issue, we need to change the order of the `::PDI_share`: +```C +PDI_share("ii", &ii, PDI_OUT); // update the metadata ii in PDI to 4 +PDI_share("main_field", cur, PDI_OUT); // event "on_data" for "main_field" +PDI_event("finalization"); +PDI_reclaim("main_field"); +PDI_reclaim("ii"); +``` + +or with `::PDI_multi_expose`: + +```C +PDI_multi_expose("finalization", + "ii", &ii, PDI_OUT, + "main_field", cur, PDI_OUT, + NULL); +``` + +\attention +In a `::PDI_multi_expose` if you have a data1 that depend on the data2. +You need to pass the arguments corresponding to data2 before the arguments +corresponding to data1 in this function. + +For example, a vector `V` that depends on its size `N`: +```C +PDI_multi_expose("save_vector_V", + "size_of_vector", &N, PDI_OUT, + "vector_V", V, PDI_OUT, + NULL); +``` + ### Ex7. Writing a selection In this exercise, you will only write a selection of the 2D array in memory diff --git a/ex10.c b/ex10.c index 44fcf75..7c51a4b 100644 --- a/ex10.c +++ b/ex10.c @@ -227,9 +227,9 @@ int main( int argc, char* argv[] ) } // finally share the main field as well as the loop counter after the loop PDI_multi_expose("finalization", - "ii", &ii, PDI_OUT, - "main_field", cur, PDI_OUT, - NULL); + "ii", &ii, PDI_OUT, + "main_field", cur, PDI_OUT, + NULL); // finalize PDI PDI_finalize(); diff --git a/ex11.c b/ex11.c index aba49e2..fd0d6a3 100644 --- a/ex11.c +++ b/ex11.c @@ -300,9 +300,9 @@ int main( int argc, char* argv[] ) } // finally share the main field as well as the loop counter after the loop PDI_multi_expose("finalization", - "ii", &ii, PDI_OUT, - "main_field", cur, PDI_OUT, - NULL); + "ii", &ii, PDI_OUT, + "main_field", cur, PDI_OUT, + NULL); // finalize PDI PDI_finalize(); diff --git a/ex12.c b/ex12.c index fb39968..0c6a5b1 100644 --- a/ex12.c +++ b/ex12.c @@ -282,9 +282,9 @@ int main( int argc, char* argv[] ) } // finally share the main field as well as the loop counter after the loop PDI_multi_expose("finalization", - "ii", &ii, PDI_OUT, - "main_field", cur, PDI_OUT, - NULL); + "ii", &ii, PDI_OUT, + "main_field", cur, PDI_OUT, + NULL); // close the file should_output.dat close_file(); diff --git a/ex3.c b/ex3.c index fd3d7e1..10289a1 100644 --- a/ex3.c +++ b/ex3.c @@ -213,10 +213,10 @@ int main( int argc, char* argv[] ) // the main loop for (; ii<10; ++ii) { // share the loop counter & main field at each iteration - PDI_share("ii", &ii, PDI_OUT); - PDI_reclaim("ii"); + PDI_share("ii", &ii, PDI_OUT); PDI_share("main_field", cur, PDI_OUT); PDI_reclaim("main_field"); + PDI_reclaim("ii"); // compute the values for the next iteration iter(cur, next); diff --git a/ex4.c b/ex4.c index 1816e1a..eb16797 100644 --- a/ex4.c +++ b/ex4.c @@ -228,9 +228,9 @@ int main( int argc, char* argv[] ) double (*tmp)[dsize[1]] = cur; cur = next; next = tmp; } // finally share the loop counter and main field after the main loop body - PDI_share("main_field", cur, PDI_OUT); - PDI_share("ii", &ii, PDI_OUT); + PDI_share("ii", &ii, PDI_OUT); PDI_reclaim("ii"); + PDI_share("main_field", cur, PDI_OUT); PDI_reclaim("main_field"); // finalize PDI diff --git a/ex5.c b/ex5.c index 43f1f82..322e66b 100644 --- a/ex5.c +++ b/ex5.c @@ -231,10 +231,10 @@ int main( int argc, char* argv[] ) // swap the current and next values double (*tmp)[dsize[1]] = cur; cur = next; next = tmp; } - // // finally share the loop counter and main field after the main loop body - PDI_share("main_field", cur, PDI_OUT); - PDI_share("ii", &ii, PDI_OUT); + // finally share the loop counter and main field after the main loop body + PDI_share("ii", &ii, PDI_OUT); PDI_reclaim("ii"); + PDI_share("main_field", cur, PDI_OUT); PDI_reclaim("main_field"); // finalize PDI diff --git a/ex6.c b/ex6.c index ed12ba8..bac3d8f 100644 --- a/ex6.c +++ b/ex6.c @@ -236,11 +236,11 @@ int main( int argc, char* argv[] ) // finally share the main field as well as the loop counter after the loop //*** use PDI_multi_expose to replace PDI_share + event + reclaim //... - PDI_share("ii", &ii, PDI_OUT); PDI_share("main_field", cur, PDI_OUT); + PDI_share("ii", &ii, PDI_OUT); PDI_event("finalization"); - PDI_reclaim("main_field"); PDI_reclaim("ii"); + PDI_reclaim("main_field"); // finalize PDI PDI_finalize(); diff --git a/ex7.c b/ex7.c index babdf3e..dbba767 100644 --- a/ex7.c +++ b/ex7.c @@ -227,9 +227,9 @@ int main( int argc, char* argv[] ) } // finally share the main field as well as the loop counter after the loop PDI_multi_expose("finalization", - "main_field", cur, PDI_OUT, - "ii", &ii, PDI_OUT, - NULL); + "ii", &ii, PDI_OUT, + "main_field", cur, PDI_OUT, + NULL); // finalize PDI PDI_finalize(); diff --git a/ex8.c b/ex8.c index 96cbc53..31ad786 100644 --- a/ex8.c +++ b/ex8.c @@ -227,9 +227,9 @@ int main( int argc, char* argv[] ) } // finally share the main field as well as the loop counter after the loop PDI_multi_expose("finalization", - "main_field", cur, PDI_OUT, - "ii", &ii, PDI_OUT, - NULL); + "ii", &ii, PDI_OUT, + "main_field", cur, PDI_OUT, + NULL); // finalize PDI PDI_finalize(); diff --git a/ex9.c b/ex9.c index b7d20c1..e254438 100644 --- a/ex9.c +++ b/ex9.c @@ -227,9 +227,9 @@ int main( int argc, char* argv[] ) } // finally share the main field as well as the loop counter after the loop PDI_multi_expose("finalization", - "main_field", cur, PDI_OUT, - "ii", &ii, PDI_OUT, - NULL); + "ii", &ii, PDI_OUT, + "main_field", cur, PDI_OUT, + NULL); // finalize PDI PDI_finalize(); diff --git a/solutions/ex12.yml b/solutions/ex12.yml index 7d12327..450ecac 100644 --- a/solutions/ex12.yml +++ b/solutions/ex12.yml @@ -11,7 +11,7 @@ pdi: dsize: { type: array, subtype: int, size: 2 } psize: { type: array, subtype: int, size: 2 } pcoord: { type: array, subtype: int, size: 2 } - should_output: logical + should_output: int switch: int data: # values for which PDI does not keep a copy main_field: { type: array, subtype: double, size: [ '$dsize[0]', '$dsize[1]' ] } diff --git a/solutions/ex2.c b/solutions/ex2.c index ef38ea8..0560cfd 100644 --- a/solutions/ex2.c +++ b/solutions/ex2.c @@ -229,7 +229,7 @@ int main( int argc, char* argv[] ) // swap the current and next values double (*tmp)[dsize[1]] = cur; cur = next; next = tmp; } - //*** finally share the loop counter and main field after the main loop body + // finally share the loop counter and main field after the main loop body PDI_share("ii", &ii, PDI_OUT); PDI_reclaim("ii"); PDI_share("main_field", cur, PDI_OUT); diff --git a/solutions/ex5.c b/solutions/ex5.c index d2f753b..2b0c6dc 100644 --- a/solutions/ex5.c +++ b/solutions/ex5.c @@ -232,9 +232,9 @@ int main( int argc, char* argv[] ) double (*tmp)[dsize[1]] = cur; cur = next; next = tmp; } // finally share the loop counter and main field after the main loop body - PDI_share("main_field", cur, PDI_OUT); - PDI_share("ii", &ii, PDI_OUT); + PDI_share("ii", &ii, PDI_OUT); PDI_reclaim("ii"); + PDI_share("main_field", cur, PDI_OUT); PDI_reclaim("main_field"); // finalize PDI