From 96d9415ad3c809e84e7477d0203b3dd210469f42 Mon Sep 17 00:00:00 2001 From: "baptiste.coudray" <baptiste.coudray@etu.hesge.ch> Date: Mon, 16 Aug 2021 17:37:03 +0200 Subject: [PATCH] Updated doc --- src/text/07-automate-elementaire.md | 2 -- src/text/08-jeu-de-la-vie.md | 7 +++--- src/text/09-lattice-boltzmann.md | 33 ++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/text/07-automate-elementaire.md b/src/text/07-automate-elementaire.md index 3fac0db..19af854 100644 --- a/src/text/07-automate-elementaire.md +++ b/src/text/07-automate-elementaire.md @@ -73,7 +73,6 @@ void compute_next_chunk_board(struct dispatch_context *dc, int main(int argc, char *argv[]) { /* ... MPI & Futhark Init ... */ - const int N_ITERATIONS = 100; int elems_dimensions[1] = {600}; struct dispatch_context *disp_context = @@ -85,7 +84,6 @@ int main(int argc, char *argv[]) { compute_next_chunk_elems(disp_context, fut_context, &ci); int8_t *sca = get_data(disp_context); } - /* ... Free resources ... */ } ``` diff --git a/src/text/08-jeu-de-la-vie.md b/src/text/08-jeu-de-la-vie.md index b0a4025..1b16f5e 100644 --- a/src/text/08-jeu-de-la-vie.md +++ b/src/text/08-jeu-de-la-vie.md @@ -50,15 +50,16 @@ void compute_next_chunk_board(struct dispatch_context *dc, } int main(int argc, char *argv[]) { - /* ... */ + /* ... MPI & Futhark Init ... */ int board_dimensions[2] = {800, 800}; struct dispatch_context *disp_context = dispatch_context_new(board_dimensions, MPI_INT8_T, 2); - /* ... */ + /* ... */ + const int N_ITERATIONS = 100; for (int i = 0; i < N_MEASURES; ++i) { compute_next_chunk_board(disp_context, fut_context, &ci); } - /* ... */ + /* ... Free resources ... */ } ``` diff --git a/src/text/09-lattice-boltzmann.md b/src/text/09-lattice-boltzmann.md index 547a991..12e8f1d 100644 --- a/src/text/09-lattice-boltzmann.md +++ b/src/text/09-lattice-boltzmann.md @@ -10,7 +10,38 @@ fundamental research, as it keeps the cycle between the elaboration of a theory ## Distributed version -We implement the Lattice-Boltzmann Method with our library to test it with a three-dimensional cellular automaton. Each cell is containing an array of 27 floats. +We implement the Lattice-Boltzmann Method with our library to test it with a three-dimensional cellular automaton. The code is almost the same as the previous example, so we focus on custom types in this example. A cell in this cellular automaton is of type of array containing 27 floats. In MPI, there is no predeclared type of array, so we need to create one. Thanks to our library, it is possible to do that with a minimum code. + +```c +typedef struct lbm_values { + float values[NB_VALUES]; +} lbm_values_t; + +int main(int argc, char *argv[]) { + /* ... MPI & Futhark Init ... */ + int count = 1; + int block_lengths[] = {NB_VALUES}; + MPI_Aint displacements[] = {offsetof(struct lbm_values, values)}; + MPI_Datatype types[] = {MPI_FLOAT}; + + MPI_Datatype lbm_type = create_type(count, block_lengths, displacements, + types); + + int lbm_dimensions[3] = {400, 400, 400}; + struct dispatch_context *disp_context = + dispatch_context_new(lbm_dimensions, lbm_type, 3); + /* ... Temporal loop & Free resources ... */ +} +```` + +We need to declare a structure specifying a cell, so `lbm_values` is a struct containing an array of 27 floats. After that, in the `main` function, we describe the structure as follows: + +* there is one field (`values`), +* the first field is containing 27 values, +* we compute where is located the field `values` in the structure, +* `values` is of type `MPI_FLOAT`. + +Finally, we call our library function `create_type` with the previous parameters, and it returns an `MPI_Datatype` that can be pass to the function `dispatch_context_new`. ## CPU Benchmarks -- GitLab