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