Skip to content

Commit a26850b

Browse files
committed
refactor(tests): standardise MPI lifecycle and reporting
- adopt shared MPI initialisation and test finalisation helpers - aggregate rank-local test results where required - make statistics and scalar-output failures update allpass - remove duplicate success reporting
1 parent 5ae7709 commit a26850b

13 files changed

Lines changed: 88 additions & 139 deletions

tests/performance/perf_omp_tridiag.f90

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ program perf_omp_tridiag
77
use m_omp_sendrecv, only: sendrecv_fields
88
use m_omp_exec_dist, only: exec_dist_tds_compact
99
use m_tdsops, only: tdsops_t, tdsops_init
10-
use m_test_utils, only: initialise_mpi, write_perf_minmax_metrics
10+
use m_test_utils, only: initialise_mpi, finalise_test, &
11+
write_perf_minmax_metrics
1112

1213
implicit none
1314

@@ -32,7 +33,7 @@ program perf_omp_tridiag
3233
call configure_benchmark()
3334
call allocate_fields()
3435
call run_case('periodic', dx_per, periodic_bw)
35-
call finalise()
36+
call finalise_test(.true., nrank)
3637

3738
contains
3839

@@ -155,8 +156,4 @@ subroutine stop_timer(t)
155156
t = omp_get_wtime()
156157
end subroutine stop_timer
157158

158-
subroutine finalise()
159-
call MPI_Finalize(ierr)
160-
end subroutine finalise
161-
162159
end program perf_omp_tridiag

tests/unit/test_ab_checkpoint.f90

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ program test_ab_checkpoint
1111
use m_solver, only: solver_t
1212
use m_omp_backend, only: omp_backend_t
1313
use m_omp_common, only: SZ
14+
use m_test_utils, only: initialise_mpi, finalise_test, global_all
1415

1516
implicit none
1617

@@ -27,7 +28,7 @@ program test_ab_checkpoint
2728
type(checkpoint_manager_t) :: chk_mgr_write, chk_mgr_restart
2829
type(flist_t), allocatable :: curr(:)
2930
type(flist_t), allocatable :: deriv(:)
30-
integer :: ierr, irank, nproc
31+
integer :: irank, nproc
3132
integer :: dims_global(3), nproc_dir(3)
3233
real(dp) :: L_global(3)
3334
character(len=20) :: BC_x(2), BC_y(2), BC_z(2)
@@ -39,9 +40,7 @@ program test_ab_checkpoint
3940
logical :: allpass
4041
real(dp) :: diff
4142

42-
call MPI_Init(ierr)
43-
call MPI_Comm_rank(MPI_COMM_WORLD, irank, ierr)
44-
call MPI_Comm_size(MPI_COMM_WORLD, nproc, ierr)
43+
call initialise_mpi(irank, nproc)
4544

4645
allpass = .true.
4746

@@ -120,15 +119,8 @@ program test_ab_checkpoint
120119
deallocate (olds_ref)
121120
end if
122121

123-
call MPI_Finalize(ierr)
124-
125-
if (irank == 0) then
126-
if (allpass) then
127-
write (stderr, '(a)') 'AB checkpoint test passed.'
128-
else
129-
error stop 'AB checkpoint test failed.'
130-
end if
131-
end if
122+
call global_all(allpass)
123+
call finalise_test(allpass, irank)
132124

133125
contains
134126

tests/unit/test_adios2_read_write.f90

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ program test_adios2
44
use m_io_base, only: io_writer_t, io_reader_t, io_file_t, io_mode_write, &
55
io_mode_read
66
use m_common, only: dp, i8, is_sp
7-
use iso_fortran_env, only: stderr => error_unit
7+
use m_test_utils, only: initialise_mpi, finalise_test, global_all
88
implicit none
99

1010
! ADIOS2 handlers
@@ -24,9 +24,7 @@ program test_adios2
2424
real(dp) :: expected, tolerance
2525

2626
! launch MPI
27-
call MPI_Init(ierr)
28-
call MPI_Comm_rank(MPI_COMM_WORLD, irank, ierr)
29-
call MPI_Comm_size(MPI_COMM_WORLD, isize, ierr)
27+
call initialise_mpi(irank, isize)
3028

3129
! data initialisation
3230
allocate (data_write(inx, iny, inz))
@@ -111,15 +109,7 @@ program test_adios2
111109

112110
! Cleanup and finalize
113111
call MPI_Barrier(MPI_COMM_WORLD, ierr)
114-
call MPI_Finalize(ierr)
115-
116-
! Test result
117-
if (irank == 0) then
118-
if (allpass) then
119-
write (stderr, '(a)') 'ADIOS2 TEST PASSED SUCCESSFULLY.'
120-
else
121-
error stop 'ADIOS2 TEST FAILED.'
122-
end if
123-
end if
112+
call global_all(allpass)
113+
call finalise_test(allpass, irank)
124114

125115
end program test_adios2

tests/unit/test_allocator.f90

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
program test_allocator
2-
use mpi
32
use iso_fortran_env, only: stderr => error_unit
43

54
use m_allocator, only: allocator_t
65
use m_field, only: field_t
76
use m_common, only: DIR_X, pi, dp
8-
use m_test_utils, only: finalise_test
7+
use m_test_utils, only: initialise_mpi, finalise_test
98

109
implicit none
1110

@@ -16,9 +15,9 @@ program test_allocator
1615
class(allocator_t), allocatable :: allocator
1716
class(field_t), pointer :: ptr1, ptr2, ptr3
1817
integer, allocatable :: l(:)
19-
integer :: ierr
18+
integer :: nrank, nproc
2019

21-
call MPI_Init(ierr)
20+
call initialise_mpi(nrank, nproc)
2221

2322
allocator = allocator_t([8, 8, 8], 8)
2423

@@ -77,5 +76,5 @@ program test_allocator
7776

7877
call allocator%destroy()
7978

80-
call finalise_test(allpass)
79+
call finalise_test(allpass, nrank)
8180
end program test_allocator

tests/unit/test_io_session.f90

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ program test_io_session
33
use mpi
44
use m_common, only: dp, i8
55
use m_io_session, only: writer_session_t, reader_session_t
6-
use iso_fortran_env, only: stderr => error_unit
6+
use m_test_utils, only: initialise_mpi, finalise_test, global_all
77
implicit none
88

99
integer, parameter, dimension(3) :: local_dims = [8, 6, 1]
@@ -22,9 +22,7 @@ program test_io_session
2222
logical :: allpass = .true.
2323
integer :: i, j, k
2424

25-
call MPI_Init(ierr)
26-
call MPI_Comm_rank(MPI_COMM_WORLD, irank, ierr)
27-
call MPI_Comm_size(MPI_COMM_WORLD, nproc, ierr)
25+
call initialise_mpi(irank, nproc)
2826

2927
! setup global domain dimensions
3028
global_dims = [int(local_dims(1), i8), int(local_dims(2), i8), &
@@ -93,19 +91,11 @@ program test_io_session
9391
if (.not. allpass) exit
9492
end do
9593

96-
call MPI_Allreduce(MPI_IN_PLACE, allpass, 1, MPI_LOGICAL, &
97-
MPI_LAND, MPI_COMM_WORLD, ierr)
94+
call global_all(allpass)
9895

9996
! cleanup
10097
if (irank == 0) call execute_command_line("rm -rf "//test_file)
10198

102-
call MPI_Finalize(ierr)
103-
104-
if (allpass) then
105-
if (irank == 0) write (stderr, &
106-
'(a)') 'PARALLEL I/O SESSION TEST PASSED SUCCESSFULLY.'
107-
else
108-
error stop 'PARALLEL I/O SESSION TEST FAILED.'
109-
end if
99+
call finalise_test(allpass, irank)
110100

111101
end program test_io_session

tests/unit/test_mesh.f90

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
program test_mesh
2-
use mpi
32
use iso_fortran_env, only: stderr => error_unit
43

54
use m_allocator, only: allocator_t
65
use m_field, only: field_t
76
use m_mesh, only: mesh_t
87
use m_common, only: DIR_X, pi, dp, CELL, DIR_C, DIR_Y, DIR_Z, VERT, Z_FACE
9-
use m_test_utils, only: finalise_test
8+
use m_test_utils, only: initialise_mpi, finalise_test
109

1110
implicit none
1211

@@ -19,15 +18,13 @@ program test_mesh
1918
class(field_t), pointer :: ptr1, ptr2, ptr3
2019
integer, dimension(3) :: dims
2120
integer, dimension(3) :: dims_check
22-
integer :: ierr, nrank, nproc
21+
integer :: nrank, nproc
2322
integer :: n_cell, n_vert, n_x_face
2423
! -ffast-math reciprocal division can be ~1 ulp off even for exactly
2524
! representable results, so the tolerance must scale with the precision
2625
real(dp), parameter :: eps = 1000*epsilon(1._dp)
2726

28-
call MPI_Init(ierr)
29-
call MPI_Comm_rank(MPI_COMM_WORLD, nrank, ierr)
30-
call MPI_Comm_size(MPI_COMM_WORLD, nproc, ierr)
27+
call initialise_mpi(nrank, nproc)
3128

3229
allpass = .true.
3330

tests/unit/test_omptgt_allocator.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ program test_allocator_omptgt
55
use m_common, only: dp, pi, DIR_X
66

77
use m_omptgt_allocator, only: omptgt_allocator_t
8+
use m_test_utils, only: initialise_mpi, finalise_test
89

910
implicit none
1011

@@ -15,9 +16,9 @@ program test_allocator_omptgt
1516
class(allocator_t), allocatable :: allocator
1617
class(field_t), pointer :: ptr1, ptr2, ptr3
1718
integer, allocatable :: l(:)
18-
integer :: ierr
19+
integer :: nrank, nproc
1920

20-
call MPI_Init(ierr)
21+
call initialise_mpi(nrank, nproc)
2122

2223
dims = [8, 8, 8]
2324
nproc_dir = [1, 1, 1]
@@ -88,5 +89,5 @@ program test_allocator_omptgt
8889

8990
call allocator%destroy()
9091

91-
call MPI_Finalize(ierr)
92+
call finalise_test(allpass, nrank)
9293
end program test_allocator_omptgt

0 commit comments

Comments
 (0)