Source

mpi3-fortran / opal / dss / dss_internal.h

Full commit
  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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/* -*- C -*-
 *
 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2006 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2012      Los Alamos National Security, Inc.  All rights reserved. 
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 *
 */
#ifndef OPAL_DSS_INTERNAL_H_
#define OPAL_DSS_INTERNAL_H_

#include "opal_config.h"
#include "opal/constants.h"

#include "opal/class/opal_pointer_array.h"

#include "opal/dss/dss.h"

#ifdef HAVE_STRING_H
#    if !defined(STDC_HEADERS) && HAVE_MEMORY_H
#        include <memory.h>
#    endif
#    include <string.h>
#endif

BEGIN_C_DECLS

/*
 * The default starting chunk size
 */
#define OPAL_DSS_DEFAULT_INITIAL_SIZE  128
/*
 * The default threshold size when we switch from doubling the 
 * buffer size to addatively increasing it
 */
#define OPAL_DSS_DEFAULT_THRESHOLD_SIZE 1024

/*
 * Internal type corresponding to size_t.  Do not use this in
 * interface calls - use OPAL_SIZE instead.
 */
#if SIZEOF_SIZE_T == 1
#define DSS_TYPE_SIZE_T OPAL_UINT8
#elif SIZEOF_SIZE_T == 2
#define DSS_TYPE_SIZE_T OPAL_UINT16
#elif SIZEOF_SIZE_T == 4
#define DSS_TYPE_SIZE_T OPAL_UINT32
#elif SIZEOF_SIZE_T == 8
#define DSS_TYPE_SIZE_T OPAL_UINT64
#else
#error Unsupported size_t size!
#endif

/*
 * Internal type corresponding to bool.  Do not use this in interface
 * calls - use OPAL_BOOL instead.
 */
#if SIZEOF_BOOL == 1
#define DSS_TYPE_BOOL OPAL_UINT8
#elif SIZEOF_BOOL == 2
#define DSS_TYPE_BOOL OPAL_UINT16
#elif SIZEOF_BOOL == 4
#define DSS_TYPE_BOOL OPAL_UINT32
#elif SIZEOF_BOOL == 8
#define DSS_TYPE_BOOL OPAL_UINT64
#else
#error Unsupported bool size!
#endif

/*
 * Internal type corresponding to int and unsigned int.  Do not use
 * this in interface calls - use OPAL_INT / OPAL_UINT instead.
 */
#if SIZEOF_INT == 1
#define DSS_TYPE_INT OPAL_INT8
#define DSS_TYPE_UINT OPAL_UINT8
#elif SIZEOF_INT == 2
#define DSS_TYPE_INT OPAL_INT16
#define DSS_TYPE_UINT OPAL_UINT16
#elif SIZEOF_INT == 4
#define DSS_TYPE_INT OPAL_INT32
#define DSS_TYPE_UINT OPAL_UINT32
#elif SIZEOF_INT == 8
#define DSS_TYPE_INT OPAL_INT64
#define DSS_TYPE_UINT OPAL_UINT64
#else
#error Unsupported int size!
#endif

/*
 * Internal type corresponding to pid_t.  Do not use this in interface
 * calls - use OPAL_PID instead.
 */
#if SIZEOF_PID_T == 1
#define DSS_TYPE_PID_T OPAL_UINT8
#elif SIZEOF_PID_T == 2
#define DSS_TYPE_PID_T OPAL_UINT16
#elif SIZEOF_PID_T == 4
#define DSS_TYPE_PID_T OPAL_UINT32
#elif SIZEOF_PID_T == 8
#define DSS_TYPE_PID_T OPAL_UINT64
#else
#error Unsupported pid_t size!
#endif

/* Unpack generic size macros */
#define UNPACK_SIZE_MISMATCH(unpack_type, remote_type, ret)                 \
    do {                                                                    \
        switch(remote_type) {                                               \
        case OPAL_UINT8:                                                    \
            UNPACK_SIZE_MISMATCH_FOUND(unpack_type, uint8_t, remote_type);  \
            break;                                                          \
        case OPAL_INT8:                                                     \
            UNPACK_SIZE_MISMATCH_FOUND(unpack_type, int8_t, remote_type);   \
            break;                                                          \
        case OPAL_UINT16:                                                   \
            UNPACK_SIZE_MISMATCH_FOUND(unpack_type, uint16_t, remote_type); \
            break;                                                          \
        case OPAL_INT16:                                                    \
            UNPACK_SIZE_MISMATCH_FOUND(unpack_type, int16_t, remote_type);  \
            break;                                                          \
        case OPAL_UINT32:                                                   \
            UNPACK_SIZE_MISMATCH_FOUND(unpack_type, uint32_t, remote_type); \
            break;                                                          \
        case OPAL_INT32:                                                    \
            UNPACK_SIZE_MISMATCH_FOUND(unpack_type, int32_t, remote_type);  \
            break;                                                          \
        case OPAL_UINT64:                                                   \
            UNPACK_SIZE_MISMATCH_FOUND(unpack_type, uint64_t, remote_type); \
            break;                                                          \
        case OPAL_INT64:                                                    \
            UNPACK_SIZE_MISMATCH_FOUND(unpack_type, int64_t, remote_type);  \
            break;                                                          \
        default:                                                            \
            ret = OPAL_ERR_NOT_FOUND;                                       \
        }                                                                   \
    } while (0)
        
/* NOTE: do not need to deal with endianness here, as the unpacking of
   the underling sender-side type will do that for us.  Repeat: the
   data in tmpbuf[] is already in host byte order. */
#define UNPACK_SIZE_MISMATCH_FOUND(unpack_type, tmptype, tmpdsstype)        \
    do {                                                                    \
        int32_t i;                                                          \
        tmptype *tmpbuf = (tmptype*)malloc(sizeof(tmptype) * (*num_vals));  \
        ret = opal_dss_unpack_buffer(buffer, tmpbuf, num_vals, tmpdsstype); \
        for (i = 0 ; i < *num_vals ; ++i) {                                 \
            ((unpack_type*) dest)[i] = (unpack_type)(tmpbuf[i]);            \
        }                                                                   \
        free(tmpbuf);                                                       \
    } while (0)
            
            
/**
 * Internal struct used for holding registered dss functions
 */
struct opal_dss_type_info_t {
    opal_object_t super;
    /* type identifier */
    opal_data_type_t odti_type;
    /** Debugging string name */
    char *odti_name;
    /** Pack function */
    opal_dss_pack_fn_t odti_pack_fn;
    /** Unpack function */
    opal_dss_unpack_fn_t odti_unpack_fn;
    /** copy function */
    opal_dss_copy_fn_t odti_copy_fn;
    /** compare function */
    opal_dss_compare_fn_t odti_compare_fn;
    /** print function */
    opal_dss_print_fn_t odti_print_fn;
    /** flag to indicate structured data */
    bool odti_structured;
};
/**
 * Convenience typedef
 */
typedef struct opal_dss_type_info_t opal_dss_type_info_t;
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_dss_type_info_t);

/*
 * globals needed within dss
 */
extern bool opal_dss_initialized;
extern bool opal_dss_debug;
extern int opal_dss_verbose;
extern int opal_dss_initial_size;
extern int opal_dss_threshold_size;
extern opal_pointer_array_t opal_dss_types;
extern opal_data_type_t opal_dss_num_reg_types;

/*
 * Implementations of API functions
 */

int opal_dss_pack(opal_buffer_t *buffer, const void *src,
                  int32_t num_vals,
                  opal_data_type_t type);
int opal_dss_unpack(opal_buffer_t *buffer, void *dest,
                    int32_t *max_num_vals,
                    opal_data_type_t type);

int opal_dss_copy(void **dest, void *src, opal_data_type_t type);

int opal_dss_compare(const void *value1, const void *value2,
                     opal_data_type_t type);

int opal_dss_print(char **output, char *prefix, void *src, opal_data_type_t type);

int opal_dss_dump(int output_stream, void *src, opal_data_type_t type);

int opal_dss_peek(opal_buffer_t *buffer, opal_data_type_t *type,
                  int32_t *number);

int opal_dss_peek_type(opal_buffer_t *buffer, opal_data_type_t *type);

int opal_dss_unload(opal_buffer_t *buffer, void **payload,
                    int32_t *bytes_used);
int opal_dss_load(opal_buffer_t *buffer, void *payload, int32_t bytes_used);

int opal_dss_copy_payload(opal_buffer_t *dest, opal_buffer_t *src);

int opal_dss_register(opal_dss_pack_fn_t pack_fn,
                      opal_dss_unpack_fn_t unpack_fn,
                      opal_dss_copy_fn_t copy_fn,
                      opal_dss_compare_fn_t compare_fn,
                      opal_dss_print_fn_t print_fn,
                      bool structured,
                      const char *name, opal_data_type_t *type);

bool opal_dss_structured(opal_data_type_t type);

char *opal_dss_lookup_data_type(opal_data_type_t type);

void opal_dss_dump_data_types(int output);

/*
 * Specialized functions
 */
OPAL_DECLSPEC    int opal_dss_pack_buffer(opal_buffer_t *buffer, const void *src, 
                                          int32_t num_vals, opal_data_type_t type);

OPAL_DECLSPEC    int opal_dss_unpack_buffer(opal_buffer_t *buffer, void *dst, 
                                            int32_t *num_vals, opal_data_type_t type);

/*
 * Internal pack functions
 */

int opal_dss_pack_null(opal_buffer_t *buffer, const void *src,
                       int32_t num_vals, opal_data_type_t type);
int opal_dss_pack_byte(opal_buffer_t *buffer, const void *src,
                       int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_bool(opal_buffer_t *buffer, const void *src,
                       int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_int(opal_buffer_t *buffer, const void *src,
                      int32_t num_vals, opal_data_type_t type);
int opal_dss_pack_int16(opal_buffer_t *buffer, const void *src,
                        int32_t num_vals, opal_data_type_t type);
int opal_dss_pack_int32(opal_buffer_t *buffer, const void *src,
                        int32_t num_vals, opal_data_type_t type);
int opal_dss_pack_int64(opal_buffer_t *buffer, const void *src,
                        int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_sizet(opal_buffer_t *buffer, const void *src,
                        int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_pid(opal_buffer_t *buffer, const void *src,
                      int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_string(opal_buffer_t *buffer, const void *src,
                         int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_data_type(opal_buffer_t *buffer, const void *src,
                            int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_byte_object(opal_buffer_t *buffer, const void *src,
                              int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_pstat(opal_buffer_t *buffer, const void *src,
                        int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_node_stat(opal_buffer_t *buffer, const void *src,
                            int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_value(opal_buffer_t *buffer, const void *src,
                        int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_buffer_contents(opal_buffer_t *buffer, const void *src,
                                  int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_float(opal_buffer_t *buffer, const void *src,
                        int32_t num_vals, opal_data_type_t type);

int opal_dss_pack_timeval(opal_buffer_t *buffer, const void *src,
                          int32_t num_vals, opal_data_type_t type);

/*
 * Internal unpack functions
 */

int opal_dss_unpack_null(opal_buffer_t *buffer, void *dest,
                         int32_t *num_vals, opal_data_type_t type);
int opal_dss_unpack_byte(opal_buffer_t *buffer, void *dest,
                         int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_bool(opal_buffer_t *buffer, void *dest,
                         int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_int(opal_buffer_t *buffer, void *dest,
                        int32_t *num_vals, opal_data_type_t type);
int opal_dss_unpack_int16(opal_buffer_t *buffer, void *dest,
                          int32_t *num_vals, opal_data_type_t type);
int opal_dss_unpack_int32(opal_buffer_t *buffer, void *dest,
                          int32_t *num_vals, opal_data_type_t type);
int opal_dss_unpack_int64(opal_buffer_t *buffer, void *dest,
                          int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_sizet(opal_buffer_t *buffer, void *dest,
                          int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_pid(opal_buffer_t *buffer, void *dest,
                        int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_string(opal_buffer_t *buffer, void *dest,
                           int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_data_type(opal_buffer_t *buffer, void *dest,
                              int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_byte_object(opal_buffer_t *buffer, void *dest,
                                int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_pstat(opal_buffer_t *buffer, void *dest,
                          int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_node_stat(opal_buffer_t *buffer, void *dest,
                              int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_value(opal_buffer_t *buffer, void *dest,
                          int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_buffer_contents(opal_buffer_t *buffer, void *dest,
                                    int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_float(opal_buffer_t *buffer, void *dest,
                          int32_t *num_vals, opal_data_type_t type);

int opal_dss_unpack_timeval(opal_buffer_t *buffer, void *dest,
                            int32_t *num_vals, opal_data_type_t type);

/*
 * Internal copy functions
 */

int opal_dss_std_copy(void **dest, void *src, opal_data_type_t type);

int opal_dss_copy_null(char **dest, char *src, opal_data_type_t type);

int opal_dss_copy_string(char **dest, char *src, opal_data_type_t type);

int opal_dss_copy_byte_object(opal_byte_object_t **dest, opal_byte_object_t *src,
                              opal_data_type_t type);

int opal_dss_copy_pstat(opal_pstats_t **dest, opal_pstats_t *src,
                        opal_data_type_t type);

int opal_dss_copy_node_stat(opal_node_stats_t **dest, opal_node_stats_t *src,
                            opal_data_type_t type);

int opal_dss_copy_value(opal_value_t **dest, opal_value_t *src,
                        opal_data_type_t type);

int opal_dss_copy_buffer_contents(opal_buffer_t **dest, opal_buffer_t *src,
                                  opal_data_type_t type);

/*
 * Internal compare functions
 */

int opal_dss_compare_bool(bool *value1, bool *value2, opal_data_type_t type);

int opal_dss_compare_int(int *value1, int *value2, opal_data_type_t type);
int opal_dss_compare_uint(unsigned int *value1, unsigned int *value2, opal_data_type_t type);

int opal_dss_compare_size(size_t *value1, size_t *value2, opal_data_type_t type);

int opal_dss_compare_pid(pid_t *value1, pid_t *value2, opal_data_type_t type);

int opal_dss_compare_byte(char *value1, char *value2, opal_data_type_t type);
int opal_dss_compare_char(char *value1, char *value2, opal_data_type_t type);
int opal_dss_compare_int8(int8_t *value1, int8_t *value2, opal_data_type_t type);
int opal_dss_compare_uint8(uint8_t *value1, uint8_t *value2, opal_data_type_t type);

int opal_dss_compare_int16(int16_t *value1, int16_t *value2, opal_data_type_t type);
int opal_dss_compare_uint16(uint16_t *value1, uint16_t *value2, opal_data_type_t type);

int opal_dss_compare_int32(int32_t *value1, int32_t *value2, opal_data_type_t type);
int opal_dss_compare_uint32(uint32_t *value1, uint32_t *value2, opal_data_type_t type);

int opal_dss_compare_int64(int64_t *value1, int64_t *value2, opal_data_type_t type);
int opal_dss_compare_uint64(uint64_t *value1, uint64_t *value2, opal_data_type_t type);

int opal_dss_compare_null(char *value1, char *value2, opal_data_type_t type);

int opal_dss_compare_string(char *value1, char *value2, opal_data_type_t type);

int opal_dss_compare_dt(opal_data_type_t *value1, opal_data_type_t *value2, opal_data_type_t type);

int opal_dss_compare_byte_object(opal_byte_object_t *value1, opal_byte_object_t *value2, opal_data_type_t type);

int opal_dss_compare_pstat(opal_pstats_t *value1, opal_pstats_t *value2, opal_data_type_t type);

int opal_dss_compare_node_stat(opal_node_stats_t *value1, opal_node_stats_t *value2, opal_data_type_t type);

int opal_dss_compare_value(opal_value_t *value1, opal_value_t *value2, opal_data_type_t type);

int opal_dss_compare_buffer_contents(opal_buffer_t *value1, opal_buffer_t *value2, opal_data_type_t type);

int opal_dss_compare_float(float *value1, float *value2, opal_data_type_t type);

int opal_dss_compare_timeval(struct timeval *value1, struct timeval *value2, opal_data_type_t type);

/*
 * Internal print functions
 */
int opal_dss_print_byte(char **output, char *prefix, uint8_t *src, opal_data_type_t type);

int opal_dss_print_string(char **output, char *prefix, char *src, opal_data_type_t type);

int opal_dss_print_size(char **output, char *prefix, size_t *src, opal_data_type_t type);
int opal_dss_print_pid(char **output, char *prefix, pid_t *src, opal_data_type_t type);
int opal_dss_print_bool(char **output, char *prefix, bool *src, opal_data_type_t type);
int opal_dss_print_int(char **output, char *prefix, int *src, opal_data_type_t type);
int opal_dss_print_uint(char **output, char *prefix, int *src, opal_data_type_t type);
int opal_dss_print_uint8(char **output, char *prefix, uint8_t *src, opal_data_type_t type);
int opal_dss_print_uint16(char **output, char *prefix, uint16_t *src, opal_data_type_t type);
int opal_dss_print_uint32(char **output, char *prefix, uint32_t *src, opal_data_type_t type);
int opal_dss_print_int8(char **output, char *prefix, int8_t *src, opal_data_type_t type);
int opal_dss_print_int16(char **output, char *prefix, int16_t *src, opal_data_type_t type);
int opal_dss_print_int32(char **output, char *prefix, int32_t *src, opal_data_type_t type);
#ifdef HAVE_INT64_T
int opal_dss_print_uint64(char **output, char *prefix, uint64_t *src, opal_data_type_t type);
int opal_dss_print_int64(char **output, char *prefix, int64_t *src, opal_data_type_t type);
#else
int opal_dss_print_uint64(char **output, char *prefix, void *src, opal_data_type_t type);
int opal_dss_print_int64(char **output, char *prefix, void *src, opal_data_type_t type);
#endif
int opal_dss_print_null(char **output, char *prefix, void *src, opal_data_type_t type);
int opal_dss_print_data_type(char **output, char *prefix, opal_data_type_t *src, opal_data_type_t type);
int opal_dss_print_byte_object(char **output, char *prefix, opal_byte_object_t *src, opal_data_type_t type);
int opal_dss_print_pstat(char **output, char *prefix, opal_pstats_t *src, opal_data_type_t type);
int opal_dss_print_node_stat(char **output, char *prefix, opal_node_stats_t *src, opal_data_type_t type);
int opal_dss_print_value(char **output, char *prefix, opal_value_t *src, opal_data_type_t type);
int opal_dss_print_buffer_contents(char **output, char *prefix, opal_buffer_t *src, opal_data_type_t type);
int opal_dss_print_float(char **output, char *prefix, float *src, opal_data_type_t type);
int opal_dss_print_timeval(char **output, char *prefix, struct timeval *src, opal_data_type_t type);


/*
 * Internal helper functions
 */

char* opal_dss_buffer_extend(opal_buffer_t *bptr, size_t bytes_to_add);

bool opal_dss_too_small(opal_buffer_t *buffer, size_t bytes_reqd);

opal_dss_type_info_t* opal_dss_find_type(opal_data_type_t type);

int opal_dss_store_data_type(opal_buffer_t *buffer, opal_data_type_t type);

int opal_dss_get_data_type(opal_buffer_t *buffer, opal_data_type_t *type);

END_C_DECLS

#endif