Skip to content

Commit 4d43a3f

Browse files
authored
Merge pull request #2162 from hjelmn/v2.x_cxx_isolation
mpi/cxx: isolate internal headers from C++ bindings
2 parents c1bdb10 + fc0eeb4 commit 4d43a3f

12 files changed

+426
-265
lines changed

ompi/errhandler/errhandler.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* -*- Mode: C; c-basic-offset:4 ; -*- */
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
22
/*
33
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44
* University Research and Technology
@@ -12,7 +12,11 @@
1212
* All rights reserved.
1313
* Copyright (c) 2008-2012 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2008-2009 Sun Microsystems, Inc. All rights reserved.
15-
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights reserved.
15+
* Copyright (c) 2015-2016 Intel, Inc. All rights reserved.
16+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
17+
* reserved.
18+
* Copyright (c) 2016 Research Organization for Information Science
19+
* and Technology (RIST). All rights reserved.
1620
* $COPYRIGHT$
1721
*
1822
* Additional copyrights may follow
@@ -32,7 +36,6 @@
3236
#include "opal/class/opal_object.h"
3337
#include "opal/class/opal_pointer_array.h"
3438

35-
#include "ompi/mca/rte/rte.h"
3639
#include "ompi/runtime/mpiruntime.h"
3740
#include "ompi/errhandler/errhandler_predefined.h"
3841
#include "ompi/errhandler/errcode-internal.h"
@@ -91,9 +94,8 @@ struct ompi_errhandler_t;
9194
/**
9295
* C++ invocation function signature
9396
*/
94-
typedef void (ompi_errhandler_cxx_dispatch_fn_t)(struct ompi_errhandler_t *errhandler,
95-
void *handle, int *err_code,
96-
const char *message);
97+
typedef void (ompi_errhandler_cxx_dispatch_fn_t)(void *handle, int *err_code,
98+
const char *message, ompi_errhandler_generic_handler_fn_t *fn);
9799

98100
/**
99101
* Back-end type for MPI_Errorhandler.

ompi/errhandler/errhandler_invoke.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12
/*
23
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
34
* University Research and Technology
@@ -11,6 +12,10 @@
1112
* All rights reserved.
1213
* Copyright (c) 2006-2012 Cisco Systems, Inc. All rights reserved.
1314
* Copyright (c) 2012 Oak Ridge National Labs. All rights reserved.
15+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
16+
* reserved.
17+
* Copyright (c) 2016 Research Organization for Information Science
18+
* and Technology (RIST). All rights reserved.
1419
* $COPYRIGHT$
1520
*
1621
* Additional copyrights may follow
@@ -54,8 +59,8 @@ int ompi_errhandler_invoke(ompi_errhandler_t *errhandler, void *mpi_object,
5459
break;
5560

5661
case OMPI_ERRHANDLER_LANG_CXX:
57-
errhandler->eh_cxx_dispatch_fn(errhandler, &comm,
58-
&err_code, message);
62+
errhandler->eh_cxx_dispatch_fn(&comm, &err_code, message,
63+
(ompi_errhandler_generic_handler_fn_t *)errhandler->eh_comm_fn);
5964
break;
6065

6166
case OMPI_ERRHANDLER_LANG_FORTRAN:
@@ -74,8 +79,8 @@ int ompi_errhandler_invoke(ompi_errhandler_t *errhandler, void *mpi_object,
7479
break;
7580

7681
case OMPI_ERRHANDLER_LANG_CXX:
77-
errhandler->eh_cxx_dispatch_fn(errhandler, &win,
78-
&err_code, message);
82+
errhandler->eh_cxx_dispatch_fn(&win, &err_code, message,
83+
(ompi_errhandler_generic_handler_fn_t *)errhandler->eh_win_fn);
7984
break;
8085

8186
case OMPI_ERRHANDLER_LANG_FORTRAN:
@@ -94,8 +99,8 @@ int ompi_errhandler_invoke(ompi_errhandler_t *errhandler, void *mpi_object,
9499
break;
95100

96101
case OMPI_ERRHANDLER_LANG_CXX:
97-
errhandler->eh_cxx_dispatch_fn(errhandler, &file,
98-
&err_code, message);
102+
errhandler->eh_cxx_dispatch_fn(&file, &err_code, message,
103+
(ompi_errhandler_generic_handler_fn_t *)errhandler->eh_file_fn);
99104
break;
100105

101106
case OMPI_ERRHANDLER_LANG_FORTRAN:

ompi/mpi/cxx/Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ lib@OMPI_LIBMPI_NAME@_cxx_la_SOURCES = \
3636
intercepts.cc \
3737
comm.cc \
3838
datatype.cc \
39-
win.cc
39+
win.cc \
40+
cxx_glue.c
4041

4142
if OMPI_PROVIDE_MPI_FILE_INTERFACE
4243
lib@OMPI_LIBMPI_NAME@_cxx_la_SOURCES += \
@@ -77,7 +78,8 @@ headers = \
7778
group_inln.h \
7879
op_inln.h \
7980
errhandler_inln.h \
80-
status_inln.h
81+
status_inln.h \
82+
cxx_glue.h
8183

8284
ompidir = $(ompiincludedir)/ompi/mpi/cxx
8385
ompi_HEADERS = \

ompi/mpi/cxx/comm.cc

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// Copyright (c) 2004-2005 The Regents of the University of California.
1212
// All rights reserved.
1313
// Copyright (c) 2007-2008 Cisco Systems, Inc. All rights reserved.
14+
// Copyright (c) 2016 Los Alamos National Security, LLC. All rights
15+
// reserved.
1416
// $COPYRIGHT$
1517
//
1618
// Additional copyrights may follow
@@ -20,16 +22,9 @@
2022

2123
// do not include ompi_config.h because it kills the free/malloc defines
2224
#include "mpi.h"
25+
#include "ompi/constants.h"
2326
#include "ompi/mpi/cxx/mpicxx.h"
24-
25-
#ifdef HAVE_SCHED_H
26-
#include <sched.h>
27-
#endif
28-
29-
30-
#include "ompi/communicator/communicator.h"
31-
#include "ompi/attribute/attribute.h"
32-
#include "ompi/errhandler/errhandler.h"
27+
#include "cxx_glue.h"
3328

3429

3530
//
@@ -56,14 +51,7 @@ MPI::Comm::Comm(const Comm_Null& data) : Comm_Null(data)
5651
MPI::Errhandler
5752
MPI::Comm::Create_errhandler(MPI::Comm::_MPI2CPP_ERRHANDLERFN_* function)
5853
{
59-
MPI_Errhandler c_errhandler =
60-
ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_COMM,
61-
(ompi_errhandler_generic_handler_fn_t*) function,
62-
OMPI_ERRHANDLER_LANG_CXX);
63-
c_errhandler->eh_cxx_dispatch_fn =
64-
(ompi_errhandler_cxx_dispatch_fn_t*)
65-
ompi_mpi_cxx_comm_errhandler_invoke;
66-
return c_errhandler;
54+
return ompi_cxx_errhandler_create_comm ((ompi_cxx_dummy_fn_t *) function);
6755
}
6856

6957

@@ -77,20 +65,15 @@ MPI::Comm::do_create_keyval(MPI_Comm_copy_attr_function* c_copy_fn,
7765
void* extra_state, int &keyval)
7866
{
7967
int ret, count = 0;
80-
ompi_attribute_fn_ptr_union_t copy_fn;
81-
ompi_attribute_fn_ptr_union_t delete_fn;
8268
keyval_intercept_data_t *cxx_extra_state;
8369

8470
// If both the callbacks are C, then do the simple thing -- no
8571
// need for all the C++ machinery.
8672
if (NULL != c_copy_fn && NULL != c_delete_fn) {
87-
copy_fn.attr_communicator_copy_fn =
88-
(MPI_Comm_internal_copy_attr_function*) c_copy_fn;
89-
delete_fn.attr_communicator_delete_fn = c_delete_fn;
90-
ret = ompi_attr_create_keyval(COMM_ATTR, copy_fn, delete_fn,
91-
&keyval, extra_state, 0, NULL);
73+
ret = ompi_cxx_attr_create_keyval_comm (c_copy_fn, c_delete_fn, &keyval,
74+
extra_state, 0, NULL);
9275
if (MPI_SUCCESS != ret) {
93-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, ret,
76+
return ompi_cxx_errhandler_invoke_comm(MPI_COMM_WORLD, ret,
9477
"MPI::Comm::Create_keyval");
9578
}
9679
}
@@ -107,8 +90,8 @@ MPI::Comm::do_create_keyval(MPI_Comm_copy_attr_function* c_copy_fn,
10790
cxx_extra_state = (keyval_intercept_data_t*)
10891
malloc(sizeof(keyval_intercept_data_t));
10992
if (NULL == cxx_extra_state) {
110-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_NO_MEM,
111-
"MPI::Comm::Create_keyval");
93+
return ompi_cxx_errhandler_invoke_comm (MPI_COMM_WORLD, MPI_ERR_NO_MEM,
94+
"MPI::Comm::Create_keyval");
11295
}
11396
cxx_extra_state->c_copy_fn = c_copy_fn;
11497
cxx_extra_state->cxx_copy_fn = cxx_copy_fn;
@@ -131,26 +114,20 @@ MPI::Comm::do_create_keyval(MPI_Comm_copy_attr_function* c_copy_fn,
131114
}
132115
if (2 != count) {
133116
free(cxx_extra_state);
134-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
135-
"MPI::Comm::Create_keyval");
117+
return ompi_cxx_errhandler_invoke_comm (MPI_COMM_WORLD, MPI_ERR_ARG,
118+
"MPI::Comm::Create_keyval");
136119
}
137120

138121
// We do not call MPI_Comm_create_keyval() here because we need to
139122
// pass in the cxx_extra_state to the backend keyval creation so
140123
// that when the keyval is destroyed (i.e., when its refcount goes
141124
// to 0), the cxx_extra_state is free()'ed.
142-
143-
copy_fn.attr_communicator_copy_fn =
144-
(MPI_Comm_internal_copy_attr_function*)
145-
ompi_mpi_cxx_comm_copy_attr_intercept;
146-
delete_fn.attr_communicator_delete_fn =
147-
ompi_mpi_cxx_comm_delete_attr_intercept;
148-
ret = ompi_attr_create_keyval(COMM_ATTR, copy_fn, delete_fn,
149-
&keyval, cxx_extra_state, 0,
150-
cxx_extra_state);
125+
ret = ompi_cxx_attr_create_keyval_comm ((MPI_Comm_copy_attr_function *) ompi_mpi_cxx_comm_copy_attr_intercept,
126+
ompi_mpi_cxx_comm_delete_attr_intercept,
127+
&keyval, cxx_extra_state, 0, cxx_extra_state);
151128
if (OMPI_SUCCESS != ret) {
152-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, ret,
153-
"MPI::Comm::Create_keyval");
129+
return ompi_cxx_errhandler_invoke_comm (MPI_COMM_WORLD, ret,
130+
"MPI::Comm::Create_keyval");
154131
}
155132

156133
return MPI_SUCCESS;

ompi/mpi/cxx/cxx_glue.c

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
4+
* reserved.
5+
* Copyright (c) 2016 Research Organization for Information Science
6+
* and Technology (RIST). All rights reserved.
7+
* $COPYRIGHT$
8+
*
9+
* Additional copyrights may follow
10+
*
11+
* $HEADER$
12+
*/
13+
14+
#include "ompi_config.h"
15+
16+
#include "ompi/communicator/communicator.h"
17+
#include "ompi/attribute/attribute.h"
18+
#include "ompi/errhandler/errhandler.h"
19+
#include "ompi/file/file.h"
20+
#include "opal/class/opal_list.h"
21+
#include "cxx_glue.h"
22+
23+
typedef struct ompi_cxx_intercept_file_extra_state_item_t {
24+
opal_list_item_t super;
25+
ompi_cxx_intercept_file_extra_state_t state;
26+
} ompi_cxx_intercept_file_extra_state_item_t;
27+
28+
OBJ_CLASS_DECLARATION(ompi_cxx_intercept_file_extra_state_item_t);
29+
OBJ_CLASS_INSTANCE(ompi_cxx_intercept_file_extra_state_item_t, opal_list_item_t,
30+
NULL, NULL);
31+
32+
ompi_cxx_communicator_type_t ompi_cxx_comm_get_type (MPI_Comm comm)
33+
{
34+
if (OMPI_COMM_IS_GRAPH(comm)) {
35+
return OMPI_CXX_COMM_TYPE_GRAPH;
36+
} else if (OMPI_COMM_IS_CART(comm)) {
37+
return OMPI_CXX_COMM_TYPE_CART;
38+
} else if (OMPI_COMM_IS_INTRA(comm)) {
39+
return OMPI_CXX_COMM_TYPE_INTRACOMM;
40+
} else if (OMPI_COMM_IS_INTER(comm)) {
41+
return OMPI_CXX_COMM_TYPE_INTERCOMM;
42+
}
43+
44+
return OMPI_CXX_COMM_TYPE_UNKNOWN;
45+
}
46+
47+
int ompi_cxx_errhandler_invoke_comm (MPI_Comm comm, int ret, const char *message)
48+
{
49+
return OMPI_ERRHANDLER_INVOKE (comm, ret, message);
50+
}
51+
52+
#if OMPI_PROVIDE_MPI_FILE_INTERFACE
53+
int ompi_cxx_errhandler_invoke_file (MPI_File file, int ret, const char *message)
54+
{
55+
return OMPI_ERRHANDLER_INVOKE (file, ret, message);
56+
}
57+
#endif
58+
59+
int ompi_cxx_attr_create_keyval_comm (MPI_Comm_copy_attr_function *copy_fn,
60+
MPI_Comm_delete_attr_function* delete_fn, int *keyval, void *extra_state,
61+
int flags, void *bindings_extra_state)
62+
{
63+
ompi_attribute_fn_ptr_union_t copy_fn_u = {.attr_communicator_copy_fn =
64+
(MPI_Comm_internal_copy_attr_function *) copy_fn};
65+
ompi_attribute_fn_ptr_union_t delete_fn_u = {.attr_communicator_delete_fn =
66+
(MPI_Comm_delete_attr_function *) delete_fn};
67+
68+
return ompi_attr_create_keyval (COMM_ATTR, copy_fn_u, delete_fn_u, keyval, extra_state, 0, bindings_extra_state);
69+
}
70+
71+
int ompi_cxx_attr_create_keyval_win (MPI_Win_copy_attr_function *copy_fn,
72+
MPI_Win_delete_attr_function* delete_fn, int *keyval, void *extra_state,
73+
int flags, void *bindings_extra_state)
74+
{
75+
ompi_attribute_fn_ptr_union_t copy_fn_u = {.attr_win_copy_fn =
76+
(MPI_Win_internal_copy_attr_function *) copy_fn};
77+
ompi_attribute_fn_ptr_union_t delete_fn_u = {.attr_win_delete_fn =
78+
(MPI_Win_delete_attr_function *) delete_fn};
79+
80+
return ompi_attr_create_keyval (WIN_ATTR, copy_fn_u, delete_fn_u, keyval, extra_state, 0, NULL);
81+
}
82+
83+
int ompi_cxx_attr_create_keyval_type (MPI_Type_copy_attr_function *copy_fn,
84+
MPI_Type_delete_attr_function* delete_fn, int *keyval, void *extra_state,
85+
int flags, void *bindings_extra_state)
86+
{
87+
ompi_attribute_fn_ptr_union_t copy_fn_u = {.attr_datatype_copy_fn =
88+
(MPI_Type_internal_copy_attr_function *) copy_fn};
89+
ompi_attribute_fn_ptr_union_t delete_fn_u = {.attr_datatype_delete_fn =
90+
(MPI_Type_delete_attr_function *) delete_fn};
91+
92+
return ompi_attr_create_keyval (TYPE_ATTR, copy_fn_u, delete_fn_u, keyval, extra_state, 0, NULL);
93+
}
94+
95+
MPI_Errhandler ompi_cxx_errhandler_create_comm (ompi_cxx_dummy_fn_t *fn)
96+
{
97+
ompi_errhandler_t *errhandler;
98+
errhandler = ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_COMM,
99+
(ompi_errhandler_generic_handler_fn_t *) fn,
100+
OMPI_ERRHANDLER_LANG_CXX);
101+
errhandler->eh_cxx_dispatch_fn =
102+
(ompi_errhandler_cxx_dispatch_fn_t *) ompi_mpi_cxx_comm_errhandler_invoke;
103+
return errhandler;
104+
}
105+
106+
MPI_Errhandler ompi_cxx_errhandler_create_win (ompi_cxx_dummy_fn_t *fn)
107+
{
108+
ompi_errhandler_t *errhandler;
109+
errhandler = ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_WIN,
110+
(ompi_errhandler_generic_handler_fn_t *) fn,
111+
OMPI_ERRHANDLER_LANG_CXX);
112+
errhandler->eh_cxx_dispatch_fn =
113+
(ompi_errhandler_cxx_dispatch_fn_t *) ompi_mpi_cxx_win_errhandler_invoke;
114+
return errhandler;
115+
}
116+
117+
#if OMPI_PROVIDE_MPI_FILE_INTERFACE
118+
MPI_Errhandler ompi_cxx_errhandler_create_file (ompi_cxx_dummy_fn_t *fn)
119+
{
120+
ompi_errhandler_t *errhandler;
121+
errhandler = ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_FILE,
122+
(ompi_errhandler_generic_handler_fn_t *) fn,
123+
OMPI_ERRHANDLER_LANG_CXX);
124+
errhandler->eh_cxx_dispatch_fn =
125+
(ompi_errhandler_cxx_dispatch_fn_t *) ompi_mpi_cxx_file_errhandler_invoke;
126+
return errhandler;
127+
}
128+
#endif
129+
130+
ompi_cxx_intercept_file_extra_state_t
131+
*ompi_cxx_new_intercept_state (void *read_fn_cxx, void *write_fn_cxx, void *extent_fn_cxx,
132+
void *extra_state_cxx)
133+
{
134+
ompi_cxx_intercept_file_extra_state_item_t *intercept;
135+
136+
intercept = OBJ_NEW(ompi_cxx_intercept_file_extra_state_item_t);
137+
if (NULL == intercept) {
138+
return NULL;
139+
}
140+
141+
opal_list_append(&ompi_registered_datareps, &intercept->super);
142+
intercept->state.read_fn_cxx = read_fn_cxx;
143+
intercept->state.write_fn_cxx = write_fn_cxx;
144+
intercept->state.extent_fn_cxx = extent_fn_cxx;
145+
intercept->state.extra_state_cxx = extra_state_cxx;
146+
147+
return &intercept->state;
148+
}
149+
150+
void ompi_cxx_errhandler_set_callbacks (struct ompi_errhandler_t *errhandler, MPI_Comm_errhandler_function *eh_comm_fn,
151+
ompi_file_errhandler_fn *eh_file_fn, MPI_Win_errhandler_function *eh_win_fn)
152+
{
153+
errhandler->eh_comm_fn = eh_comm_fn;
154+
#if OMPI_PROVIDE_MPI_FILE_INTERFACE
155+
errhandler->eh_file_fn = eh_file_fn;
156+
#endif
157+
errhandler->eh_win_fn = eh_win_fn;
158+
}

0 commit comments

Comments
 (0)