FMS  2025.04
Flexible Modeling System
mpp_sum_ad.inc
1 ! -*-f90-*-
2 
3 !***********************************************************************
4 !* Apache License 2.0
5 !*
6 !* This file is part of the GFDL Flexible Modeling System (FMS).
7 !*
8 !* Licensed under the Apache License, Version 2.0 (the "License");
9 !* you may not use this file except in compliance with the License.
10 !* You may obtain a copy of the License at
11 !*
12 !* http://www.apache.org/licenses/LICENSE-2.0
13 !*
14 !* FMS is distributed in the hope that it will be useful, but WITHOUT
15 !* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
16 !* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
17 !* PARTICULAR PURPOSE. See the License for the specific language
18 !* governing permissions and limitations under the License.
19 !***********************************************************************
20 !> @file
21 !> @brief Adjoint summation routines for @ref mpp_mod
22 
23 !> @addtogroup mpp_mod
24 !> @{
25 
26 !#######################################################################
27 
28  !> Sums array a.
29  !! when only first element is passed: this routine just converts to a call to MPP_SUM_
30  subroutine mpp_sum_scalar_ad_( a, pelist )
31  mpp_type_, intent(inout) :: a !< scalar value to sum over pelist
32  integer, intent(in), optional :: pelist(:)
33  mpp_type_ :: b(1)
34 
35  b(1) = a
36  if( debug )call mpp_error( note, 'MPP_SUM_SCALAR_: calling MPP_SUM_ ...' )
37  call mpp_sum_ad_( b, 1, pelist )
38  a = b(1)
39  return
40  end subroutine mpp_sum_scalar_ad_
41 
42 !#######################################################################
43  !> Sums 2d array across pes
44  subroutine mpp_sum_2d_ad_( a, length, pelist )
45  mpp_type_, intent(inout) :: a(:,:) !< 2d array to sum
46  integer, intent(in) :: length !< amount of indices in given 2d array
47  integer, intent(in), optional :: pelist(:) !< pelist to calculate sum across
48  mpp_type_ :: a1d(length)
49 
50  pointer( ptr, a1d )
51  ptr = loc(a)
52  call mpp_sum_ad( a1d, length, pelist )
53 
54  return
55  end subroutine mpp_sum_2d_ad_
56 
57 !#######################################################################
58  !> Sums 3d array across pes
59  subroutine mpp_sum_3d_ad_( a, length, pelist )
60  mpp_type_, intent(inout) :: a(:,:,:) !< 3d array to sum
61  integer, intent(in) :: length !< amount of indices in given 3d array
62  integer, intent(in), optional :: pelist(:) !< pelist to calculate sum across
63  mpp_type_ :: a1d(length)
64 
65  pointer( ptr, a1d )
66  ptr = loc(a)
67  call mpp_sum_ad( a1d, length, pelist )
68 
69  return
70  end subroutine mpp_sum_3d_ad_
71 
72 !#######################################################################
73  !> Sums 4d array across pes
74  subroutine mpp_sum_4d_ad_( a, length, pelist )
75  mpp_type_, intent(inout) :: a(:,:,:,:) !< 4d array to sum
76  integer, intent(in) :: length !< amount of indices in given 4d array
77  integer, intent(in), optional :: pelist(:) !< pelist to calculate sum across
78  mpp_type_ :: a1d(length)
79 
80  pointer( ptr, a1d )
81  ptr = loc(a)
82  call mpp_sum_ad( a1d, length, pelist )
83 
84  return
85  end subroutine mpp_sum_4d_ad_
86 
87 !#######################################################################
88  !> Sums 5d array across pes
89  subroutine mpp_sum_5d_ad_( a, length, pelist )
90  mpp_type_, intent(inout) :: a(:,:,:,:,:) !< 5d array to sum
91  integer, intent(in) :: length !< amount of indices in given 5d array
92  integer, intent(in), optional :: pelist(:) !< pelist to calculate sum across
93  mpp_type_ :: a1d(length)
94 
95  pointer( ptr, a1d )
96  ptr = loc(a)
97  call mpp_sum_ad( a1d, length, pelist )
98 
99  return
100  end subroutine mpp_sum_5d_ad_
subroutine mpp_sum_5d_ad_(a, length, pelist)
Sums 5d array across pes.
Definition: mpp_sum_ad.inc:90
subroutine mpp_sum_3d_ad_(a, length, pelist)
Sums 3d array across pes.
Definition: mpp_sum_ad.inc:60
subroutine mpp_sum_2d_ad_(a, length, pelist)
Sums 2d array across pes.
Definition: mpp_sum_ad.inc:45
subroutine mpp_sum_4d_ad_(a, length, pelist)
Sums 4d array across pes.
Definition: mpp_sum_ad.inc:75
subroutine mpp_sum_scalar_ad_(a, pelist)
Sums array a. when only first element is passed: this routine just converts to a call to MPP_SUM_.
Definition: mpp_sum_ad.inc:31