Skip to content

Commit 5c8fbd6

Browse files
committed
fortran: fix common symbol sizes and alignments
Refs #13043 Thanks MJ Rutter for the report Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent e8f7f7b commit 5c8fbd6

File tree

4 files changed

+70
-16
lines changed

4 files changed

+70
-16
lines changed

config/ompi_fortran_get_alignment.m4

+40
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
1010
dnl University of Stuttgart. All rights reserved.
1111
dnl Copyright (c) 2004-2005 The Regents of the University of California.
1212
dnl All rights reserved.
13+
dnl Copyright (c) 2025 Research Organization for Information Science
14+
dnl and Technology (RIST). All rights reserved.
1315
dnl Copyright (c) 2010-2012 Cisco Systems, Inc. All rights reserved.
1416
dnl $COPYRIGHT$
1517
dnl
@@ -178,3 +180,41 @@ end program]])],
178180
AS_VAR_COPY([$2], [type_var])
179181
AS_VAR_POPDEF([type_var])dnl
180182
])dnl
183+
184+
# OMPI_FORTRAN_GET_COMMON_ALIGNMENT(variable to set)
185+
# ------------------------------------------
186+
AC_DEFUN([OMPI_FORTRAN_GET_COMMON_ALIGNMENT],[
187+
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -gt $OMPI_FORTRAN_NO_BINDINGS],
188+
[AC_CACHE_CHECK([alignment of Fortran common], ompi_cv_fortran_common_alignment,
189+
[AC_LANG_PUSH([Fortran])
190+
AC_LINK_IFELSE([AC_LANG_SOURCE([[ program falignment
191+
CHARACTER A,B
192+
COMMON /AA/A
193+
COMMON /BB/B
194+
OPEN(UNIT=10, FILE="conftestval")
195+
if (LOC(A) > LOC(B)) then
196+
write (10,'(I5)') LOC(A)-LOC(B)
197+
else
198+
write (10,'(I5)') LOC(B)-LOC(A)
199+
endif
200+
CLOSE(10)
201+
202+
end program]])],
203+
[AS_IF([test "$cross_compiling" = "yes"],
204+
[AC_MSG_ERROR([Can not determine common alignment when cross-compiling])],
205+
[OPAL_LOG_COMMAND([./conftest],
206+
[AS_VAR_SET(ompi_cv_fortran_common_alignment, [`cat conftestval`])],
207+
[AC_MSG_ERROR([Could not determine common alignment])])])],
208+
209+
[AC_MSG_WARN([Could not determine common alignment])
210+
AC_MSG_WARN([See config.log for details])
211+
AC_MSG_ERROR([Cannot continue])])
212+
rm -rf conftest* *.mod 2> /dev/null
213+
AC_LANG_POP([Fortran])])
214+
215+
AS_VAR_COPY([$1], [ompi_cv_fortran_common_alignment])],
216+
[AC_MSG_CHECKING([Fortran common alignment])
217+
$1=0
218+
AC_MSG_RESULT([skipped])])
219+
220+
])dnl

config/ompi_setup_mpi_fortran.m4

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dnl Copyright (c) 2006-2008 Sun Microsystems, Inc. All rights reserved.
1515
dnl Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights
1616
dnl reserved.
1717
dnl Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
18-
dnl Copyright (c) 2014-2021 Research Organization for Information Science
18+
dnl Copyright (c) 2014-2025 Research Organization for Information Science
1919
dnl and Technology (RIST). All rights reserved.
2020
dnl Copyright (c) 2016-2022 IBM Corporation. All rights reserved.
2121
dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
@@ -138,6 +138,9 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[
138138
AC_DEFINE([ompi_fortran_bogus_type_t], [int],
139139
[A bogus type that allows us to have sentinel type values that are still valid])
140140

141+
OMPI_FORTRAN_GET_COMMON_ALIGNMENT([OMPI_FORTRAN_COMMON_ALIGNMENT])
142+
AC_SUBST([OMPI_FORTRAN_COMMON_ALIGNMENT])
143+
141144
# We want to set the #define's for all of these, so invoke the macros
142145
# regardless of whether we have F77 support or not.
143146
OMPI_FORTRAN_CHECK([CHARACTER], [yes],

ompi/include/Makefile.am

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# All rights reserved.
1212
# Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved.
1313
# Copyright (c) 2009-2011 Oak Ridge National Labs. All rights reserved.
14-
# Copyright (c) 2014-2021 Research Organization for Information Science
14+
# Copyright (c) 2014-2025 Research Organization for Information Science
1515
# and Technology (RIST). All rights reserved.
1616
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
1717
# Copyright (c) 2022 IBM Corporation. All rights reserved.
@@ -110,7 +110,10 @@ mpif-c-constants-decl.h:
110110
--caps $(OMPI_FORTRAN_CAPS) \
111111
--plain $(OMPI_FORTRAN_PLAIN) \
112112
--single $(OMPI_FORTRAN_SINGLE_UNDERSCORE) \
113-
--double $(OMPI_FORTRAN_DOUBLE_UNDERSCORE)
113+
--double $(OMPI_FORTRAN_DOUBLE_UNDERSCORE) \
114+
--status-size $(OMPI_FORTRAN_STATUS_SIZE) \
115+
--align $(OMPI_FORTRAN_COMMON_ALIGNMENT)
116+
114117

115118
if WANT_INSTALL_HEADERS
116119
ompidir = $(ompiincludedir)

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

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env perl
22
#
3-
# Copyright (c) 2015 Research Organization for Information Science
3+
# Copyright (c) 2015-2025 Research Organization for Information Science
44
# and Technology (RIST). All rights reserved.
55
# Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
66
# $COPYRIGHT$
@@ -16,17 +16,21 @@
1616
my $plain_arg;
1717
my $single_underscore_arg;
1818
my $double_underscore_arg;
19+
my $status_size_arg;
20+
my $align_arg;
1921
my $help_arg = 0;
2022

2123
&Getopt::Long::Configure("bundling");
2224
my $ok = Getopt::Long::GetOptions("caps=i" => \$caps_arg,
2325
"plain=i" => \$plain_arg,
2426
"single=i" => \$single_underscore_arg,
2527
"double=i" => \$double_underscore_arg,
28+
"status-size=i" => \$status_size_arg,
29+
"align=i" => \$align_arg,
2630
"help|h" => \$help_arg);
2731

2832
if ($help_arg || !$ok) {
29-
print "Usage: $0 [--caps|--plain|--single|--double] [--help]\n";
33+
print "Usage: $0 [--caps|--plain|--single|--double] --status-size=<MPI_STATUS_SIZE> [--align=<alignment>] [--help]\n";
3034
exit(1 - $ok);
3135
}
3236

@@ -50,25 +54,25 @@
5054
my $fortran;
5155

5256
$fortran->{bottom} = {
53-
c_type => "int",
57+
c_type => "MPI_Fint",
5458
c_name => "mpi_fortran_bottom",
5559
f_type => "integer",
5660
f_name => "MPI_BOTTOM",
5761
};
5862
$fortran->{in_place} = {
59-
c_type => "int",
63+
c_type => "MPI_Fint",
6064
c_name => "mpi_fortran_in_place",
6165
f_type => "integer",
6266
f_name => "MPI_IN_PLACE",
6367
};
6468
$fortran->{unweighted} = {
65-
c_type => "int",
69+
c_type => "MPI_Fint",
6670
c_name => "mpi_fortran_unweighted",
6771
f_type => "integer, dimension(1)",
6872
f_name => "MPI_UNWEIGHTED",
6973
};
7074
$fortran->{weights_empty} = {
71-
c_type => "int",
75+
c_type => "MPI_Fint",
7276
c_name => "mpi_fortran_weights_empty",
7377
f_type => "integer, dimension(1)",
7478
f_name => "MPI_WEIGHTS_EMPTY",
@@ -88,19 +92,21 @@
8892
};
8993

9094
$fortran->{errcodes_ignore} = {
91-
c_type => "int",
95+
c_type => "MPI_Fint",
9296
c_name => "mpi_fortran_errcodes_ignore",
9397
f_type => "integer, dimension(1)",
9498
f_name => "MPI_ERRCODES_IGNORE",
9599
};
96100
$fortran->{status_ignore} = {
97-
c_type => "int *",
101+
c_type => "MPI_Fint",
102+
c_dim => "[$status_size_arg]",
98103
c_name => "mpi_fortran_status_ignore",
99104
f_type => "type(MPI_STATUS)",
100105
f_name => "MPI_STATUS_IGNORE",
101106
};
102107
$fortran->{statuses_ignore} = {
103-
c_type => "int *",
108+
c_type => "MPI_Fint",
109+
c_dim => "[$status_size_arg]",
104110
c_name => "mpi_fortran_statuses_ignore",
105111
f_type => "type(MPI_STATUS)",
106112
f_name => "MPI_STATUSES_IGNORE(1)",
@@ -130,7 +136,7 @@ sub gen_c_constants_decl {
130136

131137
print OUT "/* WARNING: This is a generated file! Edits will be lost! */
132138
/*
133-
* Copyright (c) 2015 Research Organization for Information Science
139+
* Copyright (c) 2015-2025 Research Organization for Information Science
134140
* and Technology (RIST). All rights reserved.
135141
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
136142
* \$COPYRIGHT\$
@@ -146,7 +152,7 @@ sub gen_c_constants_decl {
146152
foreach my $key (sort(keys(%{$fortran}))) {
147153
my $f = $fortran->{$key};
148154
my $m = mangle($f->{c_name});
149-
print OUT "extern $f->{c_type} $m;
155+
print OUT "extern $f->{c_type} $m $f->{c_dim};
150156
#define OMPI_IS_FORTRAN_" . uc($key) . "(addr) \\
151157
(addr == (void*) &$m)\n\n";
152158
}
@@ -160,7 +166,7 @@ sub gen_c_constants {
160166

161167
print OUT "/* WARNING: This is a generated file! Edits will be lost! */
162168
/*
163-
* Copyright (c) 2015 Research Organization for Information Science
169+
* Copyright (c) 2015-2025 Research Organization for Information Science
164170
* and Technology (RIST). All rights reserved.
165171
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
166172
* \$COPYRIGHT\$
@@ -171,7 +177,9 @@ sub gen_c_constants {
171177
foreach my $key (sort(keys(%{$fortran}))) {
172178
my $f = $fortran->{$key};
173179
my $m = mangle($f->{c_name});
174-
print OUT "$f->{c_type} $m;\n";
180+
my $align = "";
181+
$align = "__opal_attribute_aligned__($align_arg)" if ($align_arg > 0);
182+
print OUT "$f->{c_type} $align $m $f->{c_dim};\n";
175183
}
176184

177185
close (OUT);

0 commit comments

Comments
 (0)