Skip to content

Commit 5609268

Browse files
MaskRayjsquyres
authored andcommitted
Make C and Fortran types for MPI sentinels agree in size
Fix the C types for the following: * MPI_UNWEIGHTED * MPI_WEIGHTS_EMPTY * MPI_ARGV_NULL * MPI_ARGVS_NULL * MPI_ERRCODES_IGNORE There is lengthy discussion on #7210 describing the issue; the gist of it is that the C and Fortran types for several MPI global sentenial values should agree (specifically: their sizes must(**) agree). We erroneously had several of these array-like sentinel values be "array-like" values in C. E.g., MPI_ERRCODES_IGNORE was an (int *) in C while its corresponding Fortran type was "integer, dimension(1)". On a 64 bit platform, this resulted in C expecting the symbol size to be sizeof(int*)==8 while Fortran expected the symbol size to be sizeof(INTEGER, DIMENSION(1))==4. That is incorrect -- the corresponding C type needed to be (int). Then both C and Fortran expect the size of the symbol to be the same. (**) NOTE: This code has been wrong for years. This mismatch of types typically worked because, due to Fortran's call-by-reference semantics, Open MPI was comparing the *addresses* of these instances, not their *types* (or sizes) -- so even if C expected the size of the symbol to be X and Fortran expected the size of the symbol to be Y (where X!=Y), all we really checked at run time was that the addresses of the symbols were the same. But it caused linker warning messages, and even caused errors in some cases. Specifically: due to a GNU ld bug (https://sourceware.org/bugzilla/show_bug.cgi?id=25236), the 5 common symbols are incorrectly versioned VER_NDX_LOCAL because their definitions in Fortran sources have smaller st_size than those in libmpi.so. This makes the Fortran library not linkable with lld in distributions that ship openmpi built with -Wl,--version-script (https://bugs.llvm.org/show_bug.cgi?id=43748): % mpifort -fuse-ld=lld /dev/null ld.lld: error: corrupt input file: version definition index 0 for symbol mpi_fortran_argv_null_ is out of bounds >>> defined in /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_usempif08.so ... If we fix the C and Fortran symbols to actually be the same size, the problem goes away and the GNU ld bug does not come into play. This commit also fixes a minor issue that MPI_UNWEIGHTED and MPI_WEIGHTS_EMPTY were not declared as Fortran arrays (not fully fixed by commit 107c007). Fixes #7209 Signed-off-by: Fangrui Song <[email protected]> Signed-off-by: Jeff Squyres <[email protected]>
1 parent 48c04cd commit 5609268

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Copyright (c) 2015 Research Organization for Information Science
44
# and Technology (RIST). All rights reserved.
5-
# Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
5+
# Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
66
# $COPYRIGHT$
77
#
88
# Subroutine to generate a bunch of Fortran declarations and symbols
@@ -62,33 +62,33 @@
6262
f_name => "MPI_IN_PLACE",
6363
};
6464
$fortran->{unweighted} = {
65-
c_type => "int *",
65+
c_type => "int",
6666
c_name => "mpi_fortran_unweighted",
67-
f_type => "integer",
67+
f_type => "integer, dimension(1)",
6868
f_name => "MPI_UNWEIGHTED",
6969
};
7070
$fortran->{weights_empty} = {
71-
c_type => "int *",
71+
c_type => "int",
7272
c_name => "mpi_fortran_weights_empty",
73-
f_type => "integer",
73+
f_type => "integer, dimension(1)",
7474
f_name => "MPI_WEIGHTS_EMPTY",
7575
};
7676

7777
$fortran->{argv_null} = {
78-
c_type => "char *",
78+
c_type => "char",
7979
c_name => "mpi_fortran_argv_null",
8080
f_type => "character, dimension(1)",
8181
f_name => "MPI_ARGV_NULL",
8282
};
8383
$fortran->{argvs_null} = {
84-
c_type => "char *",
84+
c_type => "char",
8585
c_name => "mpi_fortran_argvs_null",
8686
f_type => "character, dimension(1, 1)",
8787
f_name => "MPI_ARGVS_NULL",
8888
};
8989

9090
$fortran->{errcodes_ignore} = {
91-
c_type => "int *",
91+
c_type => "int",
9292
c_name => "mpi_fortran_errcodes_ignore",
9393
f_type => "integer, dimension(1)",
9494
f_name => "MPI_ERRCODES_IGNORE",

0 commit comments

Comments
 (0)