Skip to content

Commit fb46da5

Browse files
committed
Add Make to ep 6 tests, instructions and solutions
1 parent d0b4989 commit fb46da5

6 files changed

Lines changed: 35 additions & 44 deletions

File tree

docker/Dockerfile.ep-6

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,27 @@ WORKDIR /home/vscode/6-testing-parallel-code/challenge
66

77
# Fix intentional bug in code
88
RUN mv ../solution/test_find_steady_state.pf ./test/ && \
9-
echo "set(test_find_steady_state_src \${test_srcs})\n\
10-
list(FILTER test_find_steady_state_src INCLUDE REGEX \".*test_find_steady_state.pf\")\n\
11-
\n\
12-
add_pfunit_ctest (pfunit_find_steady_state_tests\n\
13-
TEST_SOURCES \${test_find_steady_state_src}\n\
9+
echo "add_pfunit_ctest (pfunit_find_steady_state_tests\n\
10+
TEST_SOURCES \"\${PROJECT_SOURCE_DIR}/test/test_find_steady_state.pf\"\n\
1411
LINK_LIBRARIES sut\n\
1512
MAX_PES 8\n\
1613
)\n\
17-
" >> test/CMakeLists.txt
14+
" >> test/CMakeLists.txt && \
15+
sed -i -E 's/TEST_FLAGS = -I\$\(BUILD_DIR\) \$\(PFUNIT_EXTRA_FFLAGS\)/TEST_FLAGS = -I\$\(BUILD_DIR\) \$\(PFUNIT_EXTRA_FFLAGS\) -lpfunit/g' test/Makefile && \
16+
sed -i -E 's/test_get_local_grid_info.pf/test_get_local_grid_info.pf \\\n test_find_steady_state.pf/g' test/Makefile
1817

1918
# build tests with cmake
2019
RUN cmake -B build-cmake -DCMAKE_PREFIX_PATH=/home/vscode/pfunit/build/installed && \
2120
cmake --build build-cmake
2221

2322
# test with ctest, allowing MPI to oversubscribe
2423
RUN ctest --test-dir build-cmake --output-on-failure
24+
25+
# Remove any generated code
26+
RUN make clean
27+
28+
# Build tests with make
29+
RUN make tests
30+
31+
# Run make tests
32+
RUN mpirun -np 8 ./test/tests

episodes/6-testing-parallel-code/challenge/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Top level variables
22
ROOT_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
3-
FC ?= mpif90
3+
FC := mpif90 -ffree-line-length-none
44

55
#------------------------------------#
66
# Targets for compiling src #

episodes/6-testing-parallel-code/challenge/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ There are some examples of parallel tests in [test_exchange_boundaries.pf](./tes
3131
1. Re-write test_find_steady_state.pf so that it uses the pfunit library instead of funit. We need to make sure that the subroutine
3232
find_steady_state reaches steady state within the same number of generations as its serial version.
3333

34-
2. Make sure your test automatically runs across different numbers of ranks via ctest. You will need to make changes in
35-
[CMakeLists.txt](./CMakeLists.txt) as well as within the test itself.
34+
2. Add your new test to the existing build systems
35+
i. Update the [test/Makefile](./test/Makefile) to allow building MPI enabled pFUnit tests and build your new test with make.
36+
ii. Make sure your test automatically runs across different numbers of ranks via ctest. You will need to make changes in
37+
[CMakeLists.txt](./CMakeLists.txt) as well as within the test itself.

episodes/6-testing-parallel-code/challenge/test/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,4 @@ add_pfunit_ctest (pfunit_exchange_boundaries_tests
5959
)
6060

6161
# find_steady_state tests
62-
add_pfunit_ctest (pfunit_find_steady_state_tests
63-
TEST_SOURCES "${PROJECT_SOURCE_DIR}/test/test_find_steady_state.pf"
64-
LINK_LIBRARIES sut # your application library
65-
)
62+
# Your changes here...

episodes/6-testing-parallel-code/challenge/test/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PFUNIT_INCLUDE_DIR ?= /home/vscode/pfunit/build/installed/PFUNIT-4.12/include
1+
PFUNIT_INCLUDE_DIR := /home/vscode/pfunit/build/installed/PFUNIT-4.12/include
22

33
# Don't try to include if we're cleaning as this doesn't depend on pFUnit
44
ifneq ($(MAKECMDGOALS),clean)
@@ -12,7 +12,6 @@ check:
1212
# Define variables to be picked up by make_pfunit_test
1313
tests_TESTS = \
1414
test_evolve_board.pf \
15-
test_find_steady_state.pf \
1615
test_read_model_from_file.pf \
1716
test_check_for_steady_state.pf \
1817
test_exchange_boundaries.pf \

episodes/6-testing-parallel-code/solution/README.md

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,21 @@ that of the parallel solution.
1010

1111
## Task 2
1212

13-
> Ensure your test can be compiled using Make.
14-
15-
To compile MPI enabled pFUnit tests via Make you must ensure you include `-lpfunit` in the test flags,
16-
17-
```diff
18-
--- a/episodes/6-testing-parallel-code/challenge/test/Makefile
19-
+++ b/episodes/6-testing-parallel-code/challenge/test/Makefile
20-
@@ -3,7 +3,7 @@ PFUNIT_INCLUDE_DIR ?= /home/vscode/pfunit/build/installed/PFUNIT-4.12/include
21-
# Don't try to include if we're cleaning as this doesn't depend on pFUnit
22-
ifneq ($(MAKECMDGOALS),clean)
23-
include $(PFUNIT_INCLUDE_DIR)/PFUNIT.mk
24-
-TEST_FLAGS = -I$(BUILD_DIR) $(PFUNIT_EXTRA_FFLAGS)
25-
+TEST_FLAGS = -I$(BUILD_DIR) $(PFUNIT_EXTRA_FFLAGS) -lpfunit
26-
endif
27-
28-
check:
29-
```
13+
> i. Update the [test/Makefile](./test/Makefile) to allow building MPI enabled pFUnit tests and build your new test with make.
14+
15+
To compile MPI enabled pFUnit tests via Make you must ensure you include `-lpfunit` in the **TEST_FLAGS** and add your new test to
16+
the list **tests_TESTS**.
3017

31-
> Make sure your test automatically runs across different numbers of ranks via ctest.
18+
> ii. Make sure your test automatically runs across different numbers of ranks via ctest. You will need to make changes in
19+
> [CMakeLists.txt](./CMakeLists.txt) as well as within the test itself.
3220
3321
In order to run this parallel solution with different numbers of MPI ranks via ctest, you will also need to update CMakeLists.txt
34-
with the following change.
35-
36-
```diff
37-
--- a/episodes/6-testing-parallel-code/challenge/test/CMakeLists.txt
38-
+++ b/episodes/6-testing-parallel-code/challenge/test/CMakeLists.txt
39-
@@ -62,4 +62,5 @@ add_pfunit_ctest (pfunit_exchange_boundaries_tests
40-
add_pfunit_ctest (pfunit_find_steady_state_tests
41-
TEST_SOURCES "${PROJECT_SOURCE_DIR}/test/test_find_steady_state.pf"
42-
LINK_LIBRARIES sut # your application library
43-
+ MAX_PES 8
44-
)
22+
to add the following.
23+
24+
```cmake
25+
add_pfunit_ctest (pfunit_find_steady_state_tests
26+
TEST_SOURCES "${PROJECT_SOURCE_DIR}/test/test_find_steady_state.pf"
27+
LINK_LIBRARIES sut # your application library
28+
MAX_PES 8
29+
)
4530
```

0 commit comments

Comments
 (0)