Skip to content

Commit c234b3a

Browse files
committed
mpi/cxx: isolate internal headers from C++ bindings
This commit adds some glue code to support the C++ bindings and updates the bindings to use the new glue code. This protects our internal headers (which are C99) from C++. This is done as a quick workaround to compilation errors when the legacy C++ bindings are requested. Fixes #2055 Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 08d08e6 commit c234b3a

File tree

10 files changed

+165
-261
lines changed

10 files changed

+165
-261
lines changed

ompi/errhandler/errhandler.h

Lines changed: 5 additions & 4 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
@@ -13,6 +13,8 @@
1313
* Copyright (c) 2008-2012 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2008-2009 Sun Microsystems, Inc. All rights reserved.
1515
* Copyright (c) 2015-2016 Intel, Inc. All rights reserved.
16+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
17+
* reserved.
1618
* $COPYRIGHT$
1719
*
1820
* Additional copyrights may follow
@@ -92,9 +94,8 @@ struct ompi_errhandler_t;
9294
/**
9395
* C++ invocation function signature
9496
*/
95-
typedef void (ompi_errhandler_cxx_dispatch_fn_t)(struct ompi_errhandler_t *errhandler,
96-
void *handle, int *err_code,
97-
const char *message);
97+
typedef void (ompi_errhandler_cxx_dispatch_fn_t)(void *handle, int *err_code,
98+
const char *message, void *fn);
9899

99100
/**
100101
* Back-end type for MPI_Errorhandler.

ompi/errhandler/errhandler_invoke.c

Lines changed: 9 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,8 @@
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.
1417
* $COPYRIGHT$
1518
*
1619
* Additional copyrights may follow
@@ -54,8 +57,8 @@ int ompi_errhandler_invoke(ompi_errhandler_t *errhandler, void *mpi_object,
5457
break;
5558

5659
case OMPI_ERRHANDLER_LANG_CXX:
57-
errhandler->eh_cxx_dispatch_fn(errhandler, &comm,
58-
&err_code, message);
60+
errhandler->eh_cxx_dispatch_fn(&comm, &err_code, message,
61+
errhandler->eh_comm_fn);
5962
break;
6063

6164
case OMPI_ERRHANDLER_LANG_FORTRAN:
@@ -74,8 +77,8 @@ int ompi_errhandler_invoke(ompi_errhandler_t *errhandler, void *mpi_object,
7477
break;
7578

7679
case OMPI_ERRHANDLER_LANG_CXX:
77-
errhandler->eh_cxx_dispatch_fn(errhandler, &win,
78-
&err_code, message);
80+
errhandler->eh_cxx_dispatch_fn(&win, &err_code, message,
81+
errhandler->eh_win_fn);
7982
break;
8083

8184
case OMPI_ERRHANDLER_LANG_FORTRAN:
@@ -94,8 +97,8 @@ int ompi_errhandler_invoke(ompi_errhandler_t *errhandler, void *mpi_object,
9497
break;
9598

9699
case OMPI_ERRHANDLER_LANG_CXX:
97-
errhandler->eh_cxx_dispatch_fn(errhandler, &file,
98-
&err_code, message);
100+
errhandler->eh_cxx_dispatch_fn(&file, &err_code, message,
101+
errhandler->eh_file_fn);
99102
break;
100103

101104
case OMPI_ERRHANDLER_LANG_FORTRAN:

ompi/mpi/cxx/Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ libmpi_cxx_la_SOURCES = \
3535
intercepts.cc \
3636
comm.cc \
3737
datatype.cc \
38-
win.cc
38+
win.cc \
39+
cxx_glue.c
3940

4041
if OMPI_PROVIDE_MPI_FILE_INTERFACE
4142
libmpi_cxx_la_SOURCES += \
@@ -76,7 +77,8 @@ headers = \
7677
group_inln.h \
7778
op_inln.h \
7879
errhandler_inln.h \
79-
status_inln.h
80+
status_inln.h \
81+
cxx_glue.h
8082

8183
ompidir = $(ompiincludedir)/ompi/mpi/cxx
8284
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 ((void *) 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/datatype.cc

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -*- c++ -*-
22
//
3-
// Copyright (c) 2006 Los Alamos National Security, LLC. All rights
3+
// Copyright (c) 2006-2016 Los Alamos National Security, LLC. All rights
44
// reserved.
55
// Copyright (c) 2007-2008 Sun Microsystems, Inc. All rights reserved.
66
// Copyright (c) 2007-2008 Cisco Systems, Inc. All rights reserved.
@@ -14,12 +14,8 @@
1414
// do not include ompi_config.h because it kills the free/malloc defines
1515
#include "mpi.h"
1616
#include "ompi/mpi/cxx/mpicxx.h"
17-
18-
19-
#include "ompi/communicator/communicator.h"
20-
#include "ompi/attribute/attribute.h"
21-
#include "ompi/errhandler/errhandler.h"
22-
17+
#include "ompi/constants.h"
18+
#include "cxx_glue.h"
2319

2420
void
2521
MPI::Datatype::Free()
@@ -35,21 +31,16 @@ MPI::Datatype::do_create_keyval(MPI_Type_copy_attr_function* c_copy_fn,
3531
void* extra_state, int &keyval)
3632
{
3733
int ret, count = 0;
38-
ompi_attribute_fn_ptr_union_t copy_fn;
39-
ompi_attribute_fn_ptr_union_t delete_fn;
4034
keyval_intercept_data_t *cxx_extra_state;
4135

4236
// If both the callbacks are C, then do the simple thing -- no
4337
// need for all the C++ machinery.
4438
if (NULL != c_copy_fn && NULL != c_delete_fn) {
45-
copy_fn.attr_datatype_copy_fn =
46-
(MPI_Type_internal_copy_attr_function*) c_copy_fn;
47-
delete_fn.attr_datatype_delete_fn = c_delete_fn;
48-
ret = ompi_attr_create_keyval(COMM_ATTR, copy_fn, delete_fn,
49-
&keyval, extra_state, 0, NULL);
39+
ret = ompi_cxx_attr_create_keyval_type (c_copy_fn, c_delete_fn, &keyval,
40+
extra_state, 0, NULL);
5041
if (MPI_SUCCESS != ret) {
51-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, ret,
52-
"MPI::Datatype::Create_keyval");
42+
return ompi_cxx_errhandler_invoke_comm (MPI_COMM_WORLD, ret,
43+
"MPI::Datatype::Create_keyval");
5344
}
5445
}
5546

@@ -63,8 +54,8 @@ MPI::Datatype::do_create_keyval(MPI_Type_copy_attr_function* c_copy_fn,
6354
cxx_extra_state = (keyval_intercept_data_t*)
6455
malloc(sizeof(keyval_intercept_data_t));
6556
if (NULL == cxx_extra_state) {
66-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_NO_MEM,
67-
"MPI::Datatype::Create_keyval");
57+
return ompi_cxx_errhandler_invoke_comm (MPI_COMM_WORLD, MPI_ERR_NO_MEM,
58+
"MPI::Datatype::Create_keyval");
6859
}
6960
cxx_extra_state->c_copy_fn = c_copy_fn;
7061
cxx_extra_state->cxx_copy_fn = cxx_copy_fn;
@@ -87,8 +78,8 @@ MPI::Datatype::do_create_keyval(MPI_Type_copy_attr_function* c_copy_fn,
8778
}
8879
if (2 != count) {
8980
free(cxx_extra_state);
90-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
91-
"MPI::Datatype::Create_keyval");
81+
return ompi_cxx_errhandler_invoke_comm (MPI_COMM_WORLD, MPI_ERR_ARG,
82+
"MPI::Datatype::Create_keyval");
9283
}
9384

9485
// We do not call MPI_Datatype_create_keyval() here because we need to
@@ -100,18 +91,12 @@ MPI::Datatype::do_create_keyval(MPI_Type_copy_attr_function* c_copy_fn,
10091
// MPI_Comm_create_keyval(). Hence, we do all the work here (and
10192
// ensure to set the destructor atomicly when the keyval is
10293
// created).
103-
104-
copy_fn.attr_datatype_copy_fn =
105-
(MPI_Type_internal_copy_attr_function*)
106-
ompi_mpi_cxx_type_copy_attr_intercept;
107-
delete_fn.attr_datatype_delete_fn =
108-
ompi_mpi_cxx_type_delete_attr_intercept;
109-
ret = ompi_attr_create_keyval(TYPE_ATTR, copy_fn, delete_fn,
110-
&keyval, cxx_extra_state, 0,
111-
cxx_extra_state);
94+
ret = ompi_cxx_attr_create_keyval_type ((MPI_Type_copy_attr_function *) ompi_mpi_cxx_type_copy_attr_intercept,
95+
ompi_mpi_cxx_type_delete_attr_intercept, &keyval,
96+
extra_state, 0, NULL);
11297
if (OMPI_SUCCESS != ret) {
113-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, ret,
114-
"MPI::Datatype::Create_keyval");
98+
return ompi_cxx_errhandler_invoke_comm (MPI_COMM_WORLD, ret,
99+
"MPI::Datatype::Create_keyval");
115100
}
116101

117102
return MPI_SUCCESS;

0 commit comments

Comments
 (0)