Skip to content
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

datatype: Add support for MPI_TYPECLASS_LOGICAL #12424

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions config/ompi_setup_mpi_fortran.m4
Expand Up @@ -150,14 +150,16 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[

OMPI_FORTRAN_CHECK([LOGICAL], [yes],
[char, int32_t, int, int64_t, long long, long], [-1], [yes])
OMPI_FORTRAN_CHECK([LOGICAL*1], [yes],
OMPI_FORTRAN_CHECK([LOGICAL*1], [no],
[char, int8_t, short, int32_t, int, int64_t, long long, long], [1], [yes])
OMPI_FORTRAN_CHECK([LOGICAL*2], [yes],
OMPI_FORTRAN_CHECK([LOGICAL*2], [no],
[short, int16_t, int32_t, int, int64_t, long long, long], [2], [yes])
OMPI_FORTRAN_CHECK([LOGICAL*4], [yes],
OMPI_FORTRAN_CHECK([LOGICAL*4], [no],
[int32_t, int, int64_t, long long, long], [4], [yes])
OMPI_FORTRAN_CHECK([LOGICAL*8], [yes],
OMPI_FORTRAN_CHECK([LOGICAL*8], [no],
[int, int64_t, long long, long], [8], [yes])
OMPI_FORTRAN_CHECK([LOGICAL*16], [no],
[int, int64_t, long long, long], [16], [yes])

OMPI_FORTRAN_CHECK([INTEGER], [yes],
[int32_t, int, int64_t, long long, long], [-1], [yes])
Expand Down
6 changes: 3 additions & 3 deletions docs/man-openmpi/man3/MPI_Type_match_size.3.rst
Expand Up @@ -65,9 +65,9 @@ The function returns an MPI datatype matching a local variable of type
(*typeclass*, *size*). The returned type is a reference (handle) to a
predefined named datatype, not a duplicate. This type cannot be freed.

The value of *typeclass* may be set to one of MPI_TYPECLASS_REAL,
MPI_TYPECLASS_INTEGER, or MPI_TYPECLASS_COMPLEX, corresponding to the
desired datatype.
The value of *typeclass* may be set to one of MPI_TYPECLASS_LOGICAL,
MPI_TYPECLASS_INTEGER, MPI_TYPECLASS_REAL, or MPI_TYPECLASS_COMPLEX,
corresponding to the desired datatype.

MPI_type_match_size can be used to obtain a size-specific type that
matches a Fortran numeric intrinsic type: first call :ref:`MPI_Sizeof` to
Expand Down
1 change: 1 addition & 0 deletions ompi/datatype/ompi_datatype.h
Expand Up @@ -49,6 +49,7 @@ BEGIN_C_DECLS
#define OMPI_DATATYPE_FLAG_ANALYZED 0x0400
#define OMPI_DATATYPE_FLAG_MONOTONIC 0x0800
/* Keep trace of the type of the predefined datatypes */
#define OMPI_DATATYPE_FLAG_DATA_BOOL 0x0000 /* TODO: what to do here? */
Copy link
Contributor Author

@dalcinl dalcinl Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need help here. I've run out of space for an extra bit to distinguish boolean types. Can I shift everything up to make room? Would it be OK to shift by 4 bits, such that the bitmasks are still readable in hexadecimal?

#define OMPI_DATATYPE_FLAG_DATA_INT 0x1000
#define OMPI_DATATYPE_FLAG_DATA_FLOAT 0x2000
#define OMPI_DATATYPE_FLAG_DATA_COMPLEX 0x3000
Expand Down
14 changes: 14 additions & 0 deletions ompi/datatype/ompi_datatype_internal.h
Expand Up @@ -247,6 +247,20 @@
# define OMPI_DATATYPE_MPI_LOGICAL8 OMPI_DATATYPE_MPI_UNAVAILABLE
#endif

#if OMPI_SIZEOF_FORTRAN_LOGICAL16 == OMPI_SIZEOF_FORTRAN_LOGICAL
# define OMPI_DATATYPE_MPI_LOGICAL16 OMPI_DATATYPE_MPI_LOGICAL
#elif OMPI_SIZEOF_FORTRAN_LOGICAL16 == 1
# define OMPI_DATATYPE_MPI_LOGICAL16 OMPI_DATATYPE_MPI_INT8_T
#elif OMPI_SIZEOF_FORTRAN_LOGICAL16 == 2
# define OMPI_DATATYPE_MPI_LOGICAL16 OMPI_DATATYPE_MPI_INT16_T
#elif OMPI_SIZEOF_FORTRAN_LOGICAL16 == 4
# define OMPI_DATATYPE_MPI_LOGICAL16 OMPI_DATATYPE_MPI_INT32_T
#elif OMPI_SIZEOF_FORTRAN_LOGICAL16 == 8
# define OMPI_DATATYPE_MPI_LOGICAL16 OMPI_DATATYPE_MPI_INT64_T
#else
# define OMPI_DATATYPE_MPI_LOGICAL16 OMPI_DATATYPE_MPI_UNAVAILABLE
#endif

/* INTEGER */
#if OMPI_SIZEOF_FORTRAN_INTEGER1 == OMPI_SIZEOF_FORTRAN_INTEGER
# define OMPI_DATATYPE_MPI_INTEGER1 OMPI_DATATYPE_MPI_INTEGER
Expand Down
15 changes: 10 additions & 5 deletions ompi/datatype/ompi_datatype_module.c
Expand Up @@ -179,7 +179,7 @@ ompi_predefined_datatype_t ompi_mpi_complex32 = OMPI_DATATYPE_INIT_UNAVAILA
/*
* Fortran datatypes
*/
ompi_predefined_datatype_t ompi_mpi_logical = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL, OMPI_SIZEOF_FORTRAN_LOGICAL, OMPI_ALIGNMENT_FORTRAN_LOGICAL, 0 );
ompi_predefined_datatype_t ompi_mpi_logical = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL, OMPI_SIZEOF_FORTRAN_LOGICAL, OMPI_ALIGNMENT_FORTRAN_LOGICAL, OMPI_DATATYPE_FLAG_DATA_BOOL );
ompi_predefined_datatype_t ompi_mpi_character = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, CHARACTER, 1, OPAL_ALIGNMENT_CHAR, 0 );
ompi_predefined_datatype_t ompi_mpi_integer = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, INTEGER, OMPI_SIZEOF_FORTRAN_INTEGER, OMPI_ALIGNMENT_FORTRAN_INTEGER, OMPI_DATATYPE_FLAG_DATA_INT );
ompi_predefined_datatype_t ompi_mpi_real = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (FLOAT, REAL, OMPI_SIZEOF_FORTRAN_REAL, OMPI_ALIGNMENT_FORTRAN_REAL, OMPI_DATATYPE_FLAG_DATA_FLOAT );
Expand All @@ -204,25 +204,30 @@ ompi_predefined_datatype_t ompi_mpi_2dblcplex = OMPI_DATATYPE_INIT_DEFER (2

/* For each of these we figure out, whether it is available -- otherwise it's set to unavailable */
#if OMPI_HAVE_FORTRAN_LOGICAL1
ompi_predefined_datatype_t ompi_mpi_logical1 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL1, OMPI_SIZEOF_FORTRAN_LOGICAL1, OMPI_ALIGNMENT_FORTRAN_LOGICAL1, 0);
ompi_predefined_datatype_t ompi_mpi_logical1 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL1, OMPI_SIZEOF_FORTRAN_LOGICAL1, OMPI_ALIGNMENT_FORTRAN_LOGICAL1, OMPI_DATATYPE_FLAG_DATA_BOOL);
#else
ompi_predefined_datatype_t ompi_mpi_logical1 = OMPI_DATATYPE_INIT_UNAVAILABLE (LOGICAL1, OMPI_DATATYPE_FLAG_DATA_FORTRAN );
#endif
#if OMPI_HAVE_FORTRAN_LOGICAL2
ompi_predefined_datatype_t ompi_mpi_logical2 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL2, OMPI_SIZEOF_FORTRAN_LOGICAL2, OMPI_ALIGNMENT_FORTRAN_LOGICAL2, 0);
ompi_predefined_datatype_t ompi_mpi_logical2 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL2, OMPI_SIZEOF_FORTRAN_LOGICAL2, OMPI_ALIGNMENT_FORTRAN_LOGICAL2, OMPI_DATATYPE_FLAG_DATA_BOOL);
#else
ompi_predefined_datatype_t ompi_mpi_logical2 = OMPI_DATATYPE_INIT_UNAVAILABLE (LOGICAL2, OMPI_DATATYPE_FLAG_DATA_FORTRAN );
#endif
#if OMPI_HAVE_FORTRAN_LOGICAL4
ompi_predefined_datatype_t ompi_mpi_logical4 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL4, OMPI_SIZEOF_FORTRAN_LOGICAL4, OMPI_ALIGNMENT_FORTRAN_LOGICAL4, 0);
ompi_predefined_datatype_t ompi_mpi_logical4 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL4, OMPI_SIZEOF_FORTRAN_LOGICAL4, OMPI_ALIGNMENT_FORTRAN_LOGICAL4, OMPI_DATATYPE_FLAG_DATA_BOOL);
#else
ompi_predefined_datatype_t ompi_mpi_logical4 = OMPI_DATATYPE_INIT_UNAVAILABLE (LOGICAL4, OMPI_DATATYPE_FLAG_DATA_FORTRAN );
#endif
#if OMPI_HAVE_FORTRAN_LOGICAL8
ompi_predefined_datatype_t ompi_mpi_logical8 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL8, OMPI_SIZEOF_FORTRAN_LOGICAL8, OMPI_ALIGNMENT_FORTRAN_LOGICAL8, 0);
ompi_predefined_datatype_t ompi_mpi_logical8 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL8, OMPI_SIZEOF_FORTRAN_LOGICAL8, OMPI_ALIGNMENT_FORTRAN_LOGICAL8, OMPI_DATATYPE_FLAG_DATA_BOOL);
#else
ompi_predefined_datatype_t ompi_mpi_logical8 = OMPI_DATATYPE_INIT_UNAVAILABLE (LOGICAL8, OMPI_DATATYPE_FLAG_DATA_FORTRAN );
#endif
#if OMPI_HAVE_FORTRAN_LOGICAL16
ompi_predefined_datatype_t ompi_mpi_logical16 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (INT, LOGICAL16, OMPI_SIZEOF_FORTRAN_LOGICAL16, OMPI_ALIGNMENT_FORTRAN_LOGICAL16, OMPI_DATATYPE_FLAG_DATA_BOOL);
#else
ompi_predefined_datatype_t ompi_mpi_logical16 = OMPI_DATATYPE_INIT_UNAVAILABLE (LOGICAL16, OMPI_DATATYPE_FLAG_DATA_FORTRAN );
#endif
#if OMPI_HAVE_FORTRAN_REAL2
ompi_predefined_datatype_t ompi_mpi_real2 = OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN (FLOAT, REAL2, OMPI_SIZEOF_FORTRAN_REAL2, OMPI_ALIGNMENT_FORTRAN_REAL2, OMPI_DATATYPE_FLAG_DATA_FLOAT);
#else
Expand Down
8 changes: 8 additions & 0 deletions ompi/include/mpi.h.in
Expand Up @@ -120,6 +120,9 @@
/* Whether we have FORTRAN LOGICAL*1 or not */
#undef OMPI_HAVE_FORTRAN_LOGICAL1

/* Whether we have FORTRAN LOGICAL*16 or not */
#undef OMPI_HAVE_FORTRAN_LOGICAL16

/* Whether we have FORTRAN LOGICAL*2 or not */
#undef OMPI_HAVE_FORTRAN_LOGICAL2

Expand Down Expand Up @@ -1140,6 +1143,7 @@ OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_logical1;
OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_logical2;
OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_logical4;
OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_logical8;
OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_logical16;
OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_integer1;
OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_integer2;
OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_integer4;
Expand Down Expand Up @@ -1287,6 +1291,9 @@ OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_ub;
#if OMPI_HAVE_FORTRAN_LOGICAL8
#define MPI_LOGICAL8 OMPI_PREDEFINED_GLOBAL(MPI_Datatype, ompi_mpi_logical8)
#endif
#if OMPI_HAVE_FORTRAN_LOGICAL16
#define MPI_LOGICAL16 OMPI_PREDEFINED_GLOBAL(MPI_Datatype, ompi_mpi_logical16)
#endif
#define MPI_INTEGER OMPI_PREDEFINED_GLOBAL(MPI_Datatype, ompi_mpi_integer)
#if OMPI_HAVE_FORTRAN_INTEGER1
#define MPI_INTEGER1 OMPI_PREDEFINED_GLOBAL(MPI_Datatype, ompi_mpi_integer1)
Expand Down Expand Up @@ -1374,6 +1381,7 @@ OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_ub;
#define MPI_TYPECLASS_INTEGER 1
#define MPI_TYPECLASS_REAL 2
#define MPI_TYPECLASS_COMPLEX 3
#define MPI_TYPECLASS_LOGICAL 4

/* Aint helper macros (MPI-3.1) */
#define MPI_Aint_add(base, disp) ((MPI_Aint) ((char *) (base) + (disp)))
Expand Down
2 changes: 2 additions & 0 deletions ompi/include/mpif-values.pl
Expand Up @@ -226,6 +226,7 @@ sub read_value_from_file {
$handles->{MPI_C_LONG_DOUBLE_COMPLEX} = 71;
$handles->{MPI_COUNT} = 72;
$handles->{MPI_COMPLEX4} = 73;
$handles->{MPI_LOGICAL16} = 74;

$handles->{MPI_MESSAGE_NO_PROC} = 1;

Expand Down Expand Up @@ -286,6 +287,7 @@ sub read_value_from_file {
$constants->{MPI_TYPECLASS_INTEGER} = 1;
$constants->{MPI_TYPECLASS_REAL} = 2;
$constants->{MPI_TYPECLASS_COMPLEX} = 3;
$constants->{MPI_TYPECLASS_LOGICAL} = 4;
$constants->{MPI_MODE_NOCHECK} = 1;
$constants->{MPI_MODE_NOPRECEDE} = 2;
$constants->{MPI_MODE_NOPUT} = 4;
Expand Down
3 changes: 3 additions & 0 deletions ompi/mpi/c/type_match_size.c
Expand Up @@ -54,6 +54,9 @@ int MPI_Type_match_size(int typeclass, int size, MPI_Datatype *type)
case MPI_TYPECLASS_COMPLEX:
*type = (MPI_Datatype)ompi_datatype_match_size( size, OMPI_DATATYPE_FLAG_DATA_COMPLEX, OMPI_DATATYPE_FLAG_DATA_FORTRAN );
break;
case MPI_TYPECLASS_LOGICAL:
*type = (MPI_Datatype)ompi_datatype_match_size( size, OMPI_DATATYPE_FLAG_DATA_BOOL, OMPI_DATATYPE_FLAG_DATA_FORTRAN );
break;
default:
*type = &ompi_mpi_datatype_null.dt;
}
Expand Down
3 changes: 3 additions & 0 deletions ompi/mpi/fortran/mpif-h/type_match_size_f.c
Expand Up @@ -97,6 +97,9 @@ void ompi_type_match_size_f(MPI_Fint *typeclass, MPI_Fint *size, MPI_Fint *type,
case MPI_TYPECLASS_COMPLEX:
c_type = (MPI_Datatype)ompi_datatype_match_size( c_size, OMPI_DATATYPE_FLAG_DATA_COMPLEX, OMPI_DATATYPE_FLAG_DATA_FORTRAN );
break;
case MPI_TYPECLASS_LOGICAL:
c_type = (MPI_Datatype)ompi_datatype_match_size( c_size, OMPI_DATATYPE_FLAG_DATA_BOOL, OMPI_DATATYPE_FLAG_DATA_FORTRAN );
break;
default:
c_type = &ompi_mpi_datatype_null.dt;
}
Expand Down
1 change: 1 addition & 0 deletions ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-types.F90
Expand Up @@ -154,6 +154,7 @@ module mpi_f08_types
type(MPI_Datatype), parameter :: MPI_LOGICAL2 = MPI_Datatype(OMPI_MPI_LOGICAL2)
type(MPI_Datatype), parameter :: MPI_LOGICAL4 = MPI_Datatype(OMPI_MPI_LOGICAL4)
type(MPI_Datatype), parameter :: MPI_LOGICAL8 = MPI_Datatype(OMPI_MPI_LOGICAL8)
type(MPI_Datatype), parameter :: MPI_LOGICAL16 = MPI_Datatype(OMPI_MPI_LOGICAL16)
type(MPI_Datatype), parameter :: MPI_C_BOOL = MPI_Datatype(OMPI_MPI_C_BOOL)
type(MPI_Datatype), parameter :: MPI_CXX_BOOL = MPI_Datatype(OMPI_MPI_CXX_BOOL)
type(MPI_Datatype), parameter :: MPI_COUNT = MPI_Datatype(OMPI_MPI_COUNT)
Expand Down