Loading [MathJax]/extensions/tex2jax.js
Neko 0.9.99
A portable framework for high-order spectral element flow simulations
All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Pages
comm.F90
Go to the documentation of this file.
1module comm
2 use mpi_f08
3 use utils, only : neko_error
5 !$ use omp_lib
6 implicit none
7
8 interface
9 subroutine neko_comm_wrapper_init(fcomm) &
10 bind(c, name='neko_comm_wrapper_init')
11 integer, value :: fcomm
12 end subroutine neko_comm_wrapper_init
13
14#ifdef HAVE_NVSHMEM
15 subroutine neko_comm_nvshmem_init() &
16 bind(c, name='neko_comm_nvshmem_init')
17 end subroutine neko_comm_nvshmem_init
18
19 subroutine neko_comm_nvshmem_finalize() &
20 bind(c, name='neko_comm_nvshmem_finalize')
21 end subroutine neko_comm_nvshmem_finalize
22#endif
23
24#if defined(HAVE_NCCL) || defined(HAVE_RCCL)
25 subroutine neko_comm_nccl_init() &
26 bind(c, name='neko_comm_nccl_init')
27 end subroutine neko_comm_nccl_init
28
29 subroutine neko_comm_nccl_finalize() &
30 bind(c, name='neko_comm_nccl_finalize')
31 end subroutine neko_comm_nccl_finalize
32#endif
33
34 end interface
35
36
38 type(mpi_comm) :: neko_comm
39 type(mpi_comm) :: neko_global_comm
40
42#ifdef HAVE_MPI_PARAM_DTYPE
43 type(mpi_datatype), parameter :: mpi_real_precision = mpi_double_precision
44 type(mpi_datatype), parameter :: mpi_extra_precision = mpi_double_precision
45#else
46 type(mpi_datatype) :: mpi_real_precision
47 type(mpi_datatype) :: mpi_extra_precision
48#endif
49
51 integer :: pe_rank
52
54 integer :: pe_size
55
57 logical :: nio
58
60 integer :: global_pe_rank
61
63 integer :: global_pe_size
64
65contains
66 subroutine comm_init
67 integer :: ierr
68 logical :: initialized
69 integer :: provided, nthrds
70 integer :: color = 0
71 integer :: envvar_len
72 character(len=255) :: color_str
73
74 pe_rank = -1
75 pe_size = 0
76 nio = .false.
77
78 call mpi_initialized(initialized, ierr)
79
80 call get_environment_variable("NEKO_COMM_ID", color_str, envvar_len)
81 if (envvar_len .gt. 0) then
82 read(color_str(1:envvar_len), *) color
83 else
84 color = 0
85 end if
86
87 nthrds = 1
88 !$omp parallel
89 !$omp master
90 !$ nthrds = omp_get_num_threads()
91 !$omp end master
92 !$omp end parallel
93
94 if (.not.initialized) then
95 if (nthrds .gt. 1) then
96 call mpi_init_thread(mpi_thread_multiple, provided, ierr)
97 if (provided .ne. mpi_thread_multiple) then
98 ! MPI_THREAD_MULTIPLE is required for mt. device backends
99 if (neko_bcknd_device .eq. 1) then
100 call neko_error('Invalid thread support provided by MPI')
101 else
102 call mpi_init_thread(mpi_thread_serialized, provided, ierr)
103 if (provided .ne. mpi_thread_serialized) then
104 call neko_error('Invalid thread support provided by MPI')
105 end if
106 end if
107 end if
108 else
109 call mpi_init(ierr)
110 end if
111 end if
112
113#ifndef HAVE_MPI_PARAM_DTYPE
114 mpi_real_precision = mpi_double_precision
115 mpi_extra_precision = mpi_double_precision
116#endif
117
118
119#ifdef HAVE_ADIOS2
120 ! We split the communicator it to work asynchronously (MPMD)
121 call mpi_comm_rank(mpi_comm_world, pe_rank, ierr)
122 call mpi_comm_split(mpi_comm_world, 0, pe_rank, neko_global_comm, ierr)
123#else
124 ! Original version duplicates the communicator:
125 call mpi_comm_dup(mpi_comm_world, neko_global_comm, ierr)
126#endif
127
128 call mpi_comm_rank(neko_global_comm, global_pe_rank, ierr)
129 call mpi_comm_size(neko_global_comm, global_pe_size, ierr)
130 if (envvar_len .gt. 0) then
131 call mpi_comm_split(neko_global_comm, color, global_pe_rank, &
132 neko_comm, ierr)
133 else
134 call mpi_comm_dup(neko_global_comm, neko_comm, ierr)
135 end if
136 call mpi_comm_rank(neko_comm, pe_rank, ierr)
137 call mpi_comm_size(neko_comm, pe_size, ierr)
138
139 ! Setup C/C++ wrapper
141
142
143#ifdef HAVE_NVSHMEM
144 ! Setup NVSHMEM (if requested)
145 call neko_comm_nvshmem_init()
146#endif
147
148#if defined(HAVE_NCCL) | defined(HAVE_RCCL)
149 ! Setup NCCL (if requested)
150 call neko_comm_nccl_init()
151#endif
152
153
154 end subroutine comm_init
155
156 subroutine comm_free
157 integer :: ierr
158
159 call mpi_barrier(neko_comm, ierr)
160 call mpi_comm_free(neko_comm, ierr)
161
162#ifdef HAVE_NCCL
163 call neko_comm_nccl_finalize()
164#endif
165
166#ifdef HAVE_NVSHMEM
167 call neko_comm_nvshmem_finalize()
168#endif
169
170 call mpi_finalize(ierr)
171
172 end subroutine comm_free
173
174end module comm
Definition comm.F90:1
integer pe_rank
MPI rank.
Definition comm.F90:51
integer global_pe_size
Global MPI size of communicator.
Definition comm.F90:63
logical nio
I/O node.
Definition comm.F90:57
type(mpi_comm) neko_comm
MPI communicator.
Definition comm.F90:38
subroutine comm_free
Definition comm.F90:157
type(mpi_datatype) mpi_real_precision
MPI type for working precision of REAL types.
Definition comm.F90:46
integer pe_size
MPI size of communicator.
Definition comm.F90:54
type(mpi_comm) neko_global_comm
Definition comm.F90:39
type(mpi_datatype) mpi_extra_precision
Definition comm.F90:47
integer global_pe_rank
Global MPI rank.
Definition comm.F90:60
subroutine comm_init
Definition comm.F90:67
Build configurations.
integer, parameter neko_bcknd_device
Utilities.
Definition utils.f90:35