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 # define DEALLOC_(x)
11 # define ALLOC_(x)
12 # define ALLOCABLE_
13 # define PTR_
14 # define TO_NULL_
15 
16 ! NIMEM and NJMEM are the maximum number of grid points in the
17 ! x- and y-directions on each processsor.
18 # define NIMEM_ (((NIGLOBAL_-1)/NIPROC_)+1+2*NIHALO_)
19 # define NJMEM_ (((NJGLOBAL_-1)/NJPROC_)+1+2*NJHALO_)
20 
21 ! These are the macros that should be used when setting up ALLOCABLE_ or
22 ! PTR_ (heap) variables.
23 # ifdef SYMMETRIC_MEMORY_
24 # define NIMEMB_ 0:NIMEM_
25 # define NJMEMB_ 0:NJMEM_
26 # else
27 # define NIMEMB_ NIMEM_
28 # define NJMEMB_ NJMEM_
29 # endif
30 # define NIMEMB_PTR_ NIMEMB_
31 # define NJMEMB_PTR_ NJMEMB_
32 # define NIMEMB_SYM_ 0:NIMEM_
33 # define NJMEMB_SYM_ 0:NJMEM_
34 # define NKMEM_ NK_
35 # define NKMEM0_ 0:NK_
36 # define NK_INTERFACE_ NK_+1
37 # define C1_ 1
38 # define C2_ 2
39 # define C3_ 3
40 ! These are the macros that should be used for subroutine arguments
41 ! or for automatically allocated (stack) variables.
42 # define SZI_(G) NIMEM_
43 # define SZJ_(G) NJMEM_
44 # define SZK_(G) NK_
45 # define SZK0_(G) 0:NK_
46 # define SZIB_(G) NIMEMB_
47 # define SZJB_(G) NJMEMB_
48 # define SZIBS_(G) 0:NIMEM_
49 # define SZJBS_(G) 0:NJMEM_
50 
51 #else
52 !/* Dynamic memory allocation section */
53 
54 !/*! Deallocates array x when using dynamic memory mode. Does nothing in static memory mode.*/
55 # define DEALLOC_(x) deallocate(x)
56 !/*! Allocates array x when using dynamic memory mode. Does nothing in static memory mode.*/
57 # define ALLOC_(x) allocate(x)
58 !/*! Attaches the ALLOCATABLE attribute to an array in dynamic memory mode. Does nothing in static memory mode.*/
59 # define ALLOCABLE_ ,allocatable
60 !/*! Attaches the POINTER attribute to an array in dynamic memory mode. Does nothing in static memory mode.*/
61 # define PTR_ ,pointer
62 !/*! Nullify a pointer in dynamic memory mode. Does nothing in static memory mode.*/
63 # define TO_NULL_ =>NULL()
64 
65 !/* These are the macros that should be used when setting up ALLOCABLE_ or PTR_ (heap) variables. */
66 
67 !/*! Expands to : in dynamic memory mode, or is the i-shape of a tile in static memory mode. Use for heap (ALLOCABLE_ or PTR_) variables at h- or v- points. */
68 # define NIMEM_ :
69 !/*! Expands to : in dynamic memory mode, or is the j-shape of a tile in static memory mode. Use for heap (ALLOCABLE_ or PTR_) variables at h- or u- points. */
70 # define NJMEM_ :
71 !/*! Expands to : in dynamic memory mode, or to NIMEMB_ in static memory mode. Use for heap (ALLOCABLE_ or PTR_) variables at h- or v- points. */
72 # define NIMEMB_PTR_ :
73 !/*! Expands to : in dynamic memory mode, or to NJMEMB_ in static memory mode. Use for heap (ALLOCABLE_ or PTR_) variables at h- or u- points. */
74 # define NJMEMB_PTR_ :
75 # ifdef SYMMETRIC_MEMORY_
76 !/*! Expands to : or 0: in dynamic memory mode, or is the staggered i-shape of a tile in static memory mode. Use for heap (ALLOCABLE_ or PTR_) variables at q- or u- points. */
77 # define NIMEMB_ 0:
78 !/*! Expands to : or 0: in dynamic memory mode, or is the staggered j-shape of a tile in static memory mode. Use for heap (ALLOCABLE_ or PTR_) variables at q- or v- points. */
79 # define NJMEMB_ 0:
80 # else
81 # define NIMEMB_ :
82 # define NJMEMB_ :
83 # endif
84 !/*! Expands to 0: in dynamic memory mode, or is the staggered i-shape of a tile in static memory mode. Use for always-symmetric heap (ALLOCABLE_ or PTR_) variables at q- or u- points. */
85 # define NIMEMB_SYM_ 0:
86 !/*! Expands to 0: in dynamic memory mode, or is the staggered j-shape of a tile in static memory mode. Use for always-symmetric heap (ALLOCABLE_ or PTR_) variables at q- or v- points. */
87 # define NJMEMB_SYM_ 0:
88 !/*! Expands to : in dynamic memory mode or is to the number of layers in static memory mode. Use for heap (ALLOCABLE_ or PTR_) layer variables. */
89 # define NKMEM_ :
90 !/*! Expands to 0: in dynamic memory mode or to 0:NK_ in static memory mode. Use for heap (ALLOCABLE_ or PTR_) interface variables. */
91 # define NKMEM0_ 0:
92 !/*! Expands to : in dynamic memory mode or to NK_+1 in static memory mode. Use for heap (ALLOCABLE_ or PTR_) interface variables. */
93 # define NK_INTERFACE_ :
94 !/*! Expands to : or 1. UNKNOWN PURPOSE! */
95 # define C1_ :
96 !/*! Expands to : or 2. UNKNOWN PURPOSE! */
97 # define C2_ :
98 !/*! Expands to : or 3. UNKNOWN PURPOSE! */
99 # define C3_ :
100 
101 !/*! \todo Explain or remove C1_, C2_ and C3_ */
102 
103 !/* These are the macros that should be used for subroutine arguments or for automatically allocated (stack) variables. */
104 
105 !/*! The i-shape of a dummy argument staggered at h- or v-points. */
106 # define SZI_(G) G%isd:G%ied
107 !/*! The j-shape of a dummy argument staggered at h- or u-points. */
108 # define SZJ_(G) G%jsd:G%jed
109 !/*! The k-shape of a layer dummy argument. */
110 # define SZK_(G) G%ke
111 !/*! The k-shape of an interface dummy argument. */
112 # define SZK0_(G) 0:G%ke
113 !/*! The i-shape of a dummy argument staggered at q- or u-points. */
114 # define SZIB_(G) G%IsdB:G%IedB
115 !/*! The j-shape of a dummy argument staggered at q- or v-points. */
116 # define SZJB_(G) G%JsdB:G%JedB
117 !/*! The i-shape of a symmetric dummy argument staggered at q- or u-points. */
118 # define SZIBS_(G) G%isd-1:G%ied
119 !/*! The j-shape of a symmetric dummy argument staggered at q- or v-points. */
120 # define SZJBS_(G) G%jsd-1:G%jed
121 
122 #endif
123 
124 !/* These dynamic size macros always give the same results (for now). */
125 
126 !/*! The i-shape of a dynamic dummy argument staggered at h- or v-points. */
127 #define SZDI_(G) G%isd:G%ied
128 !/*! The i-shape of a dynamic dummy argument staggered at q- or u-points. */
129 #define SZDIB_(G) G%IsdB:G%IedB
130 !/*! The j-shape of a dynamic dummy argument staggered at h- or u-points. */
131 #define SZDJ_(G) G%jsd:G%jed
132 !/*! The j-shape of a dynamic dummy argument staggered at q- or v-points. */
133 #define SZDJB_(G) G%JsdB:G%JedB
#define PTR_
#define SYMMETRIC_MEMORY_
Definition: MOM_memory.h:16
#define SZI_(G)
#define NIHALO_
Definition: MOM_memory.h:28
#define NIGLOBAL_
Definition: MOM_memory.h:6
#define NIMEM_
#define ALLOCABLE_
#define NIPROC_
Definition: MOM_memory.h:19