YAC 3.18.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_mpi_handshake.F90
Go to the documentation of this file.
1! Copyright (c) 2024 The YAC Authors
2!
3! SPDX-License-Identifier: BSD-3-Clause
4
8
9#include "test_macros.inc"
10
12
13 use utest
14 use yac
15 use yaxt
16 use mpi
17 implicit none
18
19 integer :: global_rank, global_size
20 integer :: ierror
21
22 call mpi_init(ierror)
23
24 call xt_initialize(mpi_comm_world)
25
26 call mpi_comm_rank ( mpi_comm_world, global_rank, ierror )
27 call mpi_comm_size ( mpi_comm_world, global_size, ierror )
28
29 if (global_size /= 6) then
30 write ( * , * ) "wrong number of processes (should be 6)"
31 call error_exit
32 endif
33
35
36 call xt_finalize()
37
38 call mpi_finalize(ierror)
39
40 call stop_test
41 call exit_tests
42
43contains
44
45 subroutine test_fmpi_handshake ()
46
47 integer :: color
48
49 integer :: ref_group_comm, ref_main_comm
50 integer :: main_comm, group_comm
51 integer :: result
52 integer :: group_comms(2)
53 CHARACTER(len=YAC_MAX_CHARLEN) :: group_names(2)
54
55 color = mpi_undefined
56 main_comm = mpi_comm_null
57 group_comm = mpi_comm_null
58
59 select case(global_rank)
60 case (0:1)
61 ! first two ranks are part of group A
62 group_names(1) = "main"
63 group_names(2) = "group a"
64 CALL yac_fmpi_handshake(mpi_comm_world, group_names, group_comms)
65 main_comm = group_comms(1)
66 group_comm = group_comms(2)
67 color = 0
68 case (2:3)
69 ! next two ranks are part of group B
70 group_names(1) = "group b"
71 group_names(2) = "main"
72 CALL yac_fmpi_handshake(mpi_comm_world, group_names, group_comms)
73 group_comm = group_comms(1)
74 main_comm = group_comms(2)
75 color = 1
76 case (4)
77 ! rank four does not provide a group
78 group_names(1) = "main"
79 CALL yac_fmpi_handshake(mpi_comm_world, group_names(1:1), group_comms(1:1))
80 main_comm = group_comms(1)
81 case (5)
82 ! rank five does a dummy initialisation
83 CALL yac_fmpi_handshake(mpi_comm_world, group_names(2:1), group_comms(2:1))
84 end select
85
86 call mpi_comm_split(mpi_comm_world, color, 0, ref_group_comm, ierror)
87 call mpi_comm_split( &
88 mpi_comm_world, merge(mpi_undefined, 0, global_rank == 5), 0, &
89 ref_main_comm, ierror)
90
91 if (ref_group_comm /= mpi_comm_null) then
92
93 call mpi_comm_compare(ref_group_comm, group_comm, result, ierror);
94
95 call test((result == mpi_congruent) .OR. (result == mpi_ident))
96
97 call mpi_comm_free(ref_group_comm, ierror)
98 call mpi_comm_free(group_comm, ierror)
99
100 else
101 call test(group_comm == mpi_comm_null)
102 end if
103
104 if (ref_main_comm /= mpi_comm_null) then
105
106 call mpi_comm_compare(ref_main_comm, main_comm, result, ierror);
107
108 call test((result == mpi_congruent) .OR. (result == mpi_ident))
109
110 call mpi_comm_free(ref_main_comm, ierror)
111 call mpi_comm_free(main_comm, ierror)
112
113 else
114 call test(main_comm == mpi_comm_null)
115 end if
116
117 end subroutine test_fmpi_handshake
118
119 subroutine error_exit ()
120
121 use mpi, only : mpi_abort, mpi_comm_world
122 use utest
123
124 integer :: ierror
125
126 call test ( .false. )
127 call stop_test
128 call exit_tests
129 call mpi_abort ( mpi_comm_world, 999, ierror )
130
131 end subroutine error_exit
132
133end program test_mpi_handshake
134
Fortran2C interface for YAC collective routines.
static void merge(char *base_a, size_t num_a, int a_ascending, char *base_b, size_t num_b, int b_ascending, size_t size, int(*compar)(const void *, const void *), char *target)
Definition mergesort.c:56
Definition utest.F90:5
subroutine, public stop_test()
Definition utest.F90:27
subroutine, public exit_tests()
Definition utest.F90:81
subroutine error_exit()
subroutine test_fmpi_handshake()
program test_mpi_handshake