File: bml_base_btl.c

package info (click to toggle)
openmpi 5.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 202,312 kB
  • sloc: ansic: 612,441; makefile: 42,495; sh: 11,230; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,154; python: 1,856; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (140 lines) | stat: -rw-r--r-- 5,000 bytes parent folder | download | duplicates (6)
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
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2007 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-2006 The Regents of the University of California.
 *                         All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "ompi_config.h"

#include <string.h>

#include "ompi/mca/bml/bml.h"
#include "bml_base_btl.h"
#include "opal/util/crc.h"
#if OPAL_ENABLE_DEBUG_RELIABILITY
#include "opal/util/alfg.h"
#endif /* OPAL_ENABLE_DEBUG_RELIABILITY */
static void mca_bml_base_btl_array_construct(mca_bml_base_btl_array_t* array)
{
    array->bml_btls = NULL;
    array->arr_size = 0;
    array->arr_index = 0;
    array->arr_reserve = 0;
}


static void mca_bml_base_btl_array_destruct(mca_bml_base_btl_array_t* array)
{
    if(NULL != array->bml_btls) {
        free(array->bml_btls);
        array->bml_btls = NULL;
    }
    array->arr_size = 0;
    array->arr_index = 0;
    array->arr_reserve = 0;
}

OBJ_CLASS_INSTANCE(
    mca_bml_base_btl_array_t,
    opal_object_t,
    mca_bml_base_btl_array_construct,
    mca_bml_base_btl_array_destruct
);

int mca_bml_base_btl_array_reserve(mca_bml_base_btl_array_t* array, size_t size)
{
    size_t old_len = sizeof(mca_bml_base_btl_t)*array->arr_reserve;
    size_t new_len = sizeof(mca_bml_base_btl_t)*size;
    if(old_len >= new_len)
        return OMPI_SUCCESS;

    array->bml_btls = (mca_bml_base_btl_t*)realloc(array->bml_btls, new_len);
    if(NULL == array->bml_btls)
        return OMPI_ERR_OUT_OF_RESOURCE;
    memset((unsigned char*)array->bml_btls + old_len, 0, new_len-old_len);
    array->arr_reserve = size;
    return OMPI_SUCCESS;
}


#if OPAL_ENABLE_DEBUG_RELIABILITY

extern int mca_bml_base_error_rate_floor;
extern int mca_bml_base_error_rate_ceiling;
extern int  mca_bml_base_error_count;
extern opal_rng_buff_t mca_bml_base_rand_buff;

struct mca_bml_base_context_t {
    size_t index;
    mca_btl_base_completion_fn_t cbfunc;
    void* cbdata;
};
typedef struct mca_bml_base_context_t mca_bml_base_context_t;

static void mca_bml_base_completion(
                                    struct mca_btl_base_module_t* btl,
                                    struct mca_btl_base_endpoint_t* ep,
                                    struct mca_btl_base_descriptor_t* des,
                                    int status)
{
    mca_bml_base_context_t* ctx = (mca_bml_base_context_t*) des->des_cbdata;
    /* restore original state */
    ((unsigned char*)des->des_segments[0].seg_addr.pval)[ctx->index] ^= ~0;
    des->des_cbdata = ctx->cbdata;
    des->des_cbfunc = ctx->cbfunc;
    free(ctx);
    /* invoke original callback */
    des->des_cbfunc(btl,ep,des,status);
}

int mca_bml_base_send( mca_bml_base_btl_t* bml_btl,
                       mca_btl_base_descriptor_t* des,
                       mca_btl_base_tag_t tag )
{
    des->des_context = (void*)bml_btl;
    if(mca_bml_base_error_count <= 0 && mca_bml_base_error_rate_ceiling > 0) {
      mca_bml_base_error_count = (int) (((double) mca_bml_base_error_rate_ceiling *
                  opal_rand(&mca_bml_base_rand_buff))/(UINT32_MAX+1.0));
        if(mca_bml_base_error_count < (double) mca_bml_base_error_rate_floor) {
          mca_bml_base_error_count = (double) mca_bml_base_error_rate_floor;
        }
        if(mca_bml_base_error_count % 2) {
            /* local completion - network "drops" packet */
            opal_output(0, "%s:%d: dropping data, with local completion\n", __FILE__, __LINE__);
            des->des_cbfunc(bml_btl->btl, bml_btl->btl_endpoint, des, OMPI_SUCCESS);
            return OMPI_SUCCESS;
        } else {
            /* corrupt data */
            mca_bml_base_context_t* ctx = (mca_bml_base_context_t*)
                malloc(sizeof(mca_bml_base_context_t));
            if(NULL != ctx) {
                opal_output(0, "%s:%d: corrupting data\n", __FILE__, __LINE__);
                ctx->index = (size_t) ((des->des_segments[0].seg_len *
                            opal_rand(&mca_bml_base_rand_buff) * 1.0) / (UINT32_MAX + 1.0));
                ctx->cbfunc = des->des_cbfunc;
                ctx->cbdata = des->des_cbdata;
                ((unsigned char*)des->des_segments[0].seg_addr.pval)[ctx->index] ^= ~0;
                des->des_cbdata = ctx;
                des->des_cbfunc = mca_bml_base_completion;
            }
        }
    }
    mca_bml_base_error_count--;
    return bml_btl->btl_send( bml_btl->btl,
                              bml_btl->btl_endpoint,
                              des, tag );
}

#endif