Skip to content

Commit 2ea0710

Browse files
Merge branch 'numpex' of github.com:pdidev/tutorial into numpex
2 parents 84036f4 + eb33135 commit 2ea0710

File tree

13 files changed

+424
-90
lines changed

13 files changed

+424
-90
lines changed

begin/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)
35+
36+

ex1.yml renamed to begin/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ 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 }

ex1.c renamed to begin/main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
#include <time.h>
3131

3232
#include <paraconf.h>
33-
// load the PDI header
34-
#include <pdi.h>
33+
3534

3635
// size of the local data as [HEIGHT, WIDTH] including the number of ghost
3736
// layers for communications or boundary conditions
@@ -152,7 +151,7 @@ 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("ex1.yml");
154+
PC_tree_t conf = PC_parse_path("config.yml");
156155

157156
// NEVER USE MPI_COMM_WORLD IN THE CODE, use our own communicator main_comm
158157
// instead

begin/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 begin/solution/config.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +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

8-
#*** PDI configuration
9-
pdi:
10-
plugins:
11-
trace:
12-
logging: { pattern: '[PDI][%n-plugin] *** %l: %v' }
8+
pdi:

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,13 @@ int main(int argc, char *argv[]) {
152152
MPI_Init(&argc, &argv);
153153

154154
// load the configuration tree
155-
PC_tree_t conf = PC_parse_path("ex2.yml");
156-
155+
PC_tree_t conf = PC_parse_path("config.yml");
156+
PDI_init(PC_get(conf, ".pdi"));
157+
157158
// NEVER USE MPI_COMM_WORLD IN THE CODE, use our own communicator main_comm
158159
// instead
159160
MPI_Comm main_comm = MPI_COMM_WORLD;
160161

161-
// initialize PDI, it can replace our main communicator by its own
162-
PDI_init(PC_get(conf, ".pdi"));
163-
164162
// load the MPI rank & size
165163
int psize_1d;
166164
MPI_Comm_size(main_comm, &psize_1d);
@@ -172,8 +170,9 @@ int main(int argc, char *argv[]) {
172170
// load the alpha parameter
173171
PC_double(PC_get(conf, ".alpha"), &alpha);
174172

175-
// load the global data-size
176173
int global_size[2];
174+
// load the global data-size
175+
// you can use paraconf to read some parameters from the yml config file
177176
PC_int(PC_get(conf, ".global_size.height"), &longval);
178177
global_size[0] = longval;
179178
PC_int(PC_get(conf, ".global_size.width"), &longval);
@@ -211,14 +210,8 @@ int main(int argc, char *argv[]) {
211210
// our loop counter so as to be able to use it outside the loop
212211
int ii = 0;
213212

214-
//*** share useful configuration bits with PDI
215-
//*** pcoord, psize, dsize
216-
//...
217-
218213
// the main loop
219-
for (; ii < 4; ++ii) {
220-
//*** share the loop counter & main field at each iteration
221-
//...
214+
for (; ii < 10; ++ii) {
222215

223216
// compute the values for the next iteration
224217
iter(cur, next);
@@ -231,18 +224,14 @@ int main(int argc, char *argv[]) {
231224
cur = next;
232225
next = tmp;
233226
}
234-
//*** finally share the loop counter and main field after the main loop body
235-
//...
236-
237-
// finalize PDI
238-
PDI_finalize();
239227

240228
// destroy the paraconf configuration tree
241229
PC_tree_destroy(&conf);
242230

243231
// free the allocated memory
244232
free(cur);
245233
free(next);
234+
PDI_finalize();
246235

247236
// finalize MPI
248237
MPI_Finalize();

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-
#...

0 commit comments

Comments
 (0)