Skip to content

Redefine the call of share and reclaim #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ex10.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions ex11.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions ex12.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions ex3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ex4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ex5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ex6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions ex7.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions ex8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions ex9.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion solutions/ex12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]' ] }
Expand Down
2 changes: 1 addition & 1 deletion solutions/ex2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions solutions/ex5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down