OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

opal_datatype.h
1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
3 * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2010 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2006 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2007 Los Alamos National Security, LLC. All rights
14 * reserved.
15 * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
16 * Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
17 * $COPYRIGHT$
18 *
19 * Additional copyrights may follow
20 *
21 * $HEADER$
22 */
23
24 /**
25 * opal_datatype_t interface for OPAL internal data type representation
26 *
27 * opal_datatype_t is a class which represents contiguous or
28 * non-contiguous data together with constituent type-related
29 * information.
30 */
31
32 #ifndef OPAL_DATATYPE_H_HAS_BEEN_INCLUDED
33 #define OPAL_DATATYPE_H_HAS_BEEN_INCLUDED
34
35 #include "opal_config.h"
36
37 #include <stddef.h>
38 #ifdef HAVE_STDINT_H
39 #include <stdint.h>
40 #endif
41
42 #include "opal/class/opal_object.h"
43
44 BEGIN_C_DECLS
45
46 /*
47 * If there are more basic datatypes than the number of bytes in the int type
48 * the bdt_used field of the data description struct should be changed to long.
49 *
50 * This must match the same definition as in opal_datatype_internal.h
51 */
52 #define OPAL_DATATYPE_MAX_PREDEFINED 25
53 /*
54 * No more than this number of _Basic_ datatypes in C/CPP or Fortran
55 * are supported (in order to not change setup and usage of btypes).
56 *
57 * XXX TODO Adapt to whatever the OMPI-layer needs
58 */
59 #define OPAL_DATATYPE_MAX_SUPPORTED 46
60
61
62 /* flags for the datatypes. */
63 #define OPAL_DATATYPE_FLAG_UNAVAILABLE 0x0001 /**< datatypes unavailable on the build (OS or compiler dependant) */
64 #define OPAL_DATATYPE_FLAG_PREDEFINED 0x0002 /**< cannot be removed: initial and predefined datatypes */
65 #define OPAL_DATATYPE_FLAG_COMMITED 0x0004 /**< ready to be used for a send/recv operation */
66 #define OPAL_DATATYPE_FLAG_OVERLAP 0x0008 /**< datatype is unpropper for a recv operation */
67 #define OPAL_DATATYPE_FLAG_CONTIGUOUS 0x0010 /**< contiguous datatype */
68 #define OPAL_DATATYPE_FLAG_NO_GAPS 0x0020 /**< no gaps around the datatype, aka OPAL_DATATYPE_FLAG_CONTIGUOUS and extent == size */
69 #define OPAL_DATATYPE_FLAG_USER_LB 0x0040 /**< has a user defined LB */
70 #define OPAL_DATATYPE_FLAG_USER_UB 0x0080 /**< has a user defined UB */
71 #define OPAL_DATATYPE_FLAG_DATA 0x0100 /**< data or control structure */
72 /*
73 * We should make the difference here between the predefined contiguous and non contiguous
74 * datatypes. The OPAL_DATATYPE_FLAG_BASIC is held by all predefined contiguous datatypes.
75 */
76 #define OPAL_DATATYPE_FLAG_BASIC (OPAL_DATATYPE_FLAG_PREDEFINED | \
77 OPAL_DATATYPE_FLAG_CONTIGUOUS | \
78 OPAL_DATATYPE_FLAG_NO_GAPS | \
79 OPAL_DATATYPE_FLAG_DATA | \
80 OPAL_DATATYPE_FLAG_COMMITED)
81
82
83 /**
84 * The number of supported entries in the data-type definition and the
85 * associated type.
86 */
87 #define MAX_DT_COMPONENT_COUNT UINT_MAX
88 typedef uint32_t opal_datatype_count_t;
89
90 typedef union dt_elem_desc dt_elem_desc_t;
91
92 struct dt_type_desc_t {
93 opal_datatype_count_t length; /**< the maximum number of elements in the description array */
94 opal_datatype_count_t used; /**< the number of used elements in the description array */
95 dt_elem_desc_t* desc;
96 };
97 typedef struct dt_type_desc_t dt_type_desc_t;
98
99
100 /*
101 * The datatype description.
102 */
103 struct opal_datatype_t {
104 opal_object_t super; /**< basic superclass */
105 uint16_t flags; /**< the flags */
106 uint16_t id; /**< data id, normally the index in the data array. */
107 uint32_t bdt_used; /**< bitset of which basic datatypes are used in the data description */
108 size_t size; /**< total size in bytes of the memory used by the data if
109 the data is put on a contiguous buffer */
110 OPAL_PTRDIFF_TYPE true_lb; /**< the true lb of the data without user defined lb and ub */
111 OPAL_PTRDIFF_TYPE true_ub; /**< the true ub of the data without user defined lb and ub */
112 OPAL_PTRDIFF_TYPE lb; /**< lower bound in memory */
113 OPAL_PTRDIFF_TYPE ub; /**< upper bound in memory */
114 /* --- cacheline 1 boundary (64 bytes) --- */
115 uint32_t align; /**< data should be aligned to */
116 uint32_t nbElems; /**< total number of elements inside the datatype */
117
118 /* Attribute fields */
119 char name[OPAL_MAX_OBJECT_NAME]; /**< name of the datatype */
120 /* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */
121 dt_type_desc_t desc; /**< the data description */
122 dt_type_desc_t opt_desc; /**< short description of the data used when conversion is useless
123 or in the send case (without conversion) */
124
125 uint32_t btypes[OPAL_DATATYPE_MAX_SUPPORTED];
126 /**< basic elements count used to compute the size of the
127 datatype for remote nodes. The length of the array is dependent on
128 the maximum number of datatypes of all top layers.
129 Reason being is that Fortran is not at the OPAL layer. */
130 /* --- cacheline 5 boundary (320 bytes) was 32 bytes ago --- */
131
132 /* size: 352, cachelines: 6, members: 15 */
133 /* last cacheline: 32 bytes */
134 };
135
136 typedef struct opal_datatype_t opal_datatype_t;
137
138 OPAL_DECLSPEC OBJ_CLASS_DECLARATION( opal_datatype_t );
139
140 OPAL_DECLSPEC extern const opal_datatype_t* opal_datatype_basicDatatypes[OPAL_DATATYPE_MAX_PREDEFINED];
141 OPAL_DECLSPEC extern const size_t opal_datatype_local_sizes[OPAL_DATATYPE_MAX_PREDEFINED];
142
143 /* Local Architecture as provided by opal_arch_compute_local_id() */
144 OPAL_DECLSPEC extern uint32_t opal_local_arch;
145
146 /*
147 * The OPAL-layer's Basic datatypes themselves.
148 */
149 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_empty;
150 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_loop;
151 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_end_loop;
152 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_lb;
153 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_ub;
154 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int1; /* in bytes */
155 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int2; /* in bytes */
156 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int4; /* in bytes */
157 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int8; /* in bytes */
158 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int16; /* in bytes */
159 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint1; /* in bytes */
160 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint2; /* in bytes */
161 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint4; /* in bytes */
162 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint8; /* in bytes */
163 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint16; /* in bytes */
164 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float2; /* in bytes */
165 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float4; /* in bytes */
166 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float8; /* in bytes */
167 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float12; /* in bytes */
168 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float16; /* in bytes */
169 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_complex8; /* in bytes */
170 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_complex16; /* in bytes */
171 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_complex32; /* in bytes */
172 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_bool;
173 OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_wchar;
174
175
176 /*
177 * Functions exported externally
178 */
179 int opal_datatype_register_params(void);
180 OPAL_DECLSPEC int32_t opal_datatype_init( void );
181 OPAL_DECLSPEC int32_t opal_datatype_finalize( void );
182 OPAL_DECLSPEC opal_datatype_t* opal_datatype_create( int32_t expectedSize );
183 OPAL_DECLSPEC int32_t opal_datatype_create_desc( opal_datatype_t * datatype, int32_t expectedSize );
184 OPAL_DECLSPEC int32_t opal_datatype_commit( opal_datatype_t * pData );
185 OPAL_DECLSPEC int32_t opal_datatype_destroy( opal_datatype_t** );
186
187 static inline int32_t
188 opal_datatype_is_committed( const opal_datatype_t* type )
189 {
190 return ((type->flags & OPAL_DATATYPE_FLAG_COMMITED) == OPAL_DATATYPE_FLAG_COMMITED);
191 }
192
193 static inline int32_t
194 opal_datatype_is_overlapped( const opal_datatype_t* type )
195 {
196 return ((type->flags & OPAL_DATATYPE_FLAG_OVERLAP) == OPAL_DATATYPE_FLAG_OVERLAP);
197 }
198
199 static inline int32_t
200 opal_datatype_is_valid( const opal_datatype_t* type )
201 {
202 return !((type->flags & OPAL_DATATYPE_FLAG_UNAVAILABLE) == OPAL_DATATYPE_FLAG_UNAVAILABLE);
203 }
204
205 static inline int32_t
206 opal_datatype_is_predefined( const opal_datatype_t* type )
207 {
208 return (type->flags & OPAL_DATATYPE_FLAG_PREDEFINED);
209 }
210
211 /*
212 * This function return true (1) if the datatype representation depending on the count
213 * is contiguous in the memory. And false (0) otherwise.
214 */
215 static inline int32_t
216 opal_datatype_is_contiguous_memory_layout( const opal_datatype_t* datatype, int32_t count )
217 {
218 if( !(datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) ) return 0;
219 if( (count == 1) || (datatype->flags & OPAL_DATATYPE_FLAG_NO_GAPS) ) return 1;
220 assert( (OPAL_PTRDIFF_TYPE)datatype->size != (datatype->ub - datatype->lb) );
221 return 0;
222 }
223
224
225 OPAL_DECLSPEC void opal_datatype_dump( const opal_datatype_t* pData );
226 /* data creation functions */
227 OPAL_DECLSPEC int32_t opal_datatype_clone( const opal_datatype_t * src_type, opal_datatype_t * dest_type );
228 OPAL_DECLSPEC int32_t opal_datatype_create_contiguous( int count, const opal_datatype_t* oldType, opal_datatype_t** newType );
229 OPAL_DECLSPEC int32_t opal_datatype_resize( opal_datatype_t* type, OPAL_PTRDIFF_TYPE lb, OPAL_PTRDIFF_TYPE extent );
230 OPAL_DECLSPEC int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtAdd, uint32_t count,
231 OPAL_PTRDIFF_TYPE disp, OPAL_PTRDIFF_TYPE extent );
232
233 static inline int32_t
234 opal_datatype_type_lb( const opal_datatype_t* pData, OPAL_PTRDIFF_TYPE* disp )
235 {
236 *disp = pData->lb;
237 return 0;
238 }
239
240 static inline int32_t
241 opal_datatype_type_ub( const opal_datatype_t* pData, OPAL_PTRDIFF_TYPE* disp )
242 {
243 *disp = pData->ub;
244 return 0;
245 }
246
247 static inline int32_t
248 opal_datatype_type_size( const opal_datatype_t* pData, size_t *size )
249 {
250 *size = pData->size;
251 return 0;
252 }
253
254 static inline int32_t
255 opal_datatype_type_extent( const opal_datatype_t* pData, OPAL_PTRDIFF_TYPE* extent )
256 {
257 *extent = pData->ub - pData->lb;
258 return 0;
259 }
260
261 static inline int32_t
262 opal_datatype_get_extent( const opal_datatype_t* pData, OPAL_PTRDIFF_TYPE* lb, OPAL_PTRDIFF_TYPE* extent)
263 {
264 *lb = pData->lb; *extent = pData->ub - pData->lb;
265 return 0;
266 }
267
268 static inline int32_t
269 opal_datatype_get_true_extent( const opal_datatype_t* pData, OPAL_PTRDIFF_TYPE* true_lb, OPAL_PTRDIFF_TYPE* true_extent)
270 {
271 *true_lb = pData->true_lb;
272 *true_extent = (pData->true_ub - pData->true_lb);
273 return 0;
274 }
275
276 OPAL_DECLSPEC int32_t
277 opal_datatype_get_element_count( const opal_datatype_t* pData, size_t iSize );
278 OPAL_DECLSPEC int32_t
279 opal_datatype_set_element_count( const opal_datatype_t* pData, uint32_t count, size_t* length );
280 OPAL_DECLSPEC int32_t
281 opal_datatype_copy_content_same_ddt( const opal_datatype_t* pData, int32_t count,
282 char* pDestBuf, char* pSrcBuf );
283
284 OPAL_DECLSPEC const opal_datatype_t*
285 opal_datatype_match_size( int size, uint16_t datakind, uint16_t datalang );
286
287 /*
288 *
289 */
290 OPAL_DECLSPEC int32_t
291 opal_datatype_sndrcv( void *sbuf, int32_t scount, const opal_datatype_t* sdtype, void *rbuf,
292 int32_t rcount, const opal_datatype_t* rdtype);
293
294 /*
295 *
296 */
297 OPAL_DECLSPEC int32_t
298 opal_datatype_get_args( const opal_datatype_t* pData, int32_t which,
299 int32_t * ci, int32_t * i,
300 int32_t * ca, OPAL_PTRDIFF_TYPE* a,
301 int32_t * cd, opal_datatype_t** d, int32_t * type);
302 OPAL_DECLSPEC int32_t
303 opal_datatype_set_args( opal_datatype_t* pData,
304 int32_t ci, int32_t ** i,
305 int32_t ca, OPAL_PTRDIFF_TYPE* a,
306 int32_t cd, opal_datatype_t** d,int32_t type);
307 OPAL_DECLSPEC int32_t
308 opal_datatype_copy_args( const opal_datatype_t* source_data,
309 opal_datatype_t* dest_data );
310 OPAL_DECLSPEC int32_t
311 opal_datatype_release_args( opal_datatype_t* pData );
312
313 /*
314 *
315 */
316 OPAL_DECLSPEC size_t
317 opal_datatype_pack_description_length( const opal_datatype_t* datatype );
318
319 /*
320 *
321 */
322 OPAL_DECLSPEC int
323 opal_datatype_get_pack_description( opal_datatype_t* datatype,
324 const void** packed_buffer );
325
326 /*
327 *
328 */
329 struct opal_proc_t;
330 OPAL_DECLSPEC opal_datatype_t*
331 opal_datatype_create_from_packed_description( void** packed_buffer,
332 struct opal_proc_t* remote_processor );
333
334 #if OPAL_ENABLE_DEBUG
335 /*
336 * Set a breakpoint to this function in your favorite debugger
337 * to make it stop on all pack and unpack errors.
338 */
339 OPAL_DECLSPEC int
340 opal_datatype_safeguard_pointer_debug_breakpoint( const void* actual_ptr, int length,
341 const void* initial_ptr,
342 const opal_datatype_t* pData,
343 int count );
344 #endif /* OPAL_ENABLE_DEBUG */
345
346 END_C_DECLS
347 #endif /* OPAL_DATATYPE_H_HAS_BEEN_INCLUDED */
opal_datatype_t::flags
uint16_t flags
the flags
Definition: opal_datatype.h:105
opal_datatype_t::id
uint16_t id
data id, normally the index in the data array.
Definition: opal_datatype.h:106
opal_datatype_t::super
opal_object_t super
basic superclass
Definition: opal_datatype.h:104
dt_elem_desc
Definition: opal_datatype_internal.h:184
opal_datatype_t::bdt_used
uint32_t bdt_used
bitset of which basic datatypes are used in the data description
Definition: opal_datatype.h:107
dt_type_desc_t
Definition: opal_datatype.h:92
dt_type_desc_t::length
opal_datatype_count_t length
the maximum number of elements in the description array
Definition: opal_datatype.h:93
opal_datatype_t::desc
dt_type_desc_t desc
the data description
Definition: opal_datatype.h:121
opal_datatype_t::lb
OPAL_PTRDIFF_TYPE lb
lower bound in memory
Definition: opal_datatype.h:112
opal_datatype_t::ub
OPAL_PTRDIFF_TYPE ub
upper bound in memory
Definition: opal_datatype.h:113
opal_datatype_t::align
uint32_t align
data should be aligned to
Definition: opal_datatype.h:115
opal_datatype_t::size
size_t size
total size in bytes of the memory used by the data if the data is put on a contiguous buffer ...
Definition: opal_datatype.h:108
opal_datatype_t
Definition: opal_datatype.h:103
opal_object_t
Base object.
Definition: opal_object.h:182
dt_type_desc_t::used
opal_datatype_count_t used
the number of used elements in the description array
Definition: opal_datatype.h:94
opal_datatype_t::btypes
uint32_t btypes[OPAL_DATATYPE_MAX_SUPPORTED]
basic elements count used to compute the size of the datatype for remote nodes.
Definition: opal_datatype.h:125
opal_datatype_t::true_ub
OPAL_PTRDIFF_TYPE true_ub
the true ub of the data without user defined lb and ub
Definition: opal_datatype.h:111
opal_datatype_t::opt_desc
dt_type_desc_t opt_desc
short description of the data used when conversion is useless or in the send case (without conversion...
Definition: opal_datatype.h:122
opal_object.h
A simple C-language object-oriented system with single inheritance and ownership-based memory managem...
opal_datatype_t::nbElems
uint32_t nbElems
total number of elements inside the datatype
Definition: opal_datatype.h:116
opal_datatype_t::true_lb
OPAL_PTRDIFF_TYPE true_lb
the true lb of the data without user defined lb and ub
Definition: opal_datatype.h:110
OBJ_CLASS_DECLARATION
#define OBJ_CLASS_DECLARATION(NAME)
Declaration for class descriptor.
Definition: opal_object.h:236
opal_datatype_t::name
char name[OPAL_MAX_OBJECT_NAME]
name of the datatype
Definition: opal_datatype.h:119