OpenMPI 0.1.1

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

- File List
- Globals

types.h
1 /*
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * $COPYRIGHT$
13 *
14 * Additional copyrights may follow
15 *
16 * $HEADER$
17 */
18
19 #ifndef OPAL_TYPES_H
20 #define OPAL_TYPES_H
21
22 #include "opal_config.h"
23
24 #ifdef HAVE_STDINT_H
25 #include <stdint.h>
26 #endif
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
29 #endif
30 #ifdef HAVE_SYS_SOCKET_H
31 #include <sys/socket.h>
32 #endif
33 #ifdef HAVE_SYS_SELECT_H
34 #include <sys/select.h>
35 #endif
36 #ifdef HAVE_NETINET_IN_H
37 #include <netinet/in.h>
38 #endif
39 #ifdef HAVE_ARPA_INET_H
40 #include <arpa/inet.h>
41 #endif
42
43 #if OPAL_ENABLE_DEBUG
44 #include "opal/util/output.h"
45 #endif
46
47
48 /*
49 * portable assignment of pointer to int
50 */
51
52 typedef union {
53 uint64_t lval;
54 uint32_t ival;
55 void* pval;
56 struct {
57 uint32_t uval;
58 uint32_t lval;
59 } sval;
60 } ompi_ptr_t;
61
62 /*
63 * handle differences in iovec
64 */
65
66 #if defined(__APPLE__) || defined(__WINDOWS__)
67 typedef char* ompi_iov_base_ptr_t;
68 #else
69 typedef void* ompi_iov_base_ptr_t;
70 #endif
71
72 /*
73 * handle differences in socklen_t
74 */
75
76 #if defined(HAVE_SOCKLEN_T)
77 typedef socklen_t opal_socklen_t;
78 #else
79 typedef int opal_socklen_t;
80 #endif
81
82
83 /*
84 * Convert a 64 bit value to network byte order.
85 */
86 static inline uint64_t hton64(uint64_t val) __opal_attribute_const__;
87 static inline uint64_t hton64(uint64_t val)
88 {
89 #ifdef HAVE_UNIX_BYTESWAP
90 union { uint64_t ll;
91 uint32_t l[2];
92 } w, r;
93
94 /* platform already in network byte order? */
95 if(htonl(1) == 1L)
96 return val;
97 w.ll = val;
98 r.l[0] = htonl(w.l[1]);
99 r.l[1] = htonl(w.l[0]);
100 return r.ll;
101 #else
102 return val;
103 #endif
104 }
105
106 /*
107 * Convert a 64 bit value from network to host byte order.
108 */
109
110 static inline uint64_t ntoh64(uint64_t val) __opal_attribute_const__;
111 static inline uint64_t ntoh64(uint64_t val)
112 {
113 #ifdef HAVE_UNIX_BYTESWAP
114 union { uint64_t ll;
115 uint32_t l[2];
116 } w, r;
117
118 /* platform already in network byte order? */
119 if(htonl(1) == 1L)
120 return val;
121 w.ll = val;
122 r.l[0] = ntohl(w.l[1]);
123 r.l[1] = ntohl(w.l[0]);
124 return r.ll;
125 #else
126 return val;
127 #endif
128 }
129
130
131 /**
132 * Convert between a local representation of pointer and a 64 bits value.
133 */
134 static inline uint64_t ompi_ptr_ptol( void* ptr ) __opal_attribute_const__;
135 static inline uint64_t ompi_ptr_ptol( void* ptr )
136 {
137 return (uint64_t)(uintptr_t) ptr;
138 }
139
140 static inline void* ompi_ptr_ltop( uint64_t value ) __opal_attribute_const__;
141 static inline void* ompi_ptr_ltop( uint64_t value )
142 {
143 #if SIZEOF_VOID_P == 4 && OPAL_ENABLE_DEBUG
144 if (value > ((1ULL << 32) - 1ULL)) {
145 opal_output(0, "Warning: truncating value in ompi_ptr_ltop");
146 }
147 #endif
148 return (void*)(uintptr_t) value;
149 }
150
151 #if defined(WORDS_BIGENDIAN) || !defined(HAVE_UNIX_BYTESWAP)
152 static inline uint16_t opal_swap_bytes2(uint16_t val) __opal_attribute_const__;
153 static inline uint16_t opal_swap_bytes2(uint16_t val)
154 {
155 union { uint16_t bigval;
156 uint8_t arrayval[2];
157 } w, r;
158
159 w.bigval = val;
160 r.arrayval[0] = w.arrayval[1];
161 r.arrayval[1] = w.arrayval[0];
162
163 return r.bigval;
164 }
165
166 static inline uint32_t opal_swap_bytes4(uint32_t val) __opal_attribute_const__;
167 static inline uint32_t opal_swap_bytes4(uint32_t val)
168 {
169 union { uint32_t bigval;
170 uint8_t arrayval[4];
171 } w, r;
172
173 w.bigval = val;
174 r.arrayval[0] = w.arrayval[3];
175 r.arrayval[1] = w.arrayval[2];
176 r.arrayval[2] = w.arrayval[1];
177 r.arrayval[3] = w.arrayval[0];
178
179 return r.bigval;
180 }
181
182 static inline uint64_t opal_swap_bytes8(uint64_t val) __opal_attribute_const__;
183 static inline uint64_t opal_swap_bytes8(uint64_t val)
184 {
185 union { uint64_t bigval;
186 uint8_t arrayval[8];
187 } w, r;
188
189 w.bigval = val;
190 r.arrayval[0] = w.arrayval[7];
191 r.arrayval[1] = w.arrayval[6];
192 r.arrayval[2] = w.arrayval[5];
193 r.arrayval[3] = w.arrayval[4];
194 r.arrayval[4] = w.arrayval[3];
195 r.arrayval[5] = w.arrayval[2];
196 r.arrayval[6] = w.arrayval[1];
197 r.arrayval[7] = w.arrayval[0];
198
199 return r.bigval;
200 }
201
202 #else
203 #define opal_swap_bytes2 htons
204 #define opal_swap_bytes4 htonl
205 #define opal_swap_bytes8 hton64
206 #endif /* WORDS_BIGENDIAN || !HAVE_UNIX_BYTESWAP */
207
208 #endif /* OPAL_TYPES_H */
output.h
OPAL output stream facility.
ompi_ptr_t
Definition: types.h:52
opal_output
OPAL_DECLSPEC void opal_output(int output_id, const char *format,...) __opal_attribute_format__(__printf__
Main function to send output to a stream.