Skip to content

Commit 9a05dd7

Browse files
committed
fortran/use-mpi-f08: add support for Fortran 2018 ISO_Fortran_binding.h
add the infrastructuce and update MPI_Send() and MPI_Recv() Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent 0a446b0 commit 9a05dd7

18 files changed

+394
-29
lines changed

config/ompi_config_files.m4

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- shell-script -*-
22
#
33
# Copyright (c) 2009-2017 Cisco Systems, Inc. All rights reserved
4-
# Copyright (c) 2017-2018 Research Organization for Information Science
5-
# and Technology (RIST). All rights reserved.
4+
# Copyright (c) 2017-2019 Research Organization for Information Science
5+
# and Technology (RIST). All rights reserved.
66
# Copyright (c) 2018 Los Alamos National Security, LLC. All rights
77
# reserved.
88
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
@@ -38,6 +38,7 @@ AC_DEFUN([OMPI_CONFIG_FILES],[
3838
ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr-file-interfaces.h
3939
ompi/mpi/fortran/use-mpi-f08/Makefile
4040
ompi/mpi/fortran/use-mpi-f08/bindings/Makefile
41+
ompi/mpi/fortran/use-mpi-f08/cdesc/Makefile
4142
ompi/mpi/fortran/use-mpi-f08/mod/Makefile
4243
ompi/mpi/fortran/mpiext-use-mpi/Makefile
4344
ompi/mpi/fortran/mpiext-use-mpi-f08/Makefile
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
dnl -*- shell-script -*-
2+
dnl
3+
dnl Copyright (c) 2019 Research Organization for Information Science
4+
dnl and Technology (RIST). All rights reserved.
5+
dnl $COPYRIGHT$
6+
dnl
7+
dnl Additional copyrights may follow
8+
dnl
9+
dnl $HEADER$
10+
dnl
11+
12+
# Check whether or not the C compiler supports ISO Fortran binding
13+
#
14+
# OMPI_FORTRAN_CHECK_ISO_FORTRAN_BINDING([action if found], [action if not found])
15+
# ----------------------------------------------------
16+
AC_DEFUN([OMPI_FORTRAN_CHECK_ISO_FORTRAN_BINDING],[
17+
AC_CHECK_HEADERS([ISO_Fortran_binding.h], [$1], [$2])
18+
])

config/ompi_setup_mpi_fortran.m4

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ 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-2017 Research Organization for Information Science
19-
dnl and Technology (RIST). All rights reserved.
18+
dnl Copyright (c) 2014-2019 Research Organization for Information Science
19+
dnl and Technology (RIST). All rights reserved.
2020
dnl Copyright (c) 2016 IBM Corporation. All rights reserved.
2121
dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
2222
dnl $COPYRIGHT$
@@ -558,6 +558,12 @@ end type test_mpi_handle],
558558
])
559559
])
560560

561+
OMPI_FORTRAN_HAVE_C_ISO_FORTRAN=0
562+
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
563+
test $OMPI_BUILD_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
564+
[OMPI_FORTRAN_CHECK_ISO_FORTRAN_BINDING([OMPI_FORTRAN_HAVE_C_ISO_FORTRAN=1],
565+
[OMPI_FORTRAN_HAVE_C_ISO_FORTRAN=0])])
566+
561567
# Note: the current implementation *only* has wrappers;
562568
# there is no optimized implementation for a "good"
563569
# compiler. I'm leaving the above logic in place for
@@ -580,6 +586,8 @@ end type test_mpi_handle],
580586
AS_IF([test $OMPI_MIN_REQUIRED_FORTRAN_BINDINGS -gt $OMPI_BUILD_FORTRAN_BINDINGS],
581587
[AC_MSG_ERROR([Cannot build requested Fortran bindings, aborting])])
582588

589+
AC_CONFIG_FILES([ompi/mpi/fortran/use-mpi-f08/bindings/mpi-f-interfaces-bind.h])
590+
583591
# -------------------
584592
# mpif.h final setup
585593
# -------------------
@@ -798,6 +806,20 @@ end type test_mpi_handle],
798806
# For configure-fortran-output.h
799807
AC_SUBST(OMPI_FORTRAN_HAVE_BIND_C)
800808

809+
AM_CONDITIONAL(OMPI_FORTRAN_HAVE_C_ISO_FORTRAN,
810+
[test $OMPI_FORTRAN_HAVE_C_ISO_FORTRAN -eq 1])
811+
812+
AS_IF([test $OMPI_FORTRAN_HAVE_C_ISO_FORTRAN -eq 1],
813+
[OMPI_F08_IGNORE_TKR_TYPE="type(*), dimension(..)"
814+
OMPI_F08_GCC_ATTRIBUTES=
815+
OMPI_F08_BINDINGS_EXTENSION="cdesc"],
816+
[OMPI_F08_IGNORE_TKR_TYPE=$OMPI_FORTRAN_IGNORE_TKR_TYPE
817+
OMPI_F08_GCC_ATTRIBUTES='!GCC$ ATTRIBUTES NO_ARG_CHECK :: buf'
818+
OMPI_F08_BINDINGS_EXTENSION="f"])
819+
AC_SUBST(OMPI_F08_IGNORE_TKR_TYPE)
820+
AC_SUBST(OMPI_F08_GCC_ATTRIBUTES)
821+
AC_SUBST(OMPI_F08_BINDINGS_EXTENSION)
822+
801823
# Somewhat redundant because ompi/Makefile.am won't traverse into
802824
# ompi/mpi/fortran/use-mpi-f08 if it's not to be built, but we
803825
# might as well have ompi/mpi/fortran/use-mpi-f08/Makefile.am be

ompi/Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights
1616
# reserved.
1717
# Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
18-
# Copyright (c) 2015-2018 Research Organization for Information Science
19-
# and Technology (RIST). All rights reserved.
18+
# Copyright (c) 2015-2019 Research Organization for Information Science
19+
# and Technology (RIST). All rights reserved.
2020
# Copyright (c) 2016 IBM Corporation. All rights reserved.
2121
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
2222
# $COPYRIGHT$
@@ -94,6 +94,7 @@ SUBDIRS = \
9494
mpi/fortran/mpiext-use-mpi \
9595
mpi/fortran/use-mpi-f08/mod \
9696
mpi/fortran/use-mpi-f08/bindings \
97+
mpi/fortran/use-mpi-f08/cdesc \
9798
$(OMPI_MPIEXT_USEMPIF08_DIRS) \
9899
mpi/fortran/use-mpi-f08 \
99100
mpi/fortran/mpiext-use-mpi-f08 \
@@ -126,6 +127,7 @@ DIST_SUBDIRS = \
126127
mpi/fortran/use-mpi-f08 \
127128
mpi/fortran/use-mpi-f08/mod \
128129
mpi/fortran/use-mpi-f08/bindings \
130+
mpi/fortran/use-mpi-f08/cdesc \
129131
mpi/fortran/mpiext-use-mpi-f08 \
130132
mpi/java \
131133
$(OMPI_MPIEXT_ALL_SUBDIRS) \

ompi/mpi/fortran/configure-fortran-output.h.in

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
! Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved.
44
! Copyright (c) 2009-2012 Los Alamos National Security, LLC.
55
! All rights reserved.
6-
! Copyright (c) 2017-2018 Research Organization for Information Science
7-
! and Technology (RIST). All rights reserved.
6+
! Copyright (c) 2017-2019 Research Organization for Information Science
7+
! and Technology (RIST). All rights reserved.
88
!
99
! $COPYRIGHT$
1010
!
@@ -46,6 +46,11 @@
4646
! Line 2 of the ignore TKR syntax
4747
#define OMPI_FORTRAN_IGNORE_TKR_TYPE @OMPI_FORTRAN_IGNORE_TKR_TYPE@
4848
49+
#define OMPI_F08_IGNORE_TKR_TYPE @OMPI_F08_IGNORE_TKR_TYPE@
50+
51+
#define OMPI_F08_BINDINGS_EXTENSION @OMPI_F08_BINDINGS_EXTENSION@
52+
53+
#define OMPI_F08_GCC_ATTRIBUTES(buf) @OMPI_F08_GCC_ATTRIBUTES@
4954
5055
#define OMPI_FORTRAN_BUILD_SIZEOF @OMPI_FORTRAN_BUILD_SIZEOF@
5156
! Integers

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# Copyright (c) 2012-2013 Inria. All rights reserved.
88
# Copyright (c) 2013-2018 Los Alamos National Security, LLC. All rights
99
# reserved.
10-
# Copyright (c) 2015-2018 Research Organization for Information Science
11-
# and Technology (RIST). All rights reserved.
10+
# Copyright (c) 2015-2019 Research Organization for Information Science
11+
# and Technology (RIST). All rights reserved.
1212
# Copyright (c) 2016 IBM Corporation. All rights reserved.
1313
# Copyright (c) 2017-2018 FUJITSU LIMITED. All rights reserved.
1414
# Copyright (c) 2019 Triad National Security, LLC. All rights
@@ -32,6 +32,7 @@ AM_FCFLAGS = -I$(top_builddir)/ompi/include \
3232
$(OMPI_FC_MODULE_FLAG)$(top_builddir)/ompi/$(OMPI_FORTRAN_USEMPI_DIR) \
3333
$(OMPI_FC_MODULE_FLAG)mod \
3434
$(OMPI_FC_MODULE_FLAG)bindings \
35+
$(OMPI_FC_MODULE_FLAG)cdesc \
3536
-I$(top_srcdir) $(FCFLAGS_f90)
3637

3738
MOSTLYCLEANFILES = *.mod
@@ -44,6 +45,11 @@ module_sentinel_file = \
4445
mod/libforce_usempif08_internal_modules_to_be_built.la \
4546
bindings/libforce_usempif08_internal_bindings_to_be_built.la
4647

48+
if OMPI_FORTRAN_HAVE_C_ISO_FORTRAN
49+
module_sentinel_file += \
50+
cdesc/libforce_usempif08_internal_cdesc_to_be_built.la
51+
endif
52+
4753
mpi-f08.lo: $(module_sentinel_file)
4854
mpi-f08.lo: mpi-f08.F90
4955
mpi-f08.lo: sizeof_f08.h

ompi/mpi/fortran/use-mpi-f08/bindings/mpi-f-interfaces-bind.h renamed to ompi/mpi/fortran/use-mpi-f08/bindings/mpi-f-interfaces-bind.h.in

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
! of Tennessee Research Foundation. All rights
88
! reserved.
99
! Copyright (c) 2012 Inria. All rights reserved.
10-
! Copyright (c) 2015-2018 Research Organization for Information Science
10+
! Copyright (c) 2015-2019 Research Organization for Information Science
1111
! and Technology (RIST). All rights reserved.
1212
! $COPYRIGHT$
1313
!
@@ -287,10 +287,10 @@ subroutine ompi_probe_f(source,tag,comm,status,ierror) &
287287
end subroutine ompi_probe_f
288288

289289
subroutine ompi_recv_f(buf,count,datatype,source,tag,comm,status,ierror) &
290-
BIND(C, name="ompi_recv_f")
290+
BIND(C, name="ompi_recv_@OMPI_F08_BINDINGS_EXTENSION@")
291291
use :: mpi_f08_types, only : MPI_Status
292292
implicit none
293-
OMPI_FORTRAN_IGNORE_TKR_TYPE :: buf
293+
OMPI_F08_IGNORE_TKR_TYPE :: buf
294294
INTEGER, INTENT(IN) :: count, source, tag
295295
INTEGER, INTENT(IN) :: datatype
296296
INTEGER, INTENT(IN) :: comm
@@ -338,9 +338,9 @@ subroutine ompi_rsend_init_f(buf,count,datatype,dest,tag,comm,request,ierror) &
338338
end subroutine ompi_rsend_init_f
339339

340340
subroutine ompi_send_f(buf,count,datatype,dest,tag,comm,ierror) &
341-
BIND(C, name="ompi_send_f")
341+
BIND(C, name="ompi_send_@OMPI_F08_BINDINGS_EXTENSION@")
342342
implicit none
343-
OMPI_FORTRAN_IGNORE_TKR_TYPE, INTENT(IN) :: buf
343+
OMPI_F08_IGNORE_TKR_TYPE, INTENT(IN) :: buf
344344
INTEGER, INTENT(IN) :: count, dest, tag
345345
INTEGER, INTENT(IN) :: datatype
346346
INTEGER, INTENT(IN) :: comm
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*- makefile -*-
2+
#
3+
# Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved.
4+
# Copyright (c) 2012-2013 The University of Tennessee and The University
5+
# of Tennessee Research Foundation. All rights
6+
# reserved.
7+
# Copyright (c) 2012-2013 Inria. All rights reserved.
8+
# Copyright (c) 2013 Los Alamos National Security, LLC. All rights
9+
# reserved.
10+
# Copyright (c) 2015-2019 Research Organization for Information Science
11+
# and Technology (RIST). All rights reserved.
12+
# Copyright (c) 2016 IBM Corporation. All rights reserved.
13+
#
14+
# $COPYRIGHT$
15+
#
16+
# Additional copyrights may follow
17+
#
18+
# $HEADER$
19+
#
20+
21+
include $(top_srcdir)/Makefile.ompi-rules
22+
23+
# This Makefile is only relevant if we're building the "use mpi_f08"
24+
# MPI bindings.
25+
if OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS
26+
27+
AM_CPPFLAGS = -DOMPI_COMPILING_FORTRAN_WRAPPERS=1
28+
29+
###########################################################################
30+
31+
module_sentinel_file =
32+
if OMPI_FORTRAN_HAVE_C_ISO_FORTRAN
33+
module_sentinel_file += \
34+
libforce_usempif08_internal_cdesc_to_be_built.la
35+
endif
36+
37+
noinst_LTLIBRARIES = $(module_sentinel_file)
38+
39+
# f08 support modules
40+
41+
libforce_usempif08_internal_cdesc_to_be_built_la_SOURCES = \
42+
bindings.h \
43+
cdesc.h \
44+
cdesc.c \
45+
recv_cdesc.c \
46+
send_cdesc.c
47+
48+
endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2019 Research Organization for Information Science
3+
* and Technology (RIST). All rights reserved.
4+
* $COPYRIGHT$
5+
*
6+
* Additional copyrights may follow
7+
*
8+
* $HEADER$
9+
*/
10+
11+
#ifndef OMPI_CDESC_BINDINGS_H
12+
#define OMPI_CDESC_BINDINGS_H
13+
14+
#include "cdesc.h"
15+
16+
#include "ompi_config.h"
17+
18+
#include "mpi.h"
19+
20+
void ompi_recv_cdesc(CFI_cdesc_t *x, MPI_Fint *count, MPI_Fint *datatype,
21+
MPI_Fint *source, MPI_Fint *tag, MPI_Fint *comm,
22+
MPI_Fint *status, MPI_Fint *ierr);
23+
24+
void ompi_send_cdesc(CFI_cdesc_t* x, MPI_Fint *count, MPI_Fint *datatype,
25+
MPI_Fint *dest, MPI_Fint *tag, MPI_Fint *comm, MPI_Fint *ierr);
26+
27+
28+
#endif /* OMPI_CDESC_BINDINGS_H */
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; -*- */
2+
/*
3+
* Copyright (c) 2014 Argonne National Laboratory.
4+
* Copyright (c) 2019 Research Organization for Information Science
5+
* and Technology (RIST). All rights reserved.
6+
* $COPYRIGHT$
7+
*
8+
* Additional copyrights may follow
9+
*
10+
* $HEADER$
11+
*/
12+
13+
#include "cdesc.h"
14+
15+
int cdesc_create_datatype(CFI_cdesc_t *cdesc, int oldcount, MPI_Datatype oldtype, MPI_Datatype *newtype)
16+
{
17+
const int MAX_RANK = 15; /* Fortran 2008 specifies a maximum rank of 15 */
18+
MPI_Datatype types[MAX_RANK + 1]; /* Use a fixed size array to avoid malloc. + 1 for oldtype */
19+
int mpi_errno = MPI_SUCCESS;
20+
int accum_elems = 1;
21+
int accum_sm = cdesc->elem_len;
22+
int done = 0; /* Have we created a datatype for oldcount of oldtype? */
23+
int last; /* Index of the last successfully created datatype in types[] */
24+
int extent;
25+
int i, j;
26+
27+
#ifdef OPAL_ENABLE_DEBUG
28+
{
29+
int size;
30+
assert(cdesc->rank <= MAX_RANK);
31+
ompi_datatype_size(oldtype, &size);
32+
/* When cdesc->elem_len != size, things suddenly become complicated. Generally, it is hard to create
33+
* a composite datatype based on two datatypes. Currently we don't support it and doubt it is usefull.
34+
*/
35+
assert(cdesc->elem_len == size);
36+
}
37+
#endif
38+
39+
types[0] = oldtype;
40+
i = 0;
41+
done = 0;
42+
while (i < cdesc->rank && !done) {
43+
if (oldcount % accum_elems) {
44+
/* oldcount should be a multiple of accum_elems, otherwise we might need an
45+
* MPI indexed datatype to describle the irregular region, which is not supported yet.
46+
*/
47+
mpi_errno = MPI_ERR_INTERN;
48+
goto fn_fail;
49+
}
50+
51+
extent = oldcount / accum_elems;
52+
if (extent > cdesc->dim[i].extent) {
53+
extent = cdesc->dim[i].extent;
54+
} else {
55+
/* Up to now, we have accumlated enough elements */
56+
done = 1;
57+
}
58+
59+
if (cdesc->dim[i].sm == accum_sm) {
60+
mpi_errno = PMPI_Type_contiguous(extent, types[i], &types[i+1]);
61+
} else {
62+
mpi_errno = PMPI_Type_create_hvector(extent, 1, cdesc->dim[i].sm, types[i], &types[i+1]);
63+
}
64+
if (mpi_errno != MPI_SUCCESS) {
65+
last = i; goto fn_fail;
66+
}
67+
68+
mpi_errno = PMPI_Type_commit(&types[i+1]);
69+
if (mpi_errno != MPI_SUCCESS) {
70+
last = i + 1; goto fn_fail;
71+
}
72+
73+
accum_sm = cdesc->dim[i].sm * cdesc->dim[i].extent;
74+
accum_elems *= cdesc->dim[i].extent;
75+
i++;
76+
}
77+
78+
if (done) {
79+
*newtype = types[i];
80+
last = i - 1; /* To avoid freeing newtype */
81+
} else {
82+
/* If # of elements given by "oldcount oldtype" is bigger than
83+
* what cdesc describles, then we will reach here.
84+
*/
85+
last = i;
86+
mpi_errno = MPI_ERR_ARG;
87+
goto fn_fail;
88+
}
89+
90+
fn_exit:
91+
for (j = 1; j <= last; j++)
92+
PMPI_Type_free(&types[j]);
93+
return mpi_errno;
94+
fn_fail:
95+
goto fn_exit;
96+
}

0 commit comments

Comments
 (0)