Skip to content

fortran: fix common symbol sizes and alignments #13230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions config/ompi_fortran_get_alignment.m4
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
dnl University of Stuttgart. All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl All rights reserved.
dnl Copyright (c) 2025 Research Organization for Information Science
dnl and Technology (RIST). All rights reserved.
dnl Copyright (c) 2010-2012 Cisco Systems, Inc. All rights reserved.
dnl $COPYRIGHT$
dnl
Expand Down Expand Up @@ -178,3 +180,41 @@ end program]])],
AS_VAR_COPY([$2], [type_var])
AS_VAR_POPDEF([type_var])dnl
])dnl

# OMPI_FORTRAN_GET_COMMON_ALIGNMENT(variable to set)
# ------------------------------------------
AC_DEFUN([OMPI_FORTRAN_GET_COMMON_ALIGNMENT],[
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -gt $OMPI_FORTRAN_NO_BINDINGS],
[AC_CACHE_CHECK([alignment of Fortran common], ompi_cv_fortran_common_alignment,
[AC_LANG_PUSH([Fortran])
AC_LINK_IFELSE([AC_LANG_SOURCE([[ program falignment
CHARACTER A,B
COMMON /AA/A
COMMON /BB/B
OPEN(UNIT=10, FILE="conftestval")
if (LOC(A) > LOC(B)) then
write (10,'(I5)') LOC(A)-LOC(B)
else
write (10,'(I5)') LOC(B)-LOC(A)
endif
CLOSE(10)

end program]])],
[AS_IF([test "$cross_compiling" = "yes"],
[AC_MSG_ERROR([Can not determine common alignment when cross-compiling])],
[OPAL_LOG_COMMAND([./conftest],
[AS_VAR_SET(ompi_cv_fortran_common_alignment, [`cat conftestval`])],
[AC_MSG_ERROR([Could not determine common alignment])])])],

[AC_MSG_WARN([Could not determine common alignment])
AC_MSG_WARN([See config.log for details])
AC_MSG_ERROR([Cannot continue])])
rm -rf conftest* *.mod 2> /dev/null
AC_LANG_POP([Fortran])])

AS_VAR_COPY([$1], [ompi_cv_fortran_common_alignment])],
[AC_MSG_CHECKING([Fortran common alignment])
$1=0
AC_MSG_RESULT([skipped])])

])dnl
5 changes: 4 additions & 1 deletion config/ompi_setup_mpi_fortran.m4
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dnl Copyright (c) 2006-2008 Sun Microsystems, Inc. All rights reserved.
dnl Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights
dnl reserved.
dnl Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
dnl Copyright (c) 2014-2021 Research Organization for Information Science
dnl Copyright (c) 2014-2025 Research Organization for Information Science
dnl and Technology (RIST). All rights reserved.
dnl Copyright (c) 2016-2022 IBM Corporation. All rights reserved.
dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
Expand Down Expand Up @@ -138,6 +138,9 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[
AC_DEFINE([ompi_fortran_bogus_type_t], [int],
[A bogus type that allows us to have sentinel type values that are still valid])

OMPI_FORTRAN_GET_COMMON_ALIGNMENT([OMPI_FORTRAN_COMMON_ALIGNMENT])
AC_SUBST([OMPI_FORTRAN_COMMON_ALIGNMENT])

# We want to set the #define's for all of these, so invoke the macros
# regardless of whether we have F77 support or not.
OMPI_FORTRAN_CHECK([CHARACTER], [yes],
Expand Down
7 changes: 5 additions & 2 deletions ompi/include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# All rights reserved.
# Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2009-2011 Oak Ridge National Labs. All rights reserved.
# Copyright (c) 2014-2021 Research Organization for Information Science
# Copyright (c) 2014-2025 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
# Copyright (c) 2022 IBM Corporation. All rights reserved.
Expand Down Expand Up @@ -110,7 +110,10 @@ mpif-c-constants-decl.h:
--caps $(OMPI_FORTRAN_CAPS) \
--plain $(OMPI_FORTRAN_PLAIN) \
--single $(OMPI_FORTRAN_SINGLE_UNDERSCORE) \
--double $(OMPI_FORTRAN_DOUBLE_UNDERSCORE)
--double $(OMPI_FORTRAN_DOUBLE_UNDERSCORE) \
--status-size $(OMPI_FORTRAN_STATUS_SIZE) \
--align $(OMPI_FORTRAN_COMMON_ALIGNMENT)


if WANT_INSTALL_HEADERS
ompidir = $(ompiincludedir)
Expand Down
34 changes: 21 additions & 13 deletions ompi/mpi/fortran/base/gen-mpi-mangling.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env perl
#
# Copyright (c) 2015 Research Organization for Information Science
# Copyright (c) 2015-2025 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
Expand All @@ -16,17 +16,21 @@
my $plain_arg;
my $single_underscore_arg;
my $double_underscore_arg;
my $status_size_arg;
my $align_arg;
my $help_arg = 0;

&Getopt::Long::Configure("bundling");
my $ok = Getopt::Long::GetOptions("caps=i" => \$caps_arg,
"plain=i" => \$plain_arg,
"single=i" => \$single_underscore_arg,
"double=i" => \$double_underscore_arg,
"status-size=i" => \$status_size_arg,
"align=i" => \$align_arg,
"help|h" => \$help_arg);

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

Expand All @@ -50,25 +54,25 @@
my $fortran;

$fortran->{bottom} = {
c_type => "int",
c_type => "MPI_Fint",
c_name => "mpi_fortran_bottom",
f_type => "integer",
f_name => "MPI_BOTTOM",
};
$fortran->{in_place} = {
c_type => "int",
c_type => "MPI_Fint",
c_name => "mpi_fortran_in_place",
f_type => "integer",
f_name => "MPI_IN_PLACE",
};
$fortran->{unweighted} = {
c_type => "int",
c_type => "MPI_Fint",
c_name => "mpi_fortran_unweighted",
f_type => "integer, dimension(1)",
f_name => "MPI_UNWEIGHTED",
};
$fortran->{weights_empty} = {
c_type => "int",
c_type => "MPI_Fint",
c_name => "mpi_fortran_weights_empty",
f_type => "integer, dimension(1)",
f_name => "MPI_WEIGHTS_EMPTY",
Expand All @@ -88,19 +92,21 @@
};

$fortran->{errcodes_ignore} = {
c_type => "int",
c_type => "MPI_Fint",
c_name => "mpi_fortran_errcodes_ignore",
f_type => "integer, dimension(1)",
f_name => "MPI_ERRCODES_IGNORE",
};
$fortran->{status_ignore} = {
c_type => "int *",
c_type => "MPI_Fint",
c_dim => "[$status_size_arg]",
c_name => "mpi_fortran_status_ignore",
f_type => "type(MPI_STATUS)",
f_name => "MPI_STATUS_IGNORE",
};
$fortran->{statuses_ignore} = {
c_type => "int *",
c_type => "MPI_Fint",
c_dim => "[$status_size_arg]",
c_name => "mpi_fortran_statuses_ignore",
f_type => "type(MPI_STATUS)",
f_name => "MPI_STATUSES_IGNORE(1)",
Expand Down Expand Up @@ -130,7 +136,7 @@ sub gen_c_constants_decl {

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

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

close (OUT);
Expand Down