FMS  2025.04
Flexible Modeling System
mpp_sum.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 
21 !> @file
22 !> @brief Summation routines for @ref mpp_mod
23 
24 !> @addtogroup mpp_mod
25 !> @{
26 !#######################################################################
27 
28  !> Sums array a when only first element is passed: this routine just converts to a call to MPP_SUM_
29  subroutine mpp_sum_scalar_( a, pelist )
30  mpp_type_, intent(inout) :: a
31  integer, intent(in), optional :: pelist(:)
32  mpp_type_ :: b(1)
33 
34  b(1) = a
35  if( debug )call mpp_error( note, 'MPP_SUM_SCALAR_: calling MPP_SUM_ ...' )
36  call mpp_sum_( b, 1, pelist )
37  a = b(1)
38  return
39  end subroutine mpp_sum_scalar_
40 
41 !#######################################################################
42  !> Sums 2d array across pes
43  subroutine mpp_sum_2d_( a, length, pelist )
44  mpp_type_, intent(inout) :: a(:,:) !< 2d array to sum
45  integer, intent(in) :: length !< amount of indices in given 2d array
46  integer, intent(in), optional :: pelist(:) !< pelist to calculate sum across
47  mpp_type_ :: a1d(length)
48 
49  pointer( ptr, a1d )
50  ptr = loc(a)
51  call mpp_sum( a1d, length, pelist )
52 
53  return
54  end subroutine mpp_sum_2d_
55 
56 !#######################################################################
57  !> Sums 3d array across pes
58  subroutine mpp_sum_3d_( a, length, pelist )
59  mpp_type_, intent(inout) :: a(:,:,:) !< 3d array to sum
60  integer, intent(in) :: length !< amount of indices in given 3d array
61  integer, intent(in), optional :: pelist(:) !< pelist to calculate sum across
62  mpp_type_ :: a1d(length)
63 
64  pointer( ptr, a1d )
65  ptr = loc(a)
66  call mpp_sum( a1d, length, pelist )
67 
68  return
69  end subroutine mpp_sum_3d_
70 
71 !#######################################################################
72  !> Sums 4d array across pes
73  subroutine mpp_sum_4d_( a, length, pelist )
74  mpp_type_, intent(inout) :: a(:,:,:,:) !< 4d array to sum
75  integer, intent(in) :: length !< amount of indices in given 4d array
76  integer, intent(in), optional :: pelist(:) !< pelist to calculate sum across
77  mpp_type_ :: a1d(length)
78 
79  pointer( ptr, a1d )
80  ptr = loc(a)
81  call mpp_sum( a1d, length, pelist )
82 
83  return
84  end subroutine mpp_sum_4d_
85 
86 !#######################################################################
87  !> Sums 5d array across pes
88  subroutine mpp_sum_5d_( a, length, pelist )
89  mpp_type_, intent(inout) :: a(:,:,:,:,:) !< 5d array to sum
90  integer, intent(in) :: length !< amount of indices in given 5d array
91  integer, intent(in), optional :: pelist(:) !< pelist to calculate sum across
92  mpp_type_ :: a1d(length)
93 
94  pointer( ptr, a1d )
95  ptr = loc(a)
96  call mpp_sum( a1d, length, pelist )
97 
98  return
99  end subroutine mpp_sum_5d_
100 !> @}
subroutine mpp_sum_2d_(a, length, pelist)
Sums 2d array across pes.
Definition: mpp_sum.inc:44
subroutine mpp_sum_3d_(a, length, pelist)
Sums 3d array across pes.
Definition: mpp_sum.inc:59
subroutine mpp_sum_scalar_(a, pelist)
Sums array a when only first element is passed: this routine just converts to a call to MPP_SUM_.
Definition: mpp_sum.inc:30
subroutine mpp_sum_4d_(a, length, pelist)
Sums 4d array across pes.
Definition: mpp_sum.inc:74
subroutine mpp_sum_5d_(a, length, pelist)
Sums 5d array across pes.
Definition: mpp_sum.inc:89