Yet Another eXchange Tool  DO_NOT_EDIT_HERE
xt_core_f.f90
Go to the documentation of this file.
1 
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://doc.redmine.dkrz.de/yaxt/html/
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 MODULE xt_core
49  use, INTRINSIC :: iso_c_binding, only: c_char, c_null_char, c_int, &
50  c_long, c_short, c_long_long
51  USE xt_mpi, ONLY: xt_int_fc_mpidt
52  IMPLICIT NONE
53  PRIVATE
54  INTEGER, PUBLIC, PARAMETER :: xt_int_kind = xt_int_fc_kind
55  INTEGER, PUBLIC, PARAMETER :: pi2 = 4
56  INTEGER, PUBLIC, PARAMETER :: pi4 = 9
57  INTEGER, PUBLIC, PARAMETER :: pi8 = 14
58  INTEGER, PUBLIC, PARAMETER :: i2 = selected_int_kind(pi2)
59  INTEGER, PUBLIC, PARAMETER :: i4 = selected_int_kind(pi4)
60  INTEGER, PUBLIC, PARAMETER :: i8 = selected_int_kind(pi8)
61  PUBLIC :: xt_initialize, xt_finalize, xt_abort, xt_get_default_comm, char
62  PUBLIC :: xt_initialized, xt_finalized
63  PUBLIC :: xt_slice_c_loc
64  PUBLIC :: OPERATOR(==), OPERATOR(/=)
65 
66  INTEGER, PUBLIC, PARAMETER :: xt_mpi_fint_kind = xt_mpi_fint_fc_kind
67  INTEGER, PUBLIC, PARAMETER :: xt_int_mpidt = xt_int_fc_mpidt
68  INTEGER(xt_int_kind), PARAMETER :: dummy = 0_xt_int_kind
71  INTEGER, PUBLIC, PARAMETER :: xt_int_dec_len &
72  = ceiling(1.0 + REAL(DIGITS(dummy)) * log10(REAL(radix(dummy))))
73  CHARACTER(9), PARAMETER :: xt_stripe_tag = 'xt_stripe'
75  INTEGER, PUBLIC, PARAMETER :: xt_stripe2s_len &
76  = len(xt_stripe_tag) + 2 + 4 + 3 * xt_int_dec_len
77 
78  TYPE, bind(c), PUBLIC :: xt_stripe
79  INTEGER(xt_int_kind) :: start
80  INTEGER(xt_int_kind) :: stride
81  INTEGER(c_int) :: nstrides
82  END TYPE xt_stripe
83 
84  TYPE, bind(c), PUBLIC :: xt_bounds
85  INTEGER(xt_int_kind) :: start, size
86  END TYPE xt_bounds
87 
91  TYPE, bind(c), PUBLIC :: xt_pos_ext
92  INTEGER(c_int) :: start, size
93  END TYPE xt_pos_ext
94 
95  INTERFACE
96 
97  FUNCTION xt_get_default_comm() RESULT(comm) &
98  bind(c, name='xt_get_default_comm_f')
99  IMPORT :: xt_mpi_fint_kind
100  IMPLICIT NONE
101  INTEGER(xt_mpi_fint_kind) :: comm
102  END FUNCTION xt_get_default_comm
103 
104  SUBROUTINE xt_initialize(default_comm) bind(C, name='xt_initialize_f')
105  import:: c_int, xt_mpi_fint_kind
106  IMPLICIT NONE
107  INTEGER(xt_mpi_fint_kind), INTENT(in) :: default_comm
108  END SUBROUTINE xt_initialize
109 
110  SUBROUTINE xt_finalize() bind(C, name='xt_finalize')
111  END SUBROUTINE xt_finalize
112 
113  END INTERFACE
114 
115  INTERFACE xt_abort
116  MODULE PROCEDURE xt_abort4
117  MODULE PROCEDURE xt_abort3
118  END INTERFACE xt_abort
119 
120  INTERFACE
121  SUBROUTINE xt_abort_c(comm, msg, source, line) bind(c, name='xt_abort_f')
122  IMPORT :: c_char, c_int, xt_mpi_fint_kind
123  IMPLICIT NONE
124  INTEGER(xt_mpi_fint_kind), VALUE, INTENT(in):: comm
125  CHARACTER(kind=c_char), DIMENSION(*), INTENT(in) :: msg
126  CHARACTER(kind=c_char), DIMENSION(*), INTENT(in) :: source
127  INTEGER(xt_mpi_fint_kind), VALUE, INTENT(in) :: line
128  END SUBROUTINE xt_abort_c
129  END INTERFACE
130 
131  INTERFACE char
132  MODULE PROCEDURE xt_stripe2char
133  END INTERFACE char
134 
135  INTERFACE OPERATOR(==)
136  MODULE PROCEDURE xt_pos_ext_eq
137  END INTERFACE OPERATOR(==)
138 
139  INTERFACE OPERATOR(/=)
140  MODULE PROCEDURE xt_pos_ext_ne
141  END INTERFACE OPERATOR(/=)
142 
143  EXTERNAL :: xt_slice_c_loc
144 
145 CONTAINS
146 
147  SUBROUTINE xt_abort4(comm, msg, source, line)
148  INTEGER, INTENT(in) :: comm
149  CHARACTER(len=*), INTENT(in) :: msg
150  CHARACTER(len=*), INTENT(in) :: source
151  INTEGER, INTENT(in) :: line
152  CALL xt_abort_c(comm, trim(msg)//c_null_char, &
153  trim(source)//c_null_char, int(line, c_int))
154  END SUBROUTINE xt_abort4
155 
156  SUBROUTINE xt_abort3(msg, source, line)
157  CHARACTER(len=*), INTENT(in) :: msg
158  CHARACTER(len=*), INTENT(in) :: source
159  INTEGER, INTENT(in) :: line
160  CALL xt_abort_c(xt_get_default_comm(), trim(msg)//c_null_char, &
161  trim(source)//c_null_char, int(line, c_int))
162  END SUBROUTINE xt_abort3
163 
164  ELEMENTAL FUNCTION xt_stripe2char(stripe) RESULT(str)
165  CHARACTER(len=xt_stripe2s_len) :: str
166  TYPE(xt_stripe), INTENT(in) :: stripe
167  WRITE (str, '(2a,3(i0,a))') xt_stripe_tag, '(', stripe%start, ', ', &
168  stripe%stride, ', ', stripe%nstrides, ')'
169  END FUNCTION xt_stripe2char
170 
171  FUNCTION xt_initialized() RESULT(is_initialized)
172  LOGICAL :: is_initialized
173  INTERFACE
174  FUNCTION xt_initialized_c() bind(c, name='xt_initialized') &
175  result(is_initialized)
176  IMPORT :: c_int
177  INTEGER(c_int) :: is_initialized
178  END FUNCTION xt_initialized_c
179  END INTERFACE
180  is_initialized = xt_initialized_c() /= 0
181  END FUNCTION xt_initialized
182 
183  FUNCTION xt_finalized() RESULT(is_finalized)
184  LOGICAL :: is_finalized
185  INTERFACE
186  FUNCTION xt_finalized_c() bind(c, name='xt_finalized') &
187  result(is_finalized)
188  IMPORT :: c_int
189  INTEGER(c_int) :: is_finalized
190  END FUNCTION xt_finalized_c
191  END INTERFACE
192  is_finalized = xt_finalized_c() /= 0
193  END FUNCTION xt_finalized
194 
195  ELEMENTAL FUNCTION xt_pos_ext_eq(a, b) RESULT(p)
196  TYPE(xt_pos_ext), INTENT(in) :: a, b
197  LOGICAL :: p
198  p = a%start == b%start .AND. (a%size == b%size &
199  .OR. (abs(a%size) == 1 .AND. abs(a%size) == abs(b%size)))
200  END FUNCTION xt_pos_ext_eq
201 
202  ELEMENTAL FUNCTION xt_pos_ext_ne(a, b) RESULT(p)
203  TYPE(xt_pos_ext), INTENT(in) :: a, b
204  LOGICAL :: p
205  p = a%start /= b%start .OR. (a%size /= b%size &
206  .AND. .NOT. (abs(a%size) == 1 .AND. abs(a%size) == abs(b%size)))
207  END FUNCTION xt_pos_ext_ne
208 
209 END MODULE xt_core
210 !
211 ! Local Variables:
212 ! f90-continuation-indent: 5
213 ! coding: utf-8
214 ! indent-tabs-mode: nil
215 ! show-trailing-whitespace: t
216 ! require-trailing-newline: t
217 ! End:
218 !
integer, parameter, public i8
Definition: xt_core_f.f90:60
integer, parameter, public i4
Definition: xt_core_f.f90:59
integer, parameter, public pi8
Definition: xt_core_f.f90:57
integer, parameter, public pi4
Definition: xt_core_f.f90:56
void xt_initialize(MPI_Comm default_comm)
Definition: xt_init.c:69
describes range of positions starting with start up to start + size - 1 i.e. [start,start+size) if size is positive and down to start + size + 1 i.e. (start+size,start] if size is negative
Definition: xt_core_f.f90:91
integer, parameter, public xt_mpi_fint_kind
Definition: xt_core_f.f90:66
integer, parameter, public i2
Definition: xt_core_f.f90:58
integer, parameter, public xt_stripe2s_len
maximal length of string xt_stripe(a, b, c)
Definition: xt_core_f.f90:75
external, public xt_slice_c_loc
Definition: xt_core_f.f90:143
void xt_finalize(void)
Definition: xt_init.c:87
integer, parameter, public xt_int_kind
Definition: xt_core_f.f90:54
int xt_initialized(void)
Definition: xt_core_f.f90:172
integer, parameter, public pi2
Definition: xt_core_f.f90:55
integer, parameter, public xt_int_mpidt
Definition: xt_core_f.f90:67
int xt_finalized(void)
Definition: xt_core_f.f90:184
integer, parameter, public xt_int_dec_len
number of decimal places needed to print any variable of type INTEGER(xt_int_kind) ...
Definition: xt_core_f.f90:71