Skip to content

Commit 52bbd5f

Browse files
committed
Add missing MPI_Status conversion subroutines
Only in C bindings: - MPI_Status_c2f08() - MPI_Status_f082c() In all bindings but mpif.h - MPI_Status_f082f() - MPI_Status_f2f08() and the PMPI_* related subroutines As initially inteded by the MPI forum, the Fortran to/from Fortran 2008 conversion subtoutines are *not* implemented in the mpif.h bindings. See the discussion at mpi-forum/mpi-issues#298 Refs. open-mpi#1475 Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>
1 parent a876ef6 commit 52bbd5f

33 files changed

+886
-53
lines changed

config/ompi_setup_mpi_fortran.m4

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[
387387
[OMPI_TRY_FORTRAN_BINDINGS=$OMPI_FORTRAN_MPIFH_BINDINGS
388388
AC_MSG_RESULT([no])])
389389

390+
OMPI_FORTRAN_CHECK_BIND_C_TYPE(
391+
[OMPI_FORTRAN_HAVE_BIND_C_TYPE=1],
392+
[OMPI_FORTRAN_HAVE_BIND_C_TYPE=0])
393+
390394
#---------------------------------
391395
# Fortran use mpi_f08 MPI bindings
392396
#---------------------------------
@@ -422,14 +426,11 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[
422426
[OMPI_FORTRAN_HAVE_BIND_C_SUB=0
423427
OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPI_BINDINGS])])
424428

425-
OMPI_FORTRAN_HAVE_BIND_C_TYPE=0
426429
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
427430
test $OMPI_BUILD_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
428431
[ # If we don't have TYPE, BIND(C), we won't build mpi_f08 at all
429-
OMPI_FORTRAN_CHECK_BIND_C_TYPE(
430-
[OMPI_FORTRAN_HAVE_BIND_C_TYPE=1],
431-
[OMPI_FORTRAN_HAVE_BIND_C_TYPE=0
432-
OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPI_BINDINGS])])
432+
AS_IF([test $OMPI_FORTRAN_HAVE_BIND_C_TYPE -ne 1],
433+
[OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPI_BINDINGS])])
433434

434435
# Per discussion on the devel list starting here:
435436
# https://www.open-mpi.org/community/lists/devel/2014/01/13799.php
@@ -701,6 +702,17 @@ end type test_mpi_handle],
701702
AM_CONDITIONAL(OMPI_BUILD_FORTRAN_USEMPI_IGNORE_TKR_BINDINGS,
702703
[test $OMPI_BUILD_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPI_BINDINGS && \
703704
test $OMPI_FORTRAN_HAVE_IGNORE_TKR -eq 1])
705+
# True if we support TYPE, BIND(C)
706+
AC_DEFINE_UNQUOTED(OMPI_FORTRAN_HAVE_BIND_C_TYPE,
707+
[$OMPI_FORTRAN_HAVE_BIND_C_TYPE],
708+
[For ompi_info: Whether the compiler supports TYPE, BIND(C) or not])
709+
AC_SUBST(OMPI_FORTRAN_HAVE_BIND_C_TYPE)
710+
711+
# For mpif-status.h, configure-fortran-output.h, mpi-f08-types.F90 (and ompi_info)
712+
AC_SUBST([OMPI_FORTRAN_HAVE_PRIVATE])
713+
AC_DEFINE_UNQUOTED([OMPI_FORTRAN_HAVE_PRIVATE],
714+
[$OMPI_FORTRAN_HAVE_PRIVATE],
715+
[For mpif-status.h, mpi-f08-types.f90 and ompi_info: whether the compiler supports the "private" keyword or not (used in MPI_Status)])
704716

705717
# -------------------
706718
# use mpi_f08 final setup
@@ -749,22 +761,13 @@ end type test_mpi_handle],
749761
AC_DEFINE_UNQUOTED(OMPI_FORTRAN_HAVE_BIND_C_SUB,
750762
[$OMPI_FORTRAN_HAVE_BIND_C_SUB],
751763
[For ompi_info: Whether the compiler supports SUBROUTINE ... BIND(C) or not])
752-
AC_DEFINE_UNQUOTED(OMPI_FORTRAN_HAVE_BIND_C_TYPE,
753-
[$OMPI_FORTRAN_HAVE_BIND_C_TYPE],
754-
[For ompi_info: Whether the compiler supports TYPE, BIND(C) or not])
755764
AC_DEFINE_UNQUOTED(OMPI_FORTRAN_HAVE_BIND_C_TYPE_NAME,
756765
[$OMPI_FORTRAN_HAVE_BIND_C_TYPE_NAME],
757766
[For ompi_info: Whether the compiler supports TYPE, BIND(C, NAME="name") or not])
758767
AC_DEFINE_UNQUOTED([OMPI_FORTRAN_HAVE_OPTIONAL_ARGS],
759768
[$OMPI_FORTRAN_HAVE_OPTIONAL_ARGS],
760769
[For ompi_info: whether the Fortran compiler supports optional arguments or not])
761770

762-
# For configure-fortran-output.h, mpi-f08-types.F90 (and ompi_info)
763-
AC_SUBST([OMPI_FORTRAN_HAVE_PRIVATE])
764-
AC_DEFINE_UNQUOTED([OMPI_FORTRAN_HAVE_PRIVATE],
765-
[$OMPI_FORTRAN_HAVE_PRIVATE],
766-
[For mpi-f08-types.f90 and ompi_info: whether the compiler supports the "private" keyword or not (used in MPI_Status)])
767-
768771
# For configure-fortran-output.h, mpi-f08-interfaces-callbacks.F90
769772
# (and ompi_info)
770773
AC_SUBST([OMPI_FORTRAN_HAVE_ABSTRACT])

ompi/include/Makefile.am

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
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-2015 Research Organization for Information Science
15-
# and Technology (RIST). All rights reserved.
14+
# Copyright (c) 2014-2020 Research Organization for Information Science
15+
# and Technology (RIST). All rights reserved.
1616
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
1717
# $COPYRIGHT$
1818
#
@@ -54,6 +54,7 @@ nodist_include_HEADERS = \
5454
mpif.h \
5555
mpif-ext.h \
5656
mpif-sizeof.h \
57+
mpif-status.h \
5758
mpif-c-constants-decl.h \
5859
mpi_portable_platform.h
5960

@@ -92,6 +93,18 @@ mpif-sizeof.h:
9293
--complex4=$(OMPI_HAVE_FORTRAN_COMPLEX4) \
9394
--complex32=$(OMPI_HAVE_FORTRAN_COMPLEX32)
9495

96+
#
97+
# mpif-status.h is generated based on some results from configure tests.
98+
#
99+
100+
status_pl=$(top_srcdir)/ompi/mpi/fortran/base/gen-mpi-status.pl
101+
mpif-status.h: $(top_builddir)/config.status
102+
mpif-status.h: $(sizeof_pl)
103+
mpif-status.h:
104+
$(OMPI_V_GEN) $(status_pl) \
105+
--mpi_status=$(OMPI_FORTRAN_HAVE_BIND_C_TYPE) \
106+
--private=$(OMPI_FORTRAN_HAVE_PRIVATE)
107+
95108
#
96109
# mpif-c-constants-decl.h, among other files, is generated based on some
97110
# results from configure tests.
@@ -124,6 +137,7 @@ CLEANFILES = mpif-sizeof.f90
124137
distclean-local:
125138
rm -f mpi-ext.h mpif-ext.h mpi_portable_platform.h \
126139
mpif-sizeof.h \
140+
mpif-status.h \
127141
mpif-c-constants-decl.h mpif-c-constants.h mpif-f08-types.h
128142

129143
mpi_portable_platform.h: $(top_srcdir)/opal/include/opal/opal_portable_platform.h

ompi/include/mpi.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ typedef struct ompi_op_t *MPI_Op;
411411
typedef struct ompi_request_t *MPI_Request;
412412
typedef struct ompi_message_t *MPI_Message;
413413
typedef struct ompi_status_public_t MPI_Status;
414+
typedef struct ompi_f08_status_public_t MPI_F08_status;
414415
typedef struct ompi_win_t *MPI_Win;
415416
typedef struct mca_base_var_enum_t *MPI_T_enum;
416417
typedef struct ompi_mpit_cvar_handle_t *MPI_T_cvar_handle;
@@ -1779,7 +1780,11 @@ OMPI_DECLSPEC int MPI_Ssend(const void *buf, int count, MPI_Datatype datatype,
17791780
OMPI_DECLSPEC int MPI_Start(MPI_Request *request);
17801781
OMPI_DECLSPEC int MPI_Startall(int count, MPI_Request array_of_requests[]);
17811782
OMPI_DECLSPEC int MPI_Status_c2f(const MPI_Status *c_status, MPI_Fint *f_status);
1783+
OMPI_DECLSPEC int MPI_Status_c2f08(const MPI_Status *c_status, MPI_F08_status *f08_status);
1784+
OMPI_DECLSPEC int MPI_Status_f082c(const MPI_F08_status *f08_status, MPI_Status *c_status);
1785+
OMPI_DECLSPEC int MPI_Status_f082f(const MPI_F08_status *f08_status, MPI_Fint *f_status);
17821786
OMPI_DECLSPEC int MPI_Status_f2c(const MPI_Fint *f_status, MPI_Status *c_status);
1787+
OMPI_DECLSPEC int MPI_Status_f2f08(const MPI_Fint *f_status, MPI_F08_status *f08_status);
17831788
OMPI_DECLSPEC int MPI_Status_set_cancelled(MPI_Status *status, int flag);
17841789
OMPI_DECLSPEC int MPI_Status_set_elements(MPI_Status *status, MPI_Datatype datatype,
17851790
int count);
@@ -2440,7 +2445,11 @@ OMPI_DECLSPEC int PMPI_Ssend(const void *buf, int count, MPI_Datatype datatype,
24402445
OMPI_DECLSPEC int PMPI_Start(MPI_Request *request);
24412446
OMPI_DECLSPEC int PMPI_Startall(int count, MPI_Request array_of_requests[]);
24422447
OMPI_DECLSPEC int PMPI_Status_c2f(const MPI_Status *c_status, MPI_Fint *f_status);
2448+
OMPI_DECLSPEC int PMPI_Status_c2f08(const MPI_Status *c_status, MPI_F08_status *f08_status);
2449+
OMPI_DECLSPEC int PMPI_Status_f082f(const MPI_F08_status *f08_status, MPI_Fint *f_status);
2450+
OMPI_DECLSPEC int PMPI_Status_f082c(const MPI_F08_status *f08_status, MPI_Status *c_status);
24432451
OMPI_DECLSPEC int PMPI_Status_f2c(const MPI_Fint *f_status, MPI_Status *c_status);
2452+
OMPI_DECLSPEC int PMPI_Status_f2f08(const MPI_Fint *f_status, MPI_F08_status *f08_status);
24442453
OMPI_DECLSPEC int PMPI_Status_set_cancelled(MPI_Status *status, int flag);
24452454
OMPI_DECLSPEC int PMPI_Status_set_elements(MPI_Status *status, MPI_Datatype datatype,
24462455
int count);

ompi/mpi/c/Makefile.am

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# Copyright (c) 2012-2013 Inria. All rights reserved.
1616
# Copyright (c) 2013-2018 Los Alamos National Security, LLC. All rights
1717
# reserved.
18-
# Copyright (c) 2015-2018 Research Organization for Information Science
19-
# and Technology (RIST). All rights reserved.
18+
# Copyright (c) 2015-2020 Research Organization for Information Science
19+
# and Technology (RIST). All rights reserved.
2020
# $COPYRIGHT$
2121
#
2222
# Additional copyrights may follow
@@ -339,7 +339,11 @@ libmpi_c_mpi_la_SOURCES = \
339339
start.c \
340340
startall.c \
341341
status_c2f.c \
342+
status_c2f08.c \
343+
status_f082c.c \
344+
status_f082f.c \
342345
status_f2c.c \
346+
status_f2f08.c \
343347
status_set_cancelled.c \
344348
status_set_elements.c \
345349
status_set_elements_x.c \

ompi/mpi/c/profile/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ nodist_libmpi_c_pmpi_la_SOURCES = \
319319
pstart.c \
320320
pstartall.c \
321321
pstatus_c2f.c \
322+
pstatus_c2f08.c \
323+
pstatus_f082c.c \
324+
pstatus_f082f.c \
325+
pstatus_f2f08.c \
322326
pstatus_f2c.c \
323327
pstatus_set_cancelled.c \
324328
pstatus_set_elements.c \

ompi/mpi/c/status_c2f08.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2004-2007 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-2008 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) 2010-2012 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
15+
* reserved.
16+
* Copyright (c) 2015-2020 Research Organization for Information Science
17+
* and Technology (RIST). All rights reserved.
18+
* $COPYRIGHT$
19+
*
20+
* Additional copyrights may follow
21+
*
22+
* $HEADER$
23+
*/
24+
#include "ompi_config.h"
25+
#include <stdio.h>
26+
27+
#include "ompi/mpi/c/bindings.h"
28+
#include "ompi/runtime/params.h"
29+
#include "ompi/communicator/communicator.h"
30+
#include "ompi/errhandler/errhandler.h"
31+
#include "ompi/mpi/fortran/base/fint_2_int.h"
32+
#include "ompi/mpi/fortran/base/constants.h"
33+
#include "ompi/memchecker.h"
34+
35+
#if OMPI_BUILD_MPI_PROFILING
36+
#if OPAL_HAVE_WEAK_SYMBOLS
37+
#pragma weak MPI_Status_c2f08 = PMPI_Status_c2f08
38+
#endif
39+
#define MPI_Status_c2f08 PMPI_Status_c2f08
40+
#endif
41+
42+
static const char FUNC_NAME[] = "MPI_Status_c2f08";
43+
44+
45+
int MPI_Status_c2f08(const MPI_Status *c_status, MPI_F08_status *f08_status)
46+
{
47+
const int *c_ints;
48+
MEMCHECKER(
49+
if(c_status != MPI_STATUSES_IGNORE) {
50+
/*
51+
* Before checking the complete status, we need to reset the definedness
52+
* of the MPI_ERROR-field (single-completion calls wait/test).
53+
*/
54+
opal_memchecker_base_mem_defined((void*)&c_status->MPI_ERROR, sizeof(int));
55+
memchecker_status(c_status);
56+
}
57+
);
58+
59+
OPAL_CR_NOOP_PROGRESS();
60+
61+
if (MPI_PARAM_CHECK) {
62+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
63+
64+
/* MPI-2:4.12.5 says that if you pass in
65+
MPI_STATUS[ES]_IGNORE, it's erroneous */
66+
67+
if (NULL == c_status || MPI_STATUS_IGNORE == c_status ||
68+
MPI_STATUSES_IGNORE == c_status || NULL == f08_status) {
69+
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD,
70+
MPI_ERR_IN_STATUS, FUNC_NAME);
71+
}
72+
}
73+
74+
/* ***NOTE*** See huge comment in status_c2f.c (yes, I know
75+
there's a size_t member in the C MPI_Status -- go
76+
read that comment for an explanation why copying
77+
everything as a bunch of int's is ok). */
78+
f08_status->MPI_SOURCE = OMPI_INT_2_FINT(c_status->MPI_SOURCE);
79+
f08_status->MPI_TAG = OMPI_INT_2_FINT(c_status->MPI_TAG);
80+
f08_status->MPI_ERROR = OMPI_INT_2_FINT(c_status->MPI_ERROR);
81+
c_ints = (const int *)c_status + 3;
82+
for(int i = 0; i < (int)(sizeof(MPI_Status) / sizeof(int) - 3); i++ )
83+
f08_status->internal[i] = OMPI_INT_2_FINT(c_ints[i]);
84+
85+
return MPI_SUCCESS;
86+
}

ompi/mpi/c/status_f082c.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2004-2007 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) 2010-2012 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
15+
* reserved.
16+
* Copyright (c) 2015-2020 Research Organization for Information Science
17+
* and Technology (RIST). All rights reserved.
18+
* $COPYRIGHT$
19+
*
20+
* Additional copyrights may follow
21+
*
22+
* $HEADER$
23+
*/
24+
#include "ompi_config.h"
25+
26+
#include "ompi/mpi/c/bindings.h"
27+
#include "ompi/runtime/params.h"
28+
#include "ompi/communicator/communicator.h"
29+
#include "ompi/errhandler/errhandler.h"
30+
#include "ompi/mpi/fortran/base/fint_2_int.h"
31+
#include "ompi/mpi/fortran/base/constants.h"
32+
33+
#if OMPI_BUILD_MPI_PROFILING
34+
#if OPAL_HAVE_WEAK_SYMBOLS
35+
#pragma weak MPI_Status_f082c = PMPI_Status_f082c
36+
#endif
37+
#define MPI_Status_f082c PMPI_Status_f082c
38+
#endif
39+
40+
static const char FUNC_NAME[] = "MPI_Status_f082c";
41+
42+
43+
int MPI_Status_f082c(const MPI_F08_status *f08_status, MPI_Status *c_status)
44+
{
45+
int *c_ints;
46+
OPAL_CR_NOOP_PROGRESS();
47+
48+
if (MPI_PARAM_CHECK) {
49+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
50+
51+
/* MPI-2:4.12.5 says that if you pass in
52+
MPI_STATUS[ES]_IGNORE, it's erroneous */
53+
54+
if (NULL == f08_status ||
55+
#if OMPI_BUILD_FORTRAN_BINDINGS
56+
/* This section is #if'ed out if we are not building the
57+
fortran bindings because these macros check values
58+
against constants that only exist if the fortran
59+
bindings exist. */
60+
OMPI_IS_FORTRAN_STATUS_IGNORE(f08_status) ||
61+
OMPI_IS_FORTRAN_STATUSES_IGNORE(f08_status) ||
62+
#endif
63+
NULL == c_status) {
64+
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD,
65+
MPI_ERR_IN_STATUS, FUNC_NAME);
66+
}
67+
}
68+
69+
/* ***NOTE*** See huge comment in status_c2f.c (yes, I know
70+
there's a size_t member in the C MPI_Status -- go
71+
read that comment for an explanation why copying
72+
everything as a bunch of int's is ok).
73+
74+
We can't use OMPI_FINT_2_INT here because of some complications
75+
with include files. :-( So just do the casting manually. */
76+
c_status->MPI_SOURCE = (int)f08_status->MPI_SOURCE;
77+
c_status->MPI_TAG = (int)f08_status->MPI_TAG;
78+
c_status->MPI_ERROR = (int)f08_status->MPI_ERROR;
79+
c_ints = (int *)c_status + 3;
80+
for(int i=0; i < (int)(sizeof(MPI_Status) / sizeof(int) - 3); i++)
81+
c_ints[i] = (int)f08_status->internal[i];
82+
83+
return MPI_SUCCESS;
84+
}

0 commit comments

Comments
 (0)