Fix undefined behavior in RSL_LITE (#1765)
[WRF.git] / external / RSL_LITE / rsl_lite.h
blobda430be9678c3863485f3295ef013c2516900e67
1 #ifndef CRAY
2 # ifdef NOUNDERSCORE
3 # define RSL_LITE_ERROR_DUP1 rsl_error_dup1
4 # define BYTE_BCAST byte_bcast
5 # define BYTE_BCAST_FROM_ROOT byte_bcast_from_root
6 # define RSL_LITE_INIT_EXCH rsl_lite_init_exch
7 # define RSL_LITE_EXCH_Y rsl_lite_exch_y
8 # define RSL_LITE_EXCH_X rsl_lite_exch_x
9 # define RSL_LITE_PACK rsl_lite_pack
10 #if ( WRFPLUS == 1 )
11 # define RSL_LITE_PACK_AD rsl_lite_pack_ad
12 #endif
13 # define RSL_LITE_BCAST_MSGS rsl_lite_bcast_msgs
14 # define RSL_LITE_TO_CHILD_MSG rsl_lite_to_child_msg
15 # define RSL_LITE_TO_CHILD_INFO rsl_lite_to_child_info
16 # define RSL_LITE_FROM_PARENT_MSG rsl_lite_from_parent_msg
17 # define RSL_LITE_FROM_PARENT_INFO rsl_lite_from_parent_info
18 # define RSL_LITE_MERGE_MSGS rsl_lite_merge_msgs
19 # define RSL_LITE_TO_PARENT_MSG rsl_lite_to_parent_msg
20 # define RSL_LITE_TO_PARENT_INFO rsl_lite_to_parent_info
21 # define RSL_LITE_FROM_CHILD_MSG rsl_lite_from_child_msg
22 # define RSL_LITE_FROM_CHILD_INFO rsl_lite_from_child_info
23 # define RSL_INTERNAL_MILLICLOCK rsl_internal_milliclock
24 # define RSL_INTERNAL_MICROCLOCK rsl_internal_microclock
25 # define TASK_FOR_POINT task_for_point
26 # define TASK_FOR_POINT_MESSAGE task_for_point_message
27 # define RSL_LITE_INIT_PERIOD rsl_lite_init_period
28 # define RSL_LITE_EXCH_PERIOD_Y rsl_lite_exch_period_y
29 # define RSL_LITE_EXCH_PERIOD_X rsl_lite_exch_period_x
30 # define RSL_LITE_PACK_PERIOD rsl_lite_pack_period
31 # define RSL_LITE_INIT_SWAP rsl_lite_init_swap
32 # define RSL_LITE_SWAP rsl_lite_swap
33 # define RSL_LITE_PACK_SWAP rsl_lite_pack_swap
34 # define RSL_LITE_INIT_CYCLE rsl_lite_init_cycle
35 # define RSL_LITE_CYCLE rsl_lite_cycle
36 # define RSL_LITE_PACK_CYCLE rsl_lite_pack_cycle
37 # define F_PACK_LINT f_pack_lint
38 # define F_PACK_INT f_pack_int
39 # define F_UNPACK_LINT f_unpack_lint
40 # define F_UNPACK_INT f_unpack_int
41 #if ( WRFPLUS == 1 )
42 # define F_PACK_LINT_AD f_pack_lint_ad
43 # define F_PACK_INT_AD f_pack_int_ad
44 # define F_UNPACK_LINT_AD f_unpack_lint_ad
45 # define F_UNPACK_INT_AD f_unpack_int_ad
46 #endif
47 # define RSL_LITE_GET_HOSTNAME rsl_lite_get_hostname
48 # define RSL_LITE_NESTING_RESET rsl_lite_nesting_reset
49 # else
50 # ifdef F2CSTYLE
51 # define RSL_LITE_ERROR_DUP1 rsl_error_dup1__
52 # define BYTE_BCAST byte_bcast__
53 # define BYTE_BCAST_FROM_ROOT byte_bcast_from_root__
54 # define RSL_LITE_INIT_EXCH rsl_lite_init_exch__
55 # define RSL_LITE_EXCH_Y rsl_lite_exch_y__
56 # define RSL_LITE_EXCH_X rsl_lite_exch_x__
57 # define RSL_LITE_PACK rsl_lite_pack__
58 #if ( WRFPLUS == 1 )
59 # define RSL_LITE_PACK_AD rsl_lite_pack_ad__
60 #endif
61 # define RSL_LITE_BCAST_MSGS rsl_lite_bcast_msgs__
62 # define RSL_LITE_TO_CHILD_MSG rsl_lite_to_child_msg__
63 # define RSL_LITE_TO_CHILD_INFO rsl_lite_to_child_info__
64 # define RSL_LITE_FROM_PARENT_MSG rsl_lite_from_parent_msg__
65 # define RSL_LITE_FROM_PARENT_INFO rsl_lite_from_parent_info__
66 # define RSL_LITE_MERGE_MSGS rsl_lite_merge_msgs__
67 # define RSL_LITE_TO_PARENT_MSG rsl_lite_to_parent_msg__
68 # define RSL_LITE_TO_PARENT_INFO rsl_lite_to_parent_info__
69 # define RSL_LITE_FROM_CHILD_MSG rsl_lite_from_child_msg__
70 # define RSL_LITE_FROM_CHILD_INFO rsl_lite_from_child_info__
71 # define RSL_INTERNAL_MILLICLOCK rsl_internal_milliclock__
72 # define RSL_INTERNAL_MICROCLOCK rsl_internal_microclock__
73 # define TASK_FOR_POINT task_for_point__
74 # define TASK_FOR_POINT_MESSAGE task_for_point_message__
75 # define RSL_LITE_INIT_PERIOD rsl_lite_init_period__
76 # define RSL_LITE_EXCH_PERIOD_Y rsl_lite_exch_period_y__
77 # define RSL_LITE_EXCH_PERIOD_X rsl_lite_exch_period_x__
78 # define RSL_LITE_PACK_PERIOD rsl_lite_pack_period__
79 # define RSL_LITE_INIT_SWAP rsl_lite_init_swap__
80 # define RSL_LITE_SWAP rsl_lite_swap__
81 # define RSL_LITE_PACK_SWAP rsl_lite_pack_swap__
82 # define RSL_LITE_INIT_CYCLE rsl_lite_init_cycle__
83 # define RSL_LITE_CYCLE rsl_lite_cycle__
84 # define RSL_LITE_PACK_CYCLE rsl_lite_pack_cycle__
85 # define F_PACK_LINT f_pack_lint__
86 # define F_PACK_INT f_pack_int__
87 # define F_UNPACK_LINT f_unpack_lint__
88 # define F_UNPACK_INT f_unpack_int__
89 #if ( WRFPLUS == 1 )
90 # define F_PACK_LINT_AD f_pack_lint_ad__
91 # define F_PACK_INT_AD f_pack_int_ad__
92 # define F_UNPACK_LINT_AD f_unpack_lint_ad__
93 # define F_UNPACK_INT_AD f_unpack_int_ad__
94 #endif
95 # define RSL_LITE_GET_HOSTNAME rsl_lite_get_hostname__
96 # define RSL_LITE_NESTING_RESET rsl_lite_nesting_reset__
97 # else
98 # define RSL_LITE_ERROR_DUP1 rsl_error_dup1_
99 # define BYTE_BCAST byte_bcast_
100 # define BYTE_BCAST_FROM_ROOT byte_bcast_from_root_
101 # define RSL_LITE_INIT_EXCH rsl_lite_init_exch_
102 # define RSL_LITE_EXCH_Y rsl_lite_exch_y_
103 # define RSL_LITE_EXCH_X rsl_lite_exch_x_
104 # define RSL_LITE_PACK rsl_lite_pack_
105 #if ( WRFPLUS == 1 )
106 # define RSL_LITE_PACK_AD rsl_lite_pack_ad_
107 #endif
108 # define RSL_LITE_BCAST_MSGS rsl_lite_bcast_msgs_
109 # define RSL_LITE_TO_CHILD_MSG rsl_lite_to_child_msg_
110 # define RSL_LITE_TO_CHILD_INFO rsl_lite_to_child_info_
111 # define RSL_LITE_FROM_PARENT_MSG rsl_lite_from_parent_msg_
112 # define RSL_LITE_FROM_PARENT_INFO rsl_lite_from_parent_info_
113 # define RSL_LITE_MERGE_MSGS rsl_lite_merge_msgs_
114 # define RSL_LITE_TO_PARENT_MSG rsl_lite_to_parent_msg_
115 # define RSL_LITE_TO_PARENT_INFO rsl_lite_to_parent_info_
116 # define RSL_LITE_FROM_CHILD_MSG rsl_lite_from_child_msg_
117 # define RSL_LITE_FROM_CHILD_INFO rsl_lite_from_child_info_
118 # define RSL_INTERNAL_MILLICLOCK rsl_internal_milliclock_
119 # define RSL_INTERNAL_MICROCLOCK rsl_internal_microclock_
120 # define TASK_FOR_POINT task_for_point_
121 # define TASK_FOR_POINT_MESSAGE task_for_point_message_
122 # define RSL_LITE_INIT_PERIOD rsl_lite_init_period_
123 # define RSL_LITE_EXCH_PERIOD_Y rsl_lite_exch_period_y_
124 # define RSL_LITE_EXCH_PERIOD_X rsl_lite_exch_period_x_
125 # define RSL_LITE_PACK_PERIOD rsl_lite_pack_period_
126 # define RSL_LITE_INIT_SWAP rsl_lite_init_swap_
127 # define RSL_LITE_SWAP rsl_lite_swap_
128 # define RSL_LITE_PACK_SWAP rsl_lite_pack_swap_
129 # define RSL_LITE_INIT_CYCLE rsl_lite_init_cycle_
130 # define RSL_LITE_CYCLE rsl_lite_cycle_
131 # define RSL_LITE_PACK_CYCLE rsl_lite_pack_cycle_
132 # define F_PACK_LINT f_pack_lint_
133 # define F_PACK_INT f_pack_int_
134 # define F_UNPACK_LINT f_unpack_lint_
135 # define F_UNPACK_INT f_unpack_int_
136 #if ( WRFPLUS == 1 )
137 # define F_PACK_LINT_AD f_pack_lint_ad_
138 # define F_PACK_INT_AD f_pack_int_ad_
139 # define F_UNPACK_LINT_AD f_unpack_lint_ad_
140 # define F_UNPACK_INT_AD f_unpack_int_ad_
141 #endif
142 # define RSL_LITE_GET_HOSTNAME rsl_lite_get_hostname_
143 # define RSL_LITE_NESTING_RESET rsl_lite_nesting_reset_
144 # endif
145 # endif
146 #endif
148 #define RSL_SENDBUF 0
149 #define RSL_RECVBUF 1
150 #define RSL_FREEBUF 3
151 #define RSL_MAXPROC 100001
152 #define RSL_INVALID -1
154 /* this must be the same as defined in frame/module_driver_constants.F */
155 #define DATA_ORDER_XYZ 1
156 #define DATA_ORDER_YXZ 2
157 #define DATA_ORDER_ZXY 3
158 #define DATA_ORDER_ZYX 4
159 #define DATA_ORDER_XZY 5
160 #define DATA_ORDER_YZX 6
163 #define RSL_MALLOC(T,N) (T *)rsl_malloc(__FILE__,__LINE__,(sizeof(T))*(N))
164 #define RSL_FREE(P) rsl_free(&(P))
166 char * buffer_for_proc ( int P, int size, int code ) ;
167 void * rsl_malloc( char * f, int l, int s ) ;
168 void rsl_free( char ** p ) ;
169 typedef int * int_p ;
171 #define INDEX_2(A,B,NB) ( (B) + (A)*(NB) )
172 #define INDEX_3(A,B,NB,C,NC) INDEX_2( (A), INDEX_2( (B), (C), (NC) ), (NB)*(NC) )
174 #ifndef STUBMPI
175 # define RSL_FATAL(N) MPI_Abort(MPI_COMM_WORLD, 9)
176 #else
177 # define RSL_FATAL(N) exit(9) ;
178 #endif
179 #ifndef MS_SUA
180 # define RSL_TEST_ERR(T,M) {if(T){fprintf(stderr,"rsl_lite error (\"%s\":%d) %s\n",__FILE__,__LINE__,M);RSL_FATAL(5);}}
181 #else
182 # define RSL_TEST_ERR(T,M) {if(T){RSL_FATAL(5);}}
183 #endif
185 typedef struct rsl_list {
186 struct rsl_list * next ;
187 void * data ; /* pointer to some node */
188 #ifdef crayx1
189 int info1 ; /* blank info field */
190 int info2 ; /* blank info field */
191 #else
192 short info1 ; /* blank info field */
193 short info2 ; /* blank info field */
194 #endif
195 } rsl_list_t ;