File: OTF2_IdMap.h

package info (click to toggle)
otf2 3.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,000 kB
  • sloc: ansic: 92,997; python: 16,977; cpp: 9,057; sh: 6,299; makefile: 238; awk: 54
file content (287 lines) | stat: -rw-r--r-- 8,452 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
 * This file is part of the Score-P software (http://www.score-p.org)
 *
 * Copyright (c) 2009-2011,
 * RWTH Aachen University, Germany
 *
 * Copyright (c) 2009-2011,
 * Gesellschaft fuer numerische Simulation mbH Braunschweig, Germany
 *
 * Copyright (c) 2009-2011, 2013,
 * Technische Universitaet Dresden, Germany
 *
 * Copyright (c) 2009-2011,
 * University of Oregon, Eugene, USA
 *
 * Copyright (c) 2009-2011,
 * Forschungszentrum Juelich GmbH, Germany
 *
 * Copyright (c) 2009-2011,
 * German Research School for Simulation Sciences GmbH, Juelich/Aachen, Germany
 *
 * Copyright (c) 2009-2011,
 * Technische Universitaet Muenchen, Germany
 *
 * This software may be modified and distributed under the terms of
 * a BSD-style license.  See the COPYING file in the package base
 * directory for details.
 *
 */


#ifndef OTF2_IDMAP_H
#define OTF2_IDMAP_H


/**
 *  @file
 *
 *  @brief Identifier mapping data structure, based on Scalasca's epk_idmap.h
 *
 *  This file provides type definitions and function prototypes for an
 *  identifier mapping data structure which is used to store mapping tables
 *  for converting local into global identifiers.
 *
 *  This mapping data structure can operate in two different modes (see @ref
 *  OTF2_IdMapMode): A dense mapping can be used if the local identifiers
 *  are consecutively enumerated from 0 to N-1. In this case, only the global
 *  identifier are stored in the table at the corresponding entry, leading to
 *  compact storage and fast look-up. By contrast, if the local identifiers
 *  can consist of arbitrary numbers, a sparse mapping is necessary. Here,
 *  (localId, globalId) tuples are stored, which requires a more complicated
 *  look-up procedure.
 */


#include <stddef.h>
#include <stdint.h>
#ifndef __cplusplus
#include <stdbool.h>
#endif


#include <otf2/OTF2_ErrorCodes.h>


/** Opaque data structure representing an ID mapping table. */
typedef struct OTF2_IdMap_struct OTF2_IdMap;


/** Wrapper around enum OTF2_IdMapMode_enum, so that it is guaranteed
 *  that it is a uint8_t */
typedef uint8_t OTF2_IdMapMode;

/**
 * Enumeration type defining the two different modes of an identifier mapping
 * table.
 */
enum OTF2_IdMapMode_enum
{
    OTF2_ID_MAP_DENSE,   /**< Dense mapping table */
    OTF2_ID_MAP_SPARSE   /**< Sparse mapping table */
};


/** @brief Function prototype for use in @a OTF2_IdMap_Traverse.
 */
typedef void
( * OTF2_IdMap_TraverseCallback )( uint64_t localId,
                                   uint64_t globalId,
                                   void*    userData );


#ifdef __cplusplus
extern "C" {
#endif


/**
 *  Creates and returns a new instance of OTF2_IdMap with the given @a mode
 *  and initial @a capacity.  If the memory allocation request cannot be
 *  fulfilled, NULL is returned.
 *
 *  @param mode     Mapping mode.
 *  @param capacity Initial capacity.
 *
 *  @return Pointer to new instance or NULL if memory request couldn't be
 *  fulfilled.
 */
OTF2_IdMap*
OTF2_IdMap_Create( OTF2_IdMapMode mode,
                   uint64_t       capacity );


/**
 *  Creates and returns a new instance of OTF2_IdMap from the array given by
 *  @a mappings.
 *
 *  This creates always a DENSE mapping if @a optimizeSize is false. If it is
 *  true, it creates a SPARSE mapping, if the number of non-identity entries
 *  in the @a mappings array (i.e., mapping[ i ] != i) is less than half the
 *  @a length.
 *
 *  Returns NULL when optimizeSize is true and the number of non-identity
 *  entries equals zero, i.e., the given map is the identity map.
 *
 *  @param length       Number of elements in the @a mappings array.
 *  @param mappings     Array with a dense mapping.
 *  @param optimizeSize Creates a SPARSE mapping, if the number of non-
 *                      identities is less than half the array length.
 *
 *  @return Pointer to new instance or NULL if memory request couldn't be
 *  fulfilled.
 */
OTF2_IdMap*
OTF2_IdMap_CreateFromUint64Array( uint64_t        length,
                                  const uint64_t* mappings,
                                  bool            optimizeSize );


/**
 *  Creates and returns a new instance of OTF2_IdMap from the array given by
 *  @a mappings.
 *
 *  Same as @a OTF2_IdMap_CreateFromUint64Array, except from a uint32_t array.
 *
 *  @param length       Number of elements in the @a mappings array.
 *  @param mappings     Array with a dense mapping.
 *  @param optimizeSize Creates a SPARSE mapping, if the number of non-
 *                      identities is less than half the array length.
 *
 *  @return Pointer to new instance or NULL if memory request couldn't be
 *  fulfilled.
 */
OTF2_IdMap*
OTF2_IdMap_CreateFromUint32Array( uint64_t        length,
                                  const uint32_t* mappings,
                                  bool            optimizeSize );


/**
 *  Destroys the given @a instance of OTF2_IdMap and releases the allocated
 *  memory.
 *
 *  @param instance Object to be freed
 */
void
OTF2_IdMap_Free( OTF2_IdMap* instance );


/**
 *  Returns the actual number of entries stored in the given OTF2_IdMap
 *  @a instance.
 *
 *  @param instance  Queried object.
 *  @param[out] size Number of entries.
 *
 *  @return OTF2_SUCCESS, or error code.
 */
OTF2_ErrorCode
OTF2_IdMap_GetSize( const OTF2_IdMap* instance,
                    uint64_t*         size );


/**
 *  Returns the identifier mapping mode (dense/sparse) used for the given
 *  mapping table @a instance.
 *
 *  @param instance Queried object.
 *  @param[out] mode Identifier mapping mode.
 *
 *  @return OTF2_SUCCESS, or error code.
 */
OTF2_ErrorCode
OTF2_IdMap_GetMode( const OTF2_IdMap* instance,
                    OTF2_IdMapMode*   mode );


/**
 *  Removes all entries in the given mapping table @a instance. It can be
 *  used, e.g., to reuse a mapping table object for new input data.
 *
 *  @param instance Object to remove entries from.
 *
 *  @return OTF2_SUCCESS, or error code.
 */
OTF2_ErrorCode
OTF2_IdMap_Clear( OTF2_IdMap* instance );


/**
 *  Adds the given mapping from @a localId to @a globalId to the mapping
 *  table @a instance. If the current capacity does not suffice, the data
 *  structure is automatically resized.
 *
 *  @note If the mapping table operates in dense mapping mode, the parameter
 *        @a localId has to correspond to the next entry in the mapping table.
 *
 *  @param instance Object to add the mapping to.
 *  @param localId  Local identifier.
 *  @param globalId Global identifier.
 *
 *  @return OTF2_SUCCESS, or error code.
 */
OTF2_ErrorCode
OTF2_IdMap_AddIdPair( OTF2_IdMap* instance,
                      uint64_t    localId,
                      uint64_t    globalId );


/**
 *  Maps the given @a localId to the global id and store it in the storage
 *  provide by @a globalId.
 *
 *  If the given @a localId is not in the mapping, sets globalId to the localId.
 *
 *  @param instance      Object to add the mapping to.
 *  @param localId       Local identifier.
 *  @param[out] globalId Global identifier.
 *
 *  @return OTF2_SUCCESS, or error code.
 */
OTF2_ErrorCode
OTF2_IdMap_GetGlobalId( const OTF2_IdMap* instance,
                        uint64_t          localId,
                        uint64_t*         globalId );


/**
 *  Maps the given @a localId to the global id and store it in the storage
 *  provide by @a globalId.
 *
 *  If the given @a localId is not in the mapping, returns
 *  @eref{OTF2_ERROR_INDEX_OUT_OF_BOUNDS}.
 *
 *  @param instance      Object to add the mapping to.
 *  @param localId       Local identifier.
 *  @param[out] globalId Global identifier.
 *
 *  @return OTF2_SUCCESS, or error code.
 */
OTF2_ErrorCode
OTF2_IdMap_GetGlobalIdSave( const OTF2_IdMap* instance,
                            uint64_t          localId,
                            uint64_t*         globalId );


/**
 *  Calls for each mapping pair the callback @a callback.
 *
 *  @param instance Object to add the mapping to.
 *  @param callback Callback function which is called for each mapping pair.
 *  @param userData Data which is passed to the @a callback function.
 *
 *  @return OTF2_SUCCESS, or error code.
 */
OTF2_ErrorCode
OTF2_IdMap_Traverse( const OTF2_IdMap*           instance,
                     OTF2_IdMap_TraverseCallback callback,
                     void*                       userData );


#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* OTF2_IDMAP_H */