Skip to content

Commit 271ecb4

Browse files
committed
add exo expose and remove old ex2
1 parent f9f6ad1 commit 271ecb4

File tree

7 files changed

+97
-85
lines changed

7 files changed

+97
-85
lines changed

ex2.log

Lines changed: 0 additions & 28 deletions
This file was deleted.

expose/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#=============================================================================
2+
# Copyright (C) 2015-2023 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
# SOFTWARE.
21+
#=============================================================================
22+
23+
cmake_minimum_required(VERSION 3.16)
24+
project(pdi_init LANGUAGES C)
25+
26+
find_package(spdlog)
27+
find_package(MPI REQUIRED COMPONENTS C)
28+
find_package(paraconf 1.0.0 REQUIRED COMPONENTS C)
29+
find_package(PDI 1.9.0 REQUIRED COMPONENTS C)
30+
31+
set(CMAKE_C_STANDARD 99)
32+
33+
add_executable(main main.c)
34+
target_link_libraries(main m MPI::MPI_C paraconf::paraconf PDI::pdi)
35+
36+

ex2.yml renamed to expose/config.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ alpha: 0.125
33
# global data-size (excluding the number of ghost layers for boundary conditions)
44
global_size: { height: 60, width: 12 }
55
# degree of parallelism (number of blocks in each dimension)
6-
parallelism: { height: 1, width: 1 }
6+
parallelism: { height: 2, width: 2 }
77

88
pdi:
9-
#*** PDI configuration: use the trace plugin to print all the PDI activities
10-
#...

solutions/ex2.c renamed to expose/main.c

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
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();

expose/solution/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#=============================================================================
2+
# Copyright (C) 2015-2023 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
# SOFTWARE.
21+
#=============================================================================
22+
23+
cmake_minimum_required(VERSION 3.16)
24+
project(pdi_init LANGUAGES C)
25+
26+
find_package(spdlog)
27+
find_package(MPI REQUIRED COMPONENTS C)
28+
find_package(paraconf 1.0.0 REQUIRED COMPONENTS C)
29+
find_package(PDI 1.9.0 REQUIRED COMPONENTS C)
30+
31+
set(CMAKE_C_STANDARD 99)
32+
33+
add_executable(main main.c)
34+
target_link_libraries(main m MPI::MPI_C paraconf::paraconf PDI::pdi)
35+
36+

solutions/ex2.yml renamed to expose/solution/config.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ alpha: 0.125
33
# global data-size (excluding the number of ghost layers for boundary conditions)
44
global_size: { height: 60, width: 12 }
55
# degree of parallelism (number of blocks in each dimension)
6-
parallelism: { height: 1, width: 1 }
6+
parallelism: { height: 2, width: 2 }
77

8-
#*** PDI configuration
98
pdi:
9+
metadata:
10+
local_size: {type: array, subtype: int, size: 2}
11+
data:
12+
iteration: int
13+
temp: {type: array, subtype: double, size: ['$local_size[0]', '$local_size[1]']}
1014
plugins:
1115
trace:
12-
logging: { pattern: '[PDI][%n-plugin] *** %l: %v' }

ex2.c renamed to expose/solution/main.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
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);
@@ -195,6 +193,8 @@ int main(int argc, char *argv[]) {
195193
dsize[0] = global_size[0] / psize[0] + 2;
196194
dsize[1] = global_size[1] / psize[1] + 2;
197195

196+
PDI_expose("local_size", dsize, PDI_OUT);
197+
198198
// create a 2D Cartesian MPI communicator & get our coordinate (rank) in it
199199
int cart_period[2] = {1, 1};
200200
MPI_Comm cart_comm;
@@ -211,15 +211,9 @@ int main(int argc, char *argv[]) {
211211
// our loop counter so as to be able to use it outside the loop
212212
int ii = 0;
213213

214-
//*** share useful configuration bits with PDI
215-
//*** pcoord, psize, dsize
216-
//...
217-
218214
// the main loop
219-
for (; ii < 4; ++ii) {
220-
//*** share the loop counter & main field at each iteration
221-
//...
222-
215+
for (; ii < 10; ++ii) {
216+
PDI_expose("temp", cur, PDI_OUT);
223217
// compute the values for the next iteration
224218
iter(cur, next);
225219

@@ -231,18 +225,15 @@ int main(int argc, char *argv[]) {
231225
cur = next;
232226
next = tmp;
233227
}
234-
//*** finally share the loop counter and main field after the main loop body
235-
//...
236-
237-
// finalize PDI
238-
PDI_finalize();
228+
PDI_expose("temp", cur, PDI_OUT);
239229

240230
// destroy the paraconf configuration tree
241231
PC_tree_destroy(&conf);
242232

243233
// free the allocated memory
244234
free(cur);
245235
free(next);
236+
PDI_finalize();
246237

247238
// finalize MPI
248239
MPI_Finalize();

0 commit comments

Comments
 (0)