GCC Code Coverage Report


Directory: src/
File: src/xt_core_f.f90
Date: 2024-11-08 09:02:52
Exec Total Coverage
Lines: 9 26 34.6%
Branches: 0 8 0.0%

Line Branch Exec Source
1 !>
2 !! @file xt_core_f.f90
3 !! @brief Fortran interface to yaxt core declarations
4 !!
5 !! @copyright Copyright (C) 2016 Jörg Behrens <behrens@dkrz.de>
6 !! Moritz Hanke <hanke@dkrz.de>
7 !! Thomas Jahns <jahns@dkrz.de>
8 !!
9 !! @author Jörg Behrens <behrens@dkrz.de>
10 !! Moritz Hanke <hanke@dkrz.de>
11 !! Thomas Jahns <jahns@dkrz.de>
12 !!
13
14 !
15 ! Keywords:
16 ! Maintainer: Jörg Behrens <behrens@dkrz.de>
17 ! Moritz Hanke <hanke@dkrz.de>
18 ! Thomas Jahns <jahns@dkrz.de>
19 ! URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
20 !
21 ! Redistribution and use in source and binary forms, with or without
22 ! modification, are permitted provided that the following conditions are
23 ! met:
24 !
25 ! Redistributions of source code must retain the above copyright notice,
26 ! this list of conditions and the following disclaimer.
27 !
28 ! Redistributions in binary form must reproduce the above copyright
29 ! notice, this list of conditions and the following disclaimer in the
30 ! documentation and/or other materials provided with the distribution.
31 !
32 ! Neither the name of the DKRZ GmbH nor the names of its contributors
33 ! may be used to endorse or promote products derived from this software
34 ! without specific prior written permission.
35 !
36 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
37 ! IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
38 ! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
39 ! PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
40 ! OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
41 ! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
42 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
43 ! PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
44 ! LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45 ! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46 ! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 !
48 #include "fc_feature_defs.inc"
49 MODULE xt_core
50 USE, INTRINSIC :: ISO_C_BINDING, ONLY: c_char, c_null_char, c_int
51 #ifdef XT_INT_FC_KIND_IN_ISO_C_BINDING
52 USE, INTRINSIC :: iso_c_binding, ONLY: XT_INT_FC_KIND
53 #endif
54 USE xt_mpi, ONLY: XT_INT_FC_MPIDT, xt_mpi_fint_kind
55 IMPLICIT NONE
56 PRIVATE
57 INTEGER, PUBLIC, PARAMETER :: xt_int_kind = XT_INT_FC_KIND
58 INTEGER, PUBLIC, PARAMETER :: pi2 = 4
59 INTEGER, PUBLIC, PARAMETER :: pi4 = 9
60 INTEGER, PUBLIC, PARAMETER :: pi8 = 14
61 INTEGER, PUBLIC, PARAMETER :: i2 = SELECTED_INT_KIND(pi2)
62 INTEGER, PUBLIC, PARAMETER :: i4 = SELECTED_INT_KIND(pi4)
63 INTEGER, PUBLIC, PARAMETER :: i8 = SELECTED_INT_KIND(pi8)
64 PUBLIC :: xt_initialize, xt_finalize, xt_abort, xt_get_default_comm, char
65 PUBLIC :: xt_initialized, xt_finalized
66 PUBLIC :: xt_slice_c_loc
67 PUBLIC :: OPERATOR(==), OPERATOR(/=)
68
69 PUBLIC :: xt_mpi_fint_kind
70 INTEGER, PUBLIC, PARAMETER :: xt_int_mpidt = XT_INT_FC_MPIDT
71 INTEGER(xt_int_kind), PARAMETER :: dummy = 0_xt_int_kind
72 !> number of decimal places needed to print any variable of type
73 !! INTEGER(xt_int_kind)
74 INTEGER, PUBLIC, PARAMETER :: xt_int_dec_len &
75 = CEILING(1.0 + REAL(DIGITS(dummy)) * LOG10(REAL(RADIX(dummy))))
76 CHARACTER(9), PARAMETER :: xt_stripe_tag = 'xt_stripe'
77 !> maximal length of string xt_stripe(a, b, c)
78 INTEGER, PUBLIC, PARAMETER :: xt_stripe2s_len &
79 = LEN(xt_stripe_tag) + 2 + 4 + 3 * xt_int_dec_len
80
81 TYPE, BIND(C), PUBLIC :: xt_stripe
82 INTEGER(xt_int_kind) :: start
83 INTEGER(xt_int_kind) :: stride
84 INTEGER(c_int) :: nstrides
85 END TYPE xt_stripe
86
87 TYPE, BIND(C), PUBLIC :: xt_bounds
88 INTEGER(xt_int_kind) :: start, size
89 END TYPE xt_bounds
90
91 !> describes range of positions starting with start up to start + size - 1
92 !! i.e. [start,start+size) if size is positive and down to start + size + 1
93 !! i.e. (start+size,start] if size is negative
94 TYPE, BIND(c), PUBLIC :: xt_pos_ext
95 INTEGER(c_int) :: start, size
96 END TYPE xt_pos_ext
97
98 INTERFACE
99
100 FUNCTION xt_get_default_comm() RESULT(comm) &
101 BIND(c, name='xt_get_default_comm_f')
102 IMPORT :: xt_mpi_fint_kind
103 IMPLICIT NONE
104 INTEGER(xt_mpi_fint_kind) :: comm
105 END FUNCTION xt_get_default_comm
106
107 SUBROUTINE xt_initialize(default_comm) BIND(C, name='xt_initialize_f')
108 IMPORT:: xt_mpi_fint_kind
109 IMPLICIT NONE
110 INTEGER(xt_mpi_fint_kind), INTENT(in) :: default_comm
111 END SUBROUTINE xt_initialize
112
113 SUBROUTINE xt_finalize() BIND(C, name='xt_finalize')
114 END SUBROUTINE xt_finalize
115
116 SUBROUTINE xt_restore_default_abort_hndl
117 END SUBROUTINE xt_restore_default_abort_hndl
118
119 END INTERFACE
120
121 INTERFACE xt_abort
122 MODULE PROCEDURE xt_abort4
123 MODULE PROCEDURE xt_abort3
124 END INTERFACE xt_abort
125
126 INTERFACE
127 SUBROUTINE xt_abort_c(comm, msg, source, line) BIND(c, name='xt_abort_f')
128 IMPORT :: c_char, xt_mpi_fint_kind
129 IMPLICIT NONE
130 INTEGER(xt_mpi_fint_kind), VALUE, INTENT(in):: comm
131 CHARACTER(kind=c_char), DIMENSION(*), INTENT(in) :: msg
132 CHARACTER(kind=c_char), DIMENSION(*), INTENT(in) :: source
133 INTEGER(xt_mpi_fint_kind), VALUE, INTENT(in) :: line
134 END SUBROUTINE xt_abort_c
135 END INTERFACE
136
137 INTERFACE char
138 MODULE PROCEDURE xt_stripe2char
139 END INTERFACE char
140
141 INTERFACE OPERATOR(==)
142 MODULE PROCEDURE xt_pos_ext_eq
143 END INTERFACE OPERATOR(==)
144
145 INTERFACE OPERATOR(/=)
146 MODULE PROCEDURE xt_pos_ext_ne
147 END INTERFACE OPERATOR(/=)
148
149 EXTERNAL :: xt_slice_c_loc
150
151 PUBLIC :: set_abort_handler, xt_restore_default_abort_hndl
152
153 ENUM, BIND( C )
154 ENUMERATOR :: xt_lib_pre_init, &
155 xt_lib_initialized, &
156 xt_lib_finalized
157 END ENUM
158 INTEGER(c_int), PUBLIC, BIND(c, name='xt_lib_state') :: xt_lib_state
159
160 CONTAINS
161
162 SUBROUTINE xt_abort4(comm, msg, source, line)
163 INTEGER, INTENT(in) :: comm
164 CHARACTER(len=*), INTENT(in) :: msg
165 CHARACTER(len=*), INTENT(in) :: source
166 INTEGER, INTENT(in) :: line
167 CALL xt_abort_c(comm, TRIM(msg)//c_null_char, &
168 TRIM(source)//c_null_char, line)
169 END SUBROUTINE xt_abort4
170
171 SUBROUTINE xt_abort3(msg, source, line)
172 CHARACTER(len=*), INTENT(in) :: msg
173 CHARACTER(len=*), INTENT(in) :: source
174 INTEGER, INTENT(in) :: line
175 CALL xt_abort_c(xt_get_default_comm(), TRIM(msg)//c_null_char, &
176 TRIM(source)//c_null_char, line)
177 END SUBROUTINE xt_abort3
178
179 ELEMENTAL FUNCTION xt_stripe2char(stripe) RESULT(str)
180 CHARACTER(len=xt_stripe2s_len) :: str
181 TYPE(xt_stripe), INTENT(in) :: stripe
182 WRITE (str, '(2a,3(i0,a))') xt_stripe_tag, '(', stripe%start, ', ', &
183 stripe%stride, ', ', stripe%nstrides, ')'
184 END FUNCTION xt_stripe2char
185
186 3 PURE FUNCTION xt_initialized() RESULT(is_initialized)
187 LOGICAL :: is_initialized
188 3 is_initialized = xt_lib_state > xt_lib_pre_init
189 3 END FUNCTION xt_initialized
190
191 3 PURE FUNCTION xt_finalized() RESULT(is_finalized)
192 LOGICAL :: is_finalized
193 3 is_finalized = xt_lib_state == xt_lib_finalized
194 3 END FUNCTION xt_finalized
195
196 ELEMENTAL FUNCTION xt_pos_ext_eq(a, b) RESULT(p)
197 TYPE(xt_pos_ext), INTENT(in) :: a, b
198 LOGICAL :: p
199 p = a%start == b%start .AND. (a%size == b%size &
200 .OR. (ABS(a%size) == 1 .AND. ABS(a%size) == ABS(b%size)))
201 END FUNCTION xt_pos_ext_eq
202
203 12 ELEMENTAL FUNCTION xt_pos_ext_ne(a, b) RESULT(p)
204 TYPE(xt_pos_ext), INTENT(in) :: a, b
205 LOGICAL :: p
206 p = a%start /= b%start .OR. (a%size /= b%size &
207 12 .AND. .NOT. (ABS(a%size) == 1 .AND. ABS(a%size) == ABS(b%size)))
208 12 END FUNCTION xt_pos_ext_ne
209
210 !> set routine f to use as abort function which is called on xt_abort
211 SUBROUTINE set_abort_handler(f)
212 INTERFACE
213 SUBROUTINE f(comm, msg, source, line)
214 INTEGER, INTENT(in) :: comm, line
215 CHARACTER(len=*), INTENT(in) :: msg, source
216 END SUBROUTINE f
217 SUBROUTINE xt_set_abort_handler(f)
218 INTERFACE
219 SUBROUTINE f(comm, msg, source, line)
220 INTEGER, INTENT(in) :: comm, line
221 CHARACTER(len=*), INTENT(in) :: msg, source
222 END SUBROUTINE f
223 END INTERFACE
224 END SUBROUTINE xt_set_abort_handler
225 END INTERFACE
226 CALL xt_set_abort_handler(f)
227 END SUBROUTINE set_abort_handler
228
229 END MODULE xt_core
230 !
231 ! Local Variables:
232 ! f90-continuation-indent: 5
233 ! coding: utf-8
234 ! indent-tabs-mode: nil
235 ! show-trailing-whitespace: t
236 ! require-trailing-newline: t
237 ! license-project-url: "https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/"
238 ! license-default: "bsd"
239 ! End:
240 !
241