Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
pfunit_comm_utils.F90
Go to the documentation of this file.
2 use mpi
6 use utils, only : neko_error
7 implicit none
8 private
9
10 logical :: comm_test_active = .false.
11
13 module procedure comm_init_test_f
14 end interface comm_init_test
15
17
18 interface
19 subroutine neko_comm_wrapper_init(fcomm) &
20 bind(c, name='neko_comm_wrapper_init')
21 use, intrinsic :: iso_c_binding, only : c_int
22 integer(c_int), value :: fcomm
23 end subroutine neko_comm_wrapper_init
24 end interface
25
26contains
27
30 subroutine comm_init_test_f(ext_comm)
31 integer, intent(in) :: ext_comm
32 integer :: ierr
33
35 if (ext_comm .eq. mpi_comm_null) then
36 call neko_error('Cannot initialize test communicator from MPI_COMM_NULL')
37 end if
38
39#ifndef HAVE_MPI_PARAM_DTYPE
40 mpi_real_precision%mpi_val = mpi_double_precision
41 mpi_extra_precision%mpi_val = mpi_double_precision
42#endif
43
44 call mpi_comm_dup(ext_comm, neko_global_comm%mpi_val, ierr)
45 if (ierr .ne. mpi_success) then
46 call neko_error('Failed to duplicate test global communicator')
47 end if
48 call mpi_comm_dup(ext_comm, neko_comm%mpi_val, ierr)
49 if (ierr .ne. mpi_success) then
50 call neko_error('Failed to duplicate test communicator')
51 end if
53 end subroutine comm_init_test_f
54
57 subroutine comm_free_test
58 integer :: ierr
59 logical :: initialized, finalized
60
61 if (.not. comm_test_active) return
62
63 call mpi_initialized(initialized, ierr)
64 call comm_test_check(ierr, 'Failed to query MPI initialization state')
65 call mpi_finalized(finalized, ierr)
66 call comm_test_check(ierr, 'Failed to query MPI finalization state')
67 if ((.not. initialized) .or. finalized) then
68 call neko_error('MPI is not active during comm_free_test')
69 end if
70
71 call mpi_barrier(neko_comm%mpi_val, ierr)
72 call comm_test_check(ierr, 'Failed to synchronize test communicator')
73 call mpi_comm_free(neko_comm%mpi_val, ierr)
74 call comm_test_check(ierr, 'Failed to free test communicator')
75 call mpi_comm_free(neko_global_comm%mpi_val, ierr)
76 call comm_test_check(ierr, 'Failed to free test global communicator')
77
78 call neko_comm_wrapper_init(mpi_comm_null)
79 pe_rank = -1
80 pe_size = 0
83 nio = .false.
84 comm_test_active = .false.
85 end subroutine comm_free_test
86
87 subroutine comm_test_precheck()
88 integer :: ierr
89 logical :: initialized, finalized
90
91 if (comm_test_active) then
92 call neko_error('Test communicator is already initialized')
93 end if
94
95 call mpi_initialized(initialized, ierr)
96 call comm_test_check(ierr, 'Failed to query MPI initialization state')
97 if (.not. initialized) then
98 call neko_error('MPI must be initialized before comm_init_test')
99 end if
100
101 call mpi_finalized(finalized, ierr)
102 call comm_test_check(ierr, 'Failed to query MPI finalization state')
103 if (finalized) then
104 call neko_error('MPI is finalized before comm_init_test')
105 end if
106
107 call mpi_query_thread(neko_mpi_thread_provided, ierr)
108 call comm_test_check(ierr, 'Failed to query MPI thread support')
109 end subroutine comm_test_precheck
110
112 integer :: ierr
113
114 call mpi_comm_rank(neko_global_comm%mpi_val, global_pe_rank, ierr)
115 call comm_test_check(ierr, 'Failed to query test global rank')
116 call mpi_comm_size(neko_global_comm%mpi_val, global_pe_size, ierr)
117 call comm_test_check(ierr, 'Failed to query test global size')
118 call mpi_comm_rank(neko_comm%mpi_val, pe_rank, ierr)
119 call comm_test_check(ierr, 'Failed to query test rank')
120 call mpi_comm_size(neko_comm%mpi_val, pe_size, ierr)
121 call comm_test_check(ierr, 'Failed to query test size')
122
123 nio = .false.
125 comm_test_active = .true.
126 end subroutine comm_test_set_state
127
128 subroutine comm_test_check(ierr, msg)
129 integer, intent(in) :: ierr
130 character(len=*), intent(in) :: msg
131
132 if (ierr .ne. mpi_success) call neko_error(msg)
133 end subroutine comm_test_check
134
135end module pfunit_comm_utils
Definition comm.F90:1
logical, public nio
I/O node.
Definition comm.F90:65
type(mpi_comm), public neko_global_comm
Definition comm.F90:47
type(mpi_datatype), public mpi_real_precision
MPI type for working precision of REAL types.
Definition comm.F90:54
integer, public global_pe_rank
Global MPI rank.
Definition comm.F90:68
integer, public pe_size
MPI size of communicator.
Definition comm.F90:62
integer, public pe_rank
MPI rank.
Definition comm.F90:59
integer, public global_pe_size
Global MPI size of communicator.
Definition comm.F90:71
type(mpi_comm), public neko_comm
MPI communicator.
Definition comm.F90:46
integer, public neko_mpi_thread_provided
Thread support provided by the MPI library.
Definition comm.F90:74
type(mpi_datatype), public mpi_extra_precision
Definition comm.F90:55
subroutine comm_init_test_f(ext_comm)
Initialize Neko communicator state from an externally owned integer communicator, as returned by pFUn...
subroutine comm_test_set_state()
subroutine, public comm_free_test
Free communicator state initialized by comm_init_test without finalizing MPI.
subroutine comm_test_precheck()
subroutine comm_test_check(ierr, msg)
Utilities.
Definition utils.f90:35