File: btl_mvapi_proc.c

package info (click to toggle)
openmpi 1.1-2.3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 39,124 kB
  • ctags: 22,534
  • sloc: ansic: 216,698; sh: 22,541; makefile: 6,921; cpp: 5,562; asm: 3,160; lex: 375; objc: 365; perl: 347; csh: 89; tcl: 12; f90: 5
file content (192 lines) | stat: -rw-r--r-- 5,994 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2005 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$
 * 
 * Additional copyrights may follow
 * 
 * $HEADER$
 */

#include "ompi_config.h"

#include "opal/class/opal_hash_table.h"
#include "ompi/mca/pml/base/pml_base_module_exchange.h"

#include "btl_mvapi.h"
#include "btl_mvapi_proc.h"

static void mca_btl_mvapi_proc_construct(mca_btl_mvapi_proc_t* proc);
static void mca_btl_mvapi_proc_destruct(mca_btl_mvapi_proc_t* proc);

OBJ_CLASS_INSTANCE(mca_btl_mvapi_proc_t, 
        opal_list_item_t, mca_btl_mvapi_proc_construct, 
        mca_btl_mvapi_proc_destruct);

void mca_btl_mvapi_proc_construct(mca_btl_mvapi_proc_t* proc)
{
    proc->proc_ompi = 0;
    proc->proc_port_count = 0;
    proc->proc_endpoints = 0;
    proc->proc_endpoint_count = 0;
    OBJ_CONSTRUCT(&proc->proc_lock, opal_mutex_t);
    /* add to list of all proc instance */
    OPAL_THREAD_LOCK(&mca_btl_mvapi_component.ib_lock);
    opal_list_append(&mca_btl_mvapi_component.ib_procs, &proc->super);
    OPAL_THREAD_UNLOCK(&mca_btl_mvapi_component.ib_lock);
}

/*
 * Cleanup ib proc instance
 */

void mca_btl_mvapi_proc_destruct(mca_btl_mvapi_proc_t* proc)
{
    /* remove from list of all proc instances */
    OPAL_THREAD_LOCK(&mca_btl_mvapi_component.ib_lock);
    opal_list_remove_item(&mca_btl_mvapi_component.ib_procs, &proc->super);
    OPAL_THREAD_UNLOCK(&mca_btl_mvapi_component.ib_lock);

    /* release resources */
    if(NULL != proc->proc_endpoints) {
        free(proc->proc_endpoints);
    }
}


/*
 * Look for an existing IB process instances based on the associated
 * ompi_proc_t instance.
 */
static mca_btl_mvapi_proc_t* mca_btl_mvapi_proc_lookup_ompi(ompi_proc_t* ompi_proc)
{
    mca_btl_mvapi_proc_t* ib_proc;

    OPAL_THREAD_LOCK(&mca_btl_mvapi_component.ib_lock);

    for(ib_proc = (mca_btl_mvapi_proc_t*)
            opal_list_get_first(&mca_btl_mvapi_component.ib_procs);
            ib_proc != (mca_btl_mvapi_proc_t*)
            opal_list_get_end(&mca_btl_mvapi_component.ib_procs);
            ib_proc  = (mca_btl_mvapi_proc_t*)opal_list_get_next(ib_proc)) {

        if(ib_proc->proc_ompi == ompi_proc) {
            OPAL_THREAD_UNLOCK(&mca_btl_mvapi_component.ib_lock);
            return ib_proc;
        }

    }

    OPAL_THREAD_UNLOCK(&mca_btl_mvapi_component.ib_lock);

    return NULL;
}

/*
 * Create a IB process structure. There is a one-to-one correspondence
 * between a ompi_proc_t and a mca_btl_mvapi_proc_t instance. We cache
 * additional data (specifically the list of mca_btl_mvapi_endpoint_t instances, 
 * and published addresses) associated w/ a given destination on this
 * datastructure.
 */

mca_btl_mvapi_proc_t* mca_btl_mvapi_proc_create(ompi_proc_t* ompi_proc)
{
    mca_btl_mvapi_proc_t* mvapi_proc = NULL;
    size_t size; 
    int rc; 

    
    /* Check if we have already created a IB proc
     * structure for this ompi process */
    mvapi_proc = mca_btl_mvapi_proc_lookup_ompi(ompi_proc);

    if(mvapi_proc != NULL) {

        /* Gotcha! */
        return mvapi_proc;
    }

    /* Oops! First time, gotta create a new IB proc
     * out of the ompi_proc ... */

    mvapi_proc = OBJ_NEW(mca_btl_mvapi_proc_t);

    /* Initialize number of peer */
    mvapi_proc->proc_endpoint_count = 0;

    mvapi_proc->proc_ompi = ompi_proc;

    /* build a unique identifier (of arbitrary
     * size) to represent the proc */
    mvapi_proc->proc_guid = ompi_proc->proc_name;

    /* query for the peer address info */ 
    rc = mca_pml_base_modex_recv(
                                 &mca_btl_mvapi_component.super.btl_version, 
                                 ompi_proc, 
                                 (void*)&mvapi_proc->proc_ports, 
                                 &size
                                 ); 
    
    

    if(OMPI_SUCCESS != rc) {
        opal_output(0, "[%s:%d] mca_pml_base_modex_recv failed for peer [%d,%d,%d]",
            __FILE__,__LINE__,ORTE_NAME_ARGS(&ompi_proc->proc_name));
        OBJ_RELEASE(mvapi_proc);
        return NULL;
    }

    if((size % sizeof(mca_btl_mvapi_port_info_t)) != 0) {
        opal_output(0, "[%s:%d] invalid mvapi address for peer [%d,%d,%d]",
            __FILE__,__LINE__,ORTE_NAME_ARGS(&ompi_proc->proc_name));
        OBJ_RELEASE(mvapi_proc);
        return NULL;
    }


    mvapi_proc->proc_port_count = size/sizeof(mca_btl_mvapi_port_info_t);
    
    
    if (0 == mvapi_proc->proc_port_count) {
        mvapi_proc->proc_endpoints = NULL;
    } else {
        mvapi_proc->proc_endpoints = (mca_btl_base_endpoint_t**)
            malloc(mvapi_proc->proc_port_count * sizeof(mca_btl_base_endpoint_t*));
    }

    if(NULL == mvapi_proc->proc_endpoints) {
        OBJ_RELEASE(mvapi_proc);
        return NULL;
    }
    return mvapi_proc;
}


/*
 * Note that this routine must be called with the lock on the process
 * already held.  Insert a btl instance into the proc array and assign 
 * it an address.
 */
int mca_btl_mvapi_proc_insert(mca_btl_mvapi_proc_t* mvapi_proc, 
                              mca_btl_base_endpoint_t* mvapi_endpoint)
{
        
    /* insert into endpoint array */
    if(mvapi_proc->proc_port_count <= mvapi_proc->proc_endpoint_count) 
        return OMPI_ERR_OUT_OF_RESOURCE; 
    
    mvapi_endpoint->endpoint_proc = mvapi_proc;
    mvapi_proc->proc_endpoints[mvapi_proc->proc_endpoint_count++] = mvapi_endpoint;
    
    return OMPI_SUCCESS;
}