3030#include <time.h>
3131
3232#include <paraconf.h>
33- // load the PDI header
3433#include <pdi.h>
3534
3635// size of the local data as [HEIGHT, WIDTH] including the number of ghost
@@ -152,15 +151,13 @@ int main(int argc, char *argv[]) {
152151 MPI_Init (& argc , & argv );
153152
154153 // load the configuration tree
155- PC_tree_t conf = PC_parse_path ("ex2.yml" );
156-
154+ PC_tree_t conf = PC_parse_path ("config.yml" );
155+ PDI_init (PC_get (conf , ".pdi" ));
156+
157157 // NEVER USE MPI_COMM_WORLD IN THE CODE, use our own communicator main_comm
158158 // instead
159159 MPI_Comm main_comm = MPI_COMM_WORLD ;
160160
161- // initialize PDI, it can replace our main communicator by its own
162- PDI_init (PC_get (conf , ".pdi" ));
163-
164161 // load the MPI rank & size
165162 int psize_1d ;
166163 MPI_Comm_size (main_comm , & psize_1d );
@@ -172,8 +169,9 @@ int main(int argc, char *argv[]) {
172169 // load the alpha parameter
173170 PC_double (PC_get (conf , ".alpha" ), & alpha );
174171
175- // load the global data-size
176172 int global_size [2 ];
173+ // load the global data-size
174+ // you can use paraconf to read some parameters from the yml config file
177175 PC_int (PC_get (conf , ".global_size.height" ), & longval );
178176 global_size [0 ] = longval ;
179177 PC_int (PC_get (conf , ".global_size.width" ), & longval );
@@ -211,23 +209,8 @@ int main(int argc, char *argv[]) {
211209 // our loop counter so as to be able to use it outside the loop
212210 int ii = 0 ;
213211
214- //*** share useful configuration bits with PDI
215- //*** pcoord, psize, dsize
216- PDI_share ("pcoord" , pcoord , PDI_OUT );
217- PDI_reclaim ("pcoord" );
218- PDI_share ("psize" , psize , PDI_OUT );
219- PDI_reclaim ("psize" );
220- PDI_share ("dsize" , dsize , PDI_OUT );
221- PDI_reclaim ("dsize" );
222-
223212 // the main loop
224- for (; ii < 4 ; ++ ii ) {
225- // share the loop counter & main field at each iteration
226- PDI_share ("ii" , & ii , PDI_OUT );
227- PDI_share ("main_field" , cur , PDI_OUT );
228- PDI_reclaim ("main_field" );
229- PDI_reclaim ("ii" );
230-
213+ for (; ii < 10 ; ++ ii ) {
231214 // compute the values for the next iteration
232215 iter (cur , next );
233216
@@ -239,21 +222,14 @@ int main(int argc, char *argv[]) {
239222 cur = next ;
240223 next = tmp ;
241224 }
242- // finally share the loop counter and main field after the main loop body
243- PDI_share ("ii" , & ii , PDI_OUT );
244- PDI_reclaim ("ii" );
245- PDI_share ("main_field" , cur , PDI_OUT );
246- PDI_reclaim ("main_field" );
247-
248- // finalize PDI
249- PDI_finalize ();
250225
251226 // destroy the paraconf configuration tree
252227 PC_tree_destroy (& conf );
253228
254229 // free the allocated memory
255230 free (cur );
256231 free (next );
232+ PDI_finalize ();
257233
258234 // finalize MPI
259235 MPI_Finalize ();
0 commit comments