File: ompi_module_exchange.c

package info (click to toggle)
openmpi 1.6.5-9.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 91,628 kB
  • ctags: 44,305
  • sloc: ansic: 408,966; cpp: 44,454; sh: 27,828; makefile: 10,486; asm: 3,882; python: 1,239; lex: 805; perl: 549; csh: 253; fortran: 232; f90: 126; tcl: 12
file content (139 lines) | stat: -rw-r--r-- 3,743 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
/*
 * 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 (c) 2006-2007 Los Alamos National Security, LLC.  All rights
 *                         reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "ompi_config.h"
#include "ompi/constants.h"

#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/dss/dss.h"

#include "orte/mca/grpcomm/grpcomm.h"

#include "orte/util/name_fns.h"
#include "orte/runtime/orte_globals.h"

#include "ompi/proc/proc.h"
#include "ompi/runtime/ompi_module_exchange.h"


int
ompi_modex_send(mca_base_component_t * source_component,
                const void *data, size_t size)
{
    int rc;
    char * name = mca_base_component_to_string(source_component);
    
    if(NULL == name) {
        return OMPI_ERR_OUT_OF_RESOURCE;
    }
    
    rc = orte_grpcomm.set_proc_attr(name, data, size);
    free(name);
    return rc;
}


int
ompi_modex_recv(mca_base_component_t * component,
                ompi_proc_t * proc,
                void **buffer,
                size_t * size)
{
    int rc;
    char * name = mca_base_component_to_string(component);
    
    if(NULL == name) {
        return OMPI_ERR_OUT_OF_RESOURCE;
    }
    
    rc = orte_grpcomm.get_proc_attr(proc->proc_name, name, buffer, size);
    free(name);
    return rc;
}

int
ompi_modex_send_string(const char* key,
                       const void *buffer, size_t size)
{
    return orte_grpcomm.set_proc_attr(key, buffer, size);
}


int
ompi_modex_recv_string(const char* key,
                       struct ompi_proc_t *source_proc,
                       void **buffer, size_t *size)
{
    return orte_grpcomm.get_proc_attr(source_proc->proc_name, key, buffer, size);
}

int
ompi_modex_send_key_value(const char* key,
                          const void *value,
                          opal_data_type_t dtype)
{
    int rc;
    opal_buffer_t buf;
    opal_byte_object_t bo;
    
    OBJ_CONSTRUCT(&buf, opal_buffer_t);
    if (OPAL_SUCCESS != (rc = opal_dss.pack(&buf, value, 1, dtype))) {
        OBJ_DESTRUCT(&buf);
        return rc;
    }
    if (OPAL_SUCCESS != (rc = opal_dss.unload(&buf, (void**)&bo.bytes, &bo.size))) {
        OBJ_DESTRUCT(&buf);
        return rc;
    }
    OBJ_DESTRUCT(&buf);
    
    return orte_grpcomm.set_proc_attr(key, bo.bytes, bo.size);
}


int
ompi_modex_recv_key_value(const char* key,
                          struct ompi_proc_t *source_proc,
                          void *value, opal_data_type_t dtype)
{
    int rc;
    opal_buffer_t buf;
    opal_byte_object_t bo;
    int32_t n;
    size_t bsize;
    
    bo.bytes = NULL;
    bo.size = 0;
    if (OMPI_SUCCESS != (rc = orte_grpcomm.get_proc_attr(source_proc->proc_name, key,
                                                         (void**)&bo.bytes, &bsize))) {
        return rc;
    }
    bo.size = bsize;
    OBJ_CONSTRUCT(&buf, opal_buffer_t);
    if (OMPI_SUCCESS != (rc = opal_dss.load(&buf, bo.bytes, bo.size))) {
        OBJ_DESTRUCT(&buf);
        return rc;
    }
    n = 1;
    rc = opal_dss.unpack(&buf, value, &n, dtype);
    OBJ_DESTRUCT(&buf);
    return rc;
}