Skip to content

Commit a5aef2d

Browse files
committed
Fortran sentinels: use bind(C)
Instead of solely relying on common blocks for the MPI Fortran sentinels (e.g., MPI_BOTTOM), also use a bind(C) statement to bind the back-end symbol name to a specific name. There are two benefits to this: 1. We don't have to have 4 back-end symbols (i.e., CAPS, lower, one_underscore_, and two_underscore__) 2. The mpi_f08 and mpi modules can share the same back-end symbol (because they'll both bind(C) to the same back-end symbol) However, keep definition of MPI_STATUS[ES]_IGNORE in its own separate header files/modules because they are different types in the mpi module vs. the mpi_f08 module. We cannot include the mpi module in the mpi_f08 module, or will get confused by seeing MPI_STATUS[ES]_IGNORE of two different types (even if you "use :: mpi, only : ..." and do not include MPI_STATUS[ES]_IGNORE in the imports list). Fixing point 2 avoided some subtle linker issues (see #9812 (comment) for an explanation). Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
1 parent b40f19f commit a5aef2d

File tree

13 files changed

+133
-60
lines changed

13 files changed

+133
-60
lines changed

ompi/include/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ include_HEADERS += \
4141
mpif-handles.h \
4242
mpif-io-constants.h \
4343
mpif-io-handles.h \
44-
mpif-sentinels.h
44+
mpif-sentinels.h \
45+
mpif-status.h
4546

4647
endif
4748

@@ -125,7 +126,7 @@ CLEANFILES = mpif-sizeof.f90
125126
distclean-local:
126127
rm -f mpi-ext.h mpif-ext.h mpi_portable_platform.h \
127128
mpif-sizeof.h \
128-
mpif-c-constants-decl.h mpif-c-constants.h mpif-f08-types.h
129+
mpif-c-constants-decl.h mpif-c-constants.h
129130

130131
mpi_portable_platform.h: $(top_srcdir)/opal/include/opal/opal_portable_platform_real.h
131132
-@rm -f mpi_portable_platform.h

ompi/include/mpif-sentinels.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,42 @@
3333
! that we already have overloaded F90 bindings for all available
3434
! types), so any type is fine.
3535
integer MPI_BOTTOM
36+
common/mpi_fortran_bottom/MPI_BOTTOM
37+
bind(C, name="mpi_fortran_bottom")/mpi_fortran_bottom/
38+
3639
! MPI_IN_PLACE has the same rationale as MPI_BOTTOM.
3740
integer MPI_IN_PLACE
41+
common/mpi_fortran_in_place/MPI_IN_PLACE
42+
bind(C, name="mpi_fortran_in_place")/mpi_fortran_in_place/
43+
3844
! Making MPI_ARGV_NULL be the same type as the parameter that is
3945
! exepected in the F90 binding for MPI_COMM_SPAWN means that we
4046
! don't need another interface for MPI_COMM_SPAWN.
4147
character MPI_ARGV_NULL(1)
48+
common/mpi_fortran_argv_null/MPI_ARGV_NULL
49+
bind(C, name="mpi_fortran_argv_null")/mpi_fortran_argv_null/
50+
4251
! Ditto for MPI_ARGVS_NULL / MPI_COMM_SPAWN_MULTIPLE.
4352
character MPI_ARGVS_NULL(1, 1)
53+
common/mpi_fortran_argvs_null/MPI_ARGVS_NULL
54+
bind(C, name="mpi_fortran_argvs_null")/mpi_fortran_argvs_null/
55+
4456
! MPI_ERRCODES_IGNORE has similar rationale to MPI_ARGV_NULL. The
4557
! F77 functions are all smart enough to check that the errcodes
4658
! parameter is not ERRCODES_IGNORE before assigning values into it
4759
! (hence, the fact that this is an array of only 1 element does not
4860
! matter -- we'll never overrun it because we never assign values
4961
! into it).
5062
integer MPI_ERRCODES_IGNORE(1)
51-
! MPI_STATUS_IGNORE has similar rationale to MPI_ERRCODES_IGNORE.
52-
integer MPI_STATUS_IGNORE(MPI_STATUS_SIZE)
53-
! Ditto for MPI_STATUSES_IGNORE
54-
integer MPI_STATUSES_IGNORE(MPI_STATUS_SIZE, 1)
63+
common/mpi_fortran_errc_ign/MPI_ERRCODES_IGNORE
64+
bind(C, name="mpi_fortran_errcodes_ignore")/mpi_fortran_errc_ign/
65+
5566
! Ditto for MPI_UNWEIGHTED
5667
integer MPI_UNWEIGHTED(1)
68+
common/mpi_fortran_unwghtd/MPI_UNWEIGHTED
69+
bind(C, name="mpi_fortran_unweighted")/mpi_fortran_unwghtd/
70+
5771
! Ditto for MPI_WEIGHTS_EMPTY
5872
integer MPI_WEIGHTS_EMPTY(1)
59-
60-
common/mpi_fortran_bottom/MPI_BOTTOM
61-
common/mpi_fortran_in_place/MPI_IN_PLACE
62-
common/mpi_fortran_argv_null/MPI_ARGV_NULL
63-
common/mpi_fortran_argvs_null/MPI_ARGVS_NULL
64-
common/mpi_fortran_errcodes_ignore/MPI_ERRCODES_IGNORE
65-
common/mpi_fortran_status_ignore/MPI_STATUS_IGNORE
66-
common/mpi_fortran_statuses_ignore/MPI_STATUSES_IGNORE
67-
common/mpi_fortran_unweighted/MPI_UNWEIGHTED
68-
common/mpi_fortran_weights_empty/MPI_WEIGHTS_EMPTY
73+
common/mpi_fortran_wghts_empty/MPI_WEIGHTS_EMPTY
74+
bind(C, name="mpi_fortran_weights_empty")/mpi_fortran_wghts_empty/

ompi/include/mpif-status.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
! -*- fortran -*-
2+
!
3+
! Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
4+
! University Research and Technology
5+
! Corporation. All rights reserved.
6+
! Copyright (c) 2004-2005 The University of Tennessee and The University
7+
! of Tennessee Research Foundation. All rights
8+
! reserved.
9+
! Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10+
! University of Stuttgart. All rights reserved.
11+
! Copyright (c) 2004-2005 The Regents of the University of California.
12+
! All rights reserved.
13+
! Copyright (c) 2006-2017 Cisco Systems, Inc. All rights reserved
14+
! $COPYRIGHT$
15+
!
16+
! Additional copyrights may follow
17+
!
18+
! $HEADER$
19+
!
20+
21+
! MPI_STATUS[ES]_IGNORE are also sentinels, but they are different
22+
! types than they are in mpi_f08.
23+
integer MPI_STATUS_IGNORE(MPI_STATUS_SIZE)
24+
common/mpi_fortran_st_ign/MPI_STATUS_IGNORE
25+
bind(C, name="mpi_fortran_status_ignore")/mpi_fortran_st_ign/
26+
27+
integer MPI_STATUSES_IGNORE(MPI_STATUS_SIZE, 1)
28+
common/mpi_fortran_sts_ign/MPI_STATUSES_IGNORE
29+
bind(C, name="mpi_fortran_statuses_ignore")/mpi_fortran_sts_ign/

ompi/include/mpif.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@
6161
include 'mpif-externals.h'
6262
include 'mpif-sentinels.h'
6363
include 'mpif-sizeof.h'
64+
include 'mpif-status.h'

ompi/mpi/fortran/base/gen-mpi-mangling.pl

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
3232

3333
my $file_c_constants_decl = "mpif-c-constants-decl.h";
3434
my $file_c_constants = "mpif-c-constants.h";
35-
my $file_f08_types = "mpif-f08-types.h";
3635

3736
# If we are not building fortran, then just make empty files
3837
if ($caps_arg + $plain_arg + $single_underscore_arg +
3938
$double_underscore_arg == 0) {
4039
system("touch $file_c_constants_decl");
4140
system("touch $file_c_constants");
42-
system("touch $file_f08_types");
4341
exit(0);
4442
}
4543

@@ -108,22 +106,6 @@
108106

109107
###############################################################
110108

111-
sub mangle {
112-
my $name = shift;
113-
114-
if ($plain_arg) {
115-
return $name;
116-
} elsif ($caps_arg) {
117-
return uc($name);
118-
} elsif ($single_underscore_arg) {
119-
return $name . "_";
120-
} elsif ($double_underscore_arg) {
121-
return $name . "__";
122-
} else {
123-
die "Unknown name mangling type";
124-
}
125-
}
126-
127109
sub gen_c_constants_decl {
128110
open(OUT, ">$file_c_constants_decl") ||
129111
die "Can't write to $file_c_constants_decl";
@@ -139,13 +121,13 @@ sub gen_c_constants_decl {
139121
*/
140122
141123
/* Note that the rationale for the types of each of these variables is
142-
discussed in ompi/include/mpif-common.h. Do not change the types
124+
discussed in ompi/include/mpif-sentinels.h. Do not change the types
143125
without also changing ompi/runtime/ompi_mpi_init.c and
144-
ompi/include/mpif-common.h. */\n\n";
126+
ompi/include/mpif-sentinels.h. */\n\n";
145127

146128
foreach my $key (sort(keys(%{$fortran}))) {
147129
my $f = $fortran->{$key};
148-
my $m = mangle($f->{c_name});
130+
my $m = $f->{c_name};
149131
print OUT "extern $f->{c_type} $m;
150132
#define OMPI_IS_FORTRAN_" . uc($key) . "(addr) \\
151133
(addr == (void*) &$m)\n\n";
@@ -170,8 +152,8 @@ sub gen_c_constants {
170152

171153
foreach my $key (sort(keys(%{$fortran}))) {
172154
my $f = $fortran->{$key};
173-
my $m = mangle($f->{c_name});
174-
print OUT "$f->{c_type} $m;\n";
155+
my $m = $f->{c_name};
156+
print OUT "$f->{c_type} $m = {0};\n";
175157
}
176158

177159
close (OUT);

ompi/mpi/fortran/use-mpi-f08/mod/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ noinst_LTLIBRARIES = libusempif08_internal_modules.la libforce_usempif08_interna
5252
libusempif08_internal_modules_la_SOURCES = \
5353
mpi-f08-types.F90 \
5454
mpi-f08-callbacks.F90 \
55-
mpi-f08-constants.h
55+
mpi-f08-constants.h \
56+
mpi-f08-sentinels.F90
5657

5758
libusempif08_internal_modules_la_LIBADD = \
5859
$(top_builddir)/ompi/mpi/fortran/use-mpi/libusempi_internal_modules.la
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
! -*- f90 -*-
2+
!
3+
! Copyright (c) 2009-2022 Cisco Systems, Inc. All rights reserved
4+
! Copyright (c) 2009-2012 Los Alamos National Security, LLC.
5+
! All rights reserved.
6+
! Copyright (c) 2015-2020 Research Organization for Information Science
7+
! and Technology (RIST). All rights reserved.
8+
! Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
9+
! Copyright (c) 2020 The University of Tennessee and The University
10+
! of Tennessee Research Foundation. All rights
11+
! reserved.
12+
! $COPYRIGHT$
13+
!
14+
15+
module mpi_f08_sentinels
16+
17+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18+
! Do NOT "use mpi" in here! You will get conflicts for things that
19+
! are different types (e.g., MPI_STATUS[ES]_IGNORE).
20+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21+
22+
use, intrinsic :: ISO_C_BINDING
23+
24+
use mpi_types
25+
use mpi_sentinels
26+
27+
! These are different types than they are in the mpi module
28+
type(MPI_Status) MPI_STATUS_IGNORE
29+
common/mpi_f08_st_ign/MPI_STATUS_IGNORE
30+
bind(C, name="mpi_f08_status_ignore")/mpi_f08_st_ign/
31+
32+
type(MPI_Status) MPI_STATUSES_IGNORE(1)
33+
common/mpi_f08_sts_ign/MPI_STATUSES_IGNORE
34+
bind(C, name="mpi_f08_statuses_ignore")/mpi_f08_sts_ign/
35+
36+
end module mpi_f08_sentinels

ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-types.F90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
module mpi_f08_types
2222

23+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24+
! Do NOT "use mpi" in here! You will get conflicts for things that
25+
! are different types (e.g., MPI_STATUS[ES]_IGNORE).
26+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27+
2328
use, intrinsic :: ISO_C_BINDING
2429
use mpi_types
2530

ompi/mpi/fortran/use-mpi-f08/mpi-f08.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
module mpi_f08
2828

2929
use mpi_f08_types
30+
use mpi_f08_sentinels
3031
use mpi_f08_interfaces ! this module contains the mpi_f08 interface declarations
3132
use pmpi_f08_interfaces ! this module contains the pmpi_f08 interface declarations
3233
use mpi_f08_callbacks ! this module contains the mpi_f08 attribute callback subroutines

ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr.F90

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ module mpi
2727
#if OMPI_FORTRAN_HAVE_TYPE_MPI_STATUS
2828
use mpi_types
2929
#endif
30+
31+
! Sentinel values such as MPI_BOTTOM (that are the same types as in
32+
! mpi_f08 -- not including MPI_STATUS[ES]_IGNORE, which are
33+
! different types in mpi_f08).
34+
use mpi_sentinels
35+
3036
include "mpif-config.h"
3137
include "mpif-constants.h"
3238
include "mpif-handles.h"
3339
include "mpif-io-constants.h"
3440
include "mpif-io-handles.h"
35-
include "mpif-sentinels.h"
41+
include "mpif-status.h"
3642

3743
! The MPI attribute callback functions
3844

0 commit comments

Comments
 (0)