MOM_memory_macros.h

1! This file is part of MOM6, the Modular Ocean Model version 6.
2! See the LICENSE file for licensing information.
3! SPDX-License-Identifier: Apache-2.0
4
5!//! \brief Memory macros
6!//! \details This is a header file to define macros for static and dynamic memory allocation.
7!//! Define STATIC_MEMORY_ in MOM_memory.h for static memory allocation.
8!//! Otherwise dynamic memory allocation will be assumed.
9!//!
10!//! For explanation of symmetric and non-symmetric memory modes see \ref Horizontal_Indexing.
11!//! \file MOM_memory_macros.h
12
13#ifdef STATIC_MEMORY_
14!/* Static memory allocation section */
15
16!/// Deallocates array x when using dynamic memory mode. Does nothing in static memory mode.
17# define DEALLOC_(x)
18!/// Allocates array x when using dynamic memory mode. Does nothing in static memory mode.
19# define ALLOC_(x)
20!/// Attaches the ALLOCATABLE attribute to an array in dynamic memory mode. Does nothing in static memory mode.
21# define ALLOCABLE_
22!/// Attaches the POINTER attribute to an array in dynamic memory mode. Does nothing in static memory mode.
23# define PTR_
24!/// Nullify a pointer in dynamic memory mode. Does nothing in static memory mode.
25# define TO_NULL_
26
27!/* These are the macros that should be used when setting up ALLOCABLE_ or PTR_ (heap) variables. */
28
29!/// Expands to : in dynamic memory mode, or is the i-shape of a tile in static memory mode.
30!/// Use for heap (ALLOCABLE_ or PTR_) variables at h- or v- points.
31# define NIMEM_ (((NIGLOBAL_-1)/NIPROC_)+1+2*NIHALO_)
32!/// Expands to : in dynamic memory mode, or is the j-shape of a tile in static memory mode.
33!/// Use for heap (ALLOCABLE_ or PTR_) variables at h- or u- points.
34# define NJMEM_ (((NJGLOBAL_-1)/NJPROC_)+1+2*NJHALO_)
35
36# ifdef SYMMETRIC_MEMORY_
37!/// Expands to : or 0: in dynamic memory mode, or is the staggered i-shape of a tile in static memory mode.
38!/// Use for heap (ALLOCABLE_ or PTR_) variables at q- or u- points.
39# define NIMEMB_ 0:NIMEM_
40!/// Expands to : or 0: in dynamic memory mode, or is the staggered j-shape of a tile in static memory mode.
41!/// Use for heap (ALLOCABLE_ or PTR_) variables at q- or v- points.
42# define NJMEMB_ 0:NJMEM_
43# else
44!/// Expands to : or 0: in dynamic memory mode, or is the staggered i-shape of a tile in static memory mode.
45!/// Use for heap (ALLOCABLE_ or PTR_) variables at q- or u- points.
46# define NIMEMB_ NIMEM_
47!/// Expands to : or 0: in dynamic memory mode, or is the staggered j-shape of a tile in static memory mode.
48!/// Use for heap (ALLOCABLE_ or PTR_) variables at q- or v- points.
49# define NJMEMB_ NJMEM_
50# endif
51!/// Expands to : in dynamic memory mode, or to NIMEMB_ in static memory mode.
52!/// Use for heap (ALLOCABLE_ or PTR_) variables at h- or v- points.
53# define NIMEMB_PTR_ NIMEMB_
54!/// Expands to : in dynamic memory mode, or to NJMEMB_ in static memory mode.
55!/// Use for heap (ALLOCABLE_ or PTR_) variables at h- or u- points.
56# define NJMEMB_PTR_ NJMEMB_
57!/// Expands to 0: in dynamic memory mode, or is the staggered i-shape of a tile in static memory mode.
58!/// Use for always-symmetric heap (ALLOCABLE_ or PTR_) variables at q- or u- points.
59# define NIMEMB_SYM_ 0:NIMEM_
60!/// Expands to 0: in dynamic memory mode, or is the staggered j-shape of a tile in static memory mode.
61!/// Use for always-symmetric heap (ALLOCABLE_ or PTR_) variables at q- or v- points.
62# define NJMEMB_SYM_ 0:NJMEM_
63!/// Expands to : in dynamic memory mode or is to the number of layers in static memory mode.
64!/// Use for heap (ALLOCABLE_ or PTR_) layer variables.
65# define NKMEM_ NK_
66!/// Expands to 0: in dynamic memory mode or to 0:NK_ in static memory mode.
67!/// Use for heap (ALLOCABLE_ or PTR_) interface variables.
68# define NKMEM0_ 0:NK_
69!/// Expands to : in dynamic memory mode or to NK_+1 in static memory mode.
70!/// Use for heap (ALLOCABLE_ or PTR_) interface variables.
71# define NK_INTERFACE_ NK_+1
72!/// Expands to : or 1. UNKNOWN PURPOSE!
73# define C1_ 1
74!/// Expands to : or 2. UNKNOWN PURPOSE!
75# define C2_ 2
76!/// Expands to : or 3. UNKNOWN PURPOSE!
77# define C3_ 3
78
79!/* These are the macros that should be used for subroutine arguments or for automatically allocated (stack) variables. */
80
81!/// The i-shape of a dummy argument staggered at h- or v-points.
82# define SZI_(G) NIMEM_
83!/// The j-shape of a dummy argument staggered at h- or u-points.
84# define SZJ_(G) NJMEM_
85!/// The k-shape of a layer dummy argument.
86# define SZK_(G) NK_
87!/// The k-shape of an interface dummy argument.
88# define SZK0_(G) 0:NK_
89!/// The i-shape of a dummy argument staggered at q- or u-points.
90# define SZIB_(G) NIMEMB_
91!/// The j-shape of a dummy argument staggered at q- or v-points.
92# define SZJB_(G) NJMEMB_
93!/// The i-shape of a symmetric dummy argument staggered at q- or u-points.
94# define SZIBS_(G) 0:NIMEM_
95!/// The j-shape of a symmetric dummy argument staggered at q- or v-points.
96# define SZJBS_(G) 0:NJMEM_
97
98#else
99!/* Dynamic memory allocation section */
100
101!/// Deallocates array x when using dynamic memory mode. Does nothing in static memory mode.
102# define DEALLOC_(x) deallocate(x)
103!/// Allocates array x when using dynamic memory mode. Does nothing in static memory mode.
104# define ALLOC_(x) allocate(x)
105!/// Attaches the ALLOCATABLE attribute to an array in dynamic memory mode. Does nothing in static memory mode.
106# define ALLOCABLE_ ,allocatable
107!/// Attaches the POINTER attribute to an array in dynamic memory mode. Does nothing in static memory mode.
108# define PTR_ ,pointer
109!/// Nullify a pointer in dynamic memory mode. Does nothing in static memory mode.
110# define TO_NULL_ =>NULL()
111
112!/* These are the macros that should be used when setting up ALLOCABLE_ or PTR_ (heap) variables. */
113
114!/// Expands to : in dynamic memory mode, or is the i-shape of a tile in static memory mode.
115!/// Use for heap (ALLOCABLE_ or PTR_) variables at h- or v- points.
116# define NIMEM_ :
117!/// Expands to : in dynamic memory mode, or is the j-shape of a tile in static memory mode.
118!/// Use for heap (ALLOCABLE_ or PTR_) variables at h- or u- points.
119# define NJMEM_ :
120!/// Expands to : in dynamic memory mode, or to NIMEMB_ in static memory mode.
121!/// Use for heap (ALLOCABLE_ or PTR_) variables at h- or v- points.
122# define NIMEMB_PTR_ :
123!/// Expands to : in dynamic memory mode, or to NJMEMB_ in static memory mode.
124!/// Use for heap (ALLOCABLE_ or PTR_) variables at h- or u- points.
125# define NJMEMB_PTR_ :
126# ifdef SYMMETRIC_MEMORY_
127!/// Expands to : or 0: in dynamic memory mode, or is the staggered i-shape of a tile in static memory mode.
128!/// Use for heap (ALLOCABLE_ or PTR_) variables at q- or u- points.
129# define NIMEMB_ 0:
130!/// Expands to : or 0: in dynamic memory mode, or is the staggered j-shape of a tile in static memory mode.
131!/// Use for heap (ALLOCABLE_ or PTR_) variables at q- or v- points.
132# define NJMEMB_ 0:
133# else
134!/// Expands to : or 0: in dynamic memory mode, or is the staggered i-shape of a tile in static memory mode.
135!/// Use for heap (ALLOCABLE_ or PTR_) variables at q- or u- points.
136# define NIMEMB_ :
137!/// Expands to : or 0: in dynamic memory mode, or is the staggered j-shape of a tile in static memory mode.
138!/// Use for heap (ALLOCABLE_ or PTR_) variables at q- or v- points.
139# define NJMEMB_ :
140# endif
141!/// Expands to 0: in dynamic memory mode, or is the staggered i-shape of a tile in static memory mode.
142!/// Use for always-symmetric heap (ALLOCABLE_ or PTR_) variables at q- or u- points.
143# define NIMEMB_SYM_ 0:
144!/// Expands to 0: in dynamic memory mode, or is the staggered j-shape of a tile in static memory mode.
145!/// Use for always-symmetric heap (ALLOCABLE_ or PTR_) variables at q- or v- points.
146# define NJMEMB_SYM_ 0:
147!/// Expands to : in dynamic memory mode or is to the number of layers in static memory mode.
148!/// Use for heap (ALLOCABLE_ or PTR_) layer variables.
149# define NKMEM_ :
150!/// Expands to 0: in dynamic memory mode or to 0:NK_ in static memory mode.
151!/// Use for heap (ALLOCABLE_ or PTR_) interface variables.
152# define NKMEM0_ 0:
153!/// Expands to : in dynamic memory mode or to NK_+1 in static memory mode.
154!/// Use for heap (ALLOCABLE_ or PTR_) interface variables.
155# define NK_INTERFACE_ :
156!/// Expands to : or 1. UNKNOWN PURPOSE!
157# define C1_ :
158!/// Expands to : or 2. UNKNOWN PURPOSE!
159# define C2_ :
160!/// Expands to : or 3. UNKNOWN PURPOSE!
161# define C3_ :
162
163!/// \todo Explain or remove C1_, C2_ and C3_
164
165!/* These are the macros that should be used for subroutine arguments or for automatically allocated (stack) variables. */
166
167!/// The i-shape of a dummy argument staggered at h- or v-points.
168# define SZI_(G) G%isd:G%ied
169!/// The j-shape of a dummy argument staggered at h- or u-points.
170# define SZJ_(G) G%jsd:G%jed
171!/// The k-shape of a layer dummy argument.
172# define SZK_(G) G%ke
173!/// The k-shape of an interface dummy argument.
174# define SZK0_(G) 0:G%ke
175!/// The i-shape of a dummy argument staggered at q- or u-points.
176# define SZIB_(G) G%IsdB:G%IedB
177!/// The j-shape of a dummy argument staggered at q- or v-points.
178# define SZJB_(G) G%JsdB:G%JedB
179!/// The i-shape of a symmetric dummy argument staggered at q- or u-points.
180# define SZIBS_(G) G%isd-1:G%ied
181!/// The j-shape of a symmetric dummy argument staggered at q- or v-points.
182# define SZJBS_(G) G%jsd-1:G%jed
183
184#endif
185
186!/* These dynamic size macros always give the same results (for now). */
187
188!/// The i-shape of a dynamic dummy argument staggered at h- or v-points.
189#define SZDI_(G) G%isd:G%ied
190!/// The i-shape of a dynamic dummy argument staggered at q- or u-points.
191#define SZDIB_(G) G%IsdB:G%IedB
192!/// The j-shape of a dynamic dummy argument staggered at h- or u-points.
193#define SZDJ_(G) G%jsd:G%jed
194!/// The j-shape of a dynamic dummy argument staggered at q- or v-points.
195#define SZDJB_(G) G%JsdB:G%JedB