Skip to content

Commit 09504c3

Browse files
committed
basic implementation of MPI_TYPE_GET_VALUE_INDEX
We only support named types with this first pass. related to open-mpi#12076 Fortran interfaces will be added once Fortran infrastructure additions in PR open-mpi#13279 are merged in to main. Signed-off-by: Howard Pritchard <[email protected]>
1 parent 91539d0 commit 09504c3

File tree

9 files changed

+164
-1
lines changed

9 files changed

+164
-1
lines changed

docs/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ OMPI_MAN3 = \
518518
MPI_Type_get_name.3 \
519519
MPI_Type_get_true_extent.3 \
520520
MPI_Type_get_true_extent_x.3 \
521+
MPI_Type_get_value_index.3 \
521522
MPI_Type_hindexed.3 \
522523
MPI_Type_hvector.3 \
523524
MPI_Type_indexed.3 \
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. _mpi_type_get_value_index:
2+
3+
4+
MPI_Type_get_value_index
5+
========================
6+
7+
.. include_body
8+
9+
:ref:`MPI_Type_get_value_index` |mdash| Returns a reference (handle) to one of the predefined
10+
datatypes suitable for the use with MPI_MINLOC and MPI_MAXLOC if such predefined type
11+
exists.
12+
13+
.. The following file was automatically generated
14+
.. include:: ./bindings/mpi_type_get_value_index.rst
15+
16+
INPUT PARAMETERS
17+
----------------
18+
* ``value_type``: Datatype of the value in pair (handle)
19+
* ``index_type``: Datatype of the index in pair (handle)
20+
21+
OUTPUT PARAMETERS
22+
-----------------
23+
* ``pair_type``: Datatype of the value-index pair (handle)
24+
* ``ierror``: Fortran only: Error status (integer).
25+
26+
DESCRIPTION
27+
-----------
28+
29+
:ref:`MPI_Type_get_value_index` Returns a reference (handle) to one of the predefined
30+
datatypes suitable for the use with MPI_MINLOC and MPI_MAXLOC if such predefined type
31+
exists.
32+
33+
ERRORS
34+
------
35+
36+
.. include:: ./ERRORS.rst

docs/man-openmpi/man3/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ MPI API manual pages (section 3)
443443
MPI_Type_get_name.3.rst
444444
MPI_Type_get_true_extent.3.rst
445445
MPI_Type_get_true_extent_x.3.rst
446+
MPI_Type_get_value_index.3.rst
446447
MPI_Type_hindexed.3.rst
447448
MPI_Type_hvector.3.rst
448449
MPI_Type_indexed.3.rst

ompi/datatype/ompi_datatype.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ OMPI_DECLSPEC int ompi_datatype_unpack_external( const char datarep[], const voi
389389
OMPI_DECLSPEC int ompi_datatype_pack_external_size( const char datarep[], size_t incount,
390390
ompi_datatype_t *datatype, MPI_Aint *size);
391391

392+
OMPI_DECLSPEC int ompi_datatype_get_value_index(const ompi_datatype_t *value_type,
393+
const ompi_datatype_t *index_type,
394+
ompi_datatype_t **pair_type);
395+
392396
#define OMPI_DATATYPE_RETAIN(ddt) \
393397
{ \
394398
if( !ompi_datatype_is_predefined((ddt)) ) { \

ompi/datatype/ompi_datatype_create.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
1212
* Copyright (c) 2010-2018 Cisco Systems, Inc. All rights reserved
1313
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
14+
* Copyright (c) 2025 Triad National Security, LLC. All rights
15+
* reserved.
1416
* $COPYRIGHT$
1517
*
1618
* Additional copyrights may follow
@@ -27,6 +29,7 @@
2729
#include "opal/util/printf.h"
2830
#include "opal/util/string_copy.h"
2931
#include "ompi/datatype/ompi_datatype.h"
32+
#include "ompi/datatype/ompi_datatype_internal.h"
3033
#include "ompi/attribute/attribute.h"
3134

3235
static void __ompi_datatype_allocate( ompi_datatype_t* datatype )
@@ -121,3 +124,54 @@ ompi_datatype_duplicate( const ompi_datatype_t* oldType, ompi_datatype_t** newTy
121124
return OMPI_SUCCESS;
122125
}
123126

127+
/*
128+
* Note this is not a complete implementation for the MPI_Type_get_value_index function described in
129+
* MPI 4.1 and newer as it doesn't support possible unnamed datatypes returned for other value_type/index_type
130+
* pairs.
131+
*/
132+
int
133+
ompi_datatype_get_value_index(const ompi_datatype_t *value_type, const ompi_datatype_t *index_type, ompi_datatype_t **pair_type)
134+
{
135+
/* C predefined data types */
136+
if (index_type->id == OMPI_DATATYPE_MPI_INT) {
137+
if (value_type->id == OMPI_DATATYPE_MPI_FLOAT) {
138+
*pair_type = (ompi_datatype_t *)&ompi_mpi_float_int;
139+
} else if (value_type->id == OMPI_DATATYPE_MPI_DOUBLE) {
140+
*pair_type = (ompi_datatype_t *)&ompi_mpi_double_int;
141+
} else if (value_type->id == OMPI_DATATYPE_MPI_LONG) {
142+
*pair_type = (ompi_datatype_t *)&ompi_mpi_long_int;
143+
} else if (value_type->id == OMPI_DATATYPE_MPI_SHORT) {
144+
*pair_type = (ompi_datatype_t *)&ompi_mpi_short_int;
145+
} else if (value_type->id == OMPI_DATATYPE_MPI_INT) {
146+
*pair_type = (ompi_datatype_t *)&ompi_mpi_2int;
147+
} else if (value_type->id == OMPI_DATATYPE_MPI_LONG_DOUBLE) {
148+
*pair_type = (ompi_datatype_t *)&ompi_mpi_longdbl_int;
149+
} else {
150+
*pair_type = (ompi_datatype_t *)&ompi_mpi_datatype_null;
151+
}
152+
/* Fortran predefined data types */
153+
} else if ((index_type->id == OMPI_DATATYPE_MPI_INTEGER) &&
154+
(value_type->id == OMPI_DATATYPE_MPI_INTEGER)) {
155+
*pair_type = (ompi_datatype_t *)&ompi_mpi_2integer;
156+
} else if ((index_type->id == OMPI_DATATYPE_MPI_FLOAT) &&
157+
(value_type->id == OMPI_DATATYPE_MPI_FLOAT)) {
158+
*pair_type = (ompi_datatype_t *)&ompi_mpi_2real;
159+
} else if ((index_type->id == OMPI_DATATYPE_MPI_DOUBLE) &&
160+
(value_type->id == OMPI_DATATYPE_MPI_DOUBLE)) {
161+
*pair_type = (ompi_datatype_t *)&ompi_mpi_2dblprec;
162+
#if OMPI_HAVE_FORTRAN_COMPLEX
163+
} else if ((index_type->id == OMPI_DATATYPE_MPI_COMPLEX) &&
164+
(value_type->id == OMPI_DATATYPE_MPI_COMPLEX)) {
165+
*pair_type = (ompi_datatype_t *)&ompi_mpi_2cplex;
166+
#endif
167+
#if OMPI_HAVE_FORTRAN_DOUBLE_COMPLEX
168+
} else if ((index_type->id == OMPI_DATATYPE_MPI_DOUBLE_COMPLEX) &&
169+
(value_type->id == OMPI_DATATYPE_MPI_DOUBLE_COMPLEX)) {
170+
*pair_type = (ompi_datatype_t *)&ompi_mpi_2dblcplex;
171+
#endif
172+
} else {
173+
*pair_type = (ompi_datatype_t *)&ompi_mpi_datatype_null;
174+
}
175+
176+
return OMPI_SUCCESS;
177+
}

ompi/include/mpi.h.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ enum {
826826
MPI_COMBINER_F90_COMPLEX,
827827
MPI_COMBINER_F90_INTEGER,
828828
MPI_COMBINER_RESIZED,
829-
MPI_COMBINER_HINDEXED_BLOCK
829+
MPI_COMBINER_HINDEXED_BLOCK,
830+
MPI_COMBINER_VALUE_INDEX
830831
};
831832

832833
#if (OMPI_OMIT_MPI1_COMPAT_DECLS)
@@ -2501,6 +2502,8 @@ OMPI_DECLSPEC int MPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint *tru
25012502
MPI_Aint *true_extent);
25022503
OMPI_DECLSPEC int MPI_Type_get_true_extent_c(MPI_Datatype datatype, MPI_Count *true_lb,
25032504
MPI_Count *true_extent);
2505+
OMPI_DECLSPEC int MPI_Type_get_value_index(MPI_Datatype value_type, MPI_Datatype index_type,
2506+
MPI_Datatype *pair_type);
25042507
OMPI_DECLSPEC int MPI_Type_indexed(int count, const int array_of_blocklengths[],
25052508
const int array_of_displacements[],
25062509
MPI_Datatype oldtype, MPI_Datatype *newtype);
@@ -3658,6 +3661,8 @@ OMPI_DECLSPEC int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint *tr
36583661
MPI_Aint *true_extent);
36593662
OMPI_DECLSPEC int PMPI_Type_get_true_extent_c(MPI_Datatype datatype, MPI_Count *true_lb,
36603663
MPI_Count *true_extent);
3664+
OMPI_DECLSPEC int PMPI_Type_get_value_index(MPI_Datatype value_type, MPI_Datatype index_type,
3665+
MPI_Datatype *pair_type);
36613666
OMPI_DECLSPEC int PMPI_Type_indexed(int count, const int array_of_blocklengths[],
36623667
const int array_of_displacements[],
36633668
MPI_Datatype oldtype, MPI_Datatype *newtype);

ompi/include/mpif-values.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# reserved.
1010
# Copyright (c) 2022 IBM Corporation. All rights reserved.
1111
# Copyright (c) 2025 Jeffrey M. Squyres. All rights reserved.
12+
# Copyright (c) 2025 Triad National Security, LLC. All rights
13+
# reserved.
1214
# $COPYRIGHT$
1315
#
1416
# Additional copyrights may follow
@@ -320,6 +322,7 @@
320322
'MPI_COMBINER_F90_INTEGER': 16,
321323
'MPI_COMBINER_RESIZED': 17,
322324
'MPI_COMBINER_HINDEXED_BLOCK': 18,
325+
'MPI_COMBINER_VALUE_INDEX': 19,
323326
'MPI_COMM_TYPE_SHARED': 0,
324327
'OMPI_COMM_TYPE_HWTHREAD': 1,
325328
'OMPI_COMM_TYPE_CORE': 2,

ompi/mpi/c/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ prototype_sources = \
427427
type_get_name.c.in \
428428
type_get_true_extent.c.in \
429429
type_get_true_extent_x.c.in \
430+
type_get_value_index.c.in \
430431
type_indexed.c.in \
431432
type_match_size.c.in \
432433
type_set_attr.c.in \

ompi/mpi/c/type_get_value_index.c.in

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3+
* University Research and Technology
4+
* Corporation. All rights reserved.
5+
* Copyright (c) 2004-2020 The University of Tennessee and The University
6+
* of Tennessee Research Foundation. All rights
7+
* reserved.
8+
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
9+
* University of Stuttgart. All rights reserved.
10+
* Copyright (c) 2004-2005 The Regents of the University of California.
11+
* All rights reserved.
12+
* Copyright (c) 2015 Research Organization for Information Science
13+
* and Technology (RIST). All rights reserved.
14+
* Copyright (c) 2024-2025 Triad National Security, LLC. All rights
15+
* reserved.
16+
* $COPYRIGHT$
17+
*
18+
* Additional copyrights may follow
19+
*
20+
* $HEADER$
21+
*/
22+
23+
#include "ompi_config.h"
24+
25+
#include "ompi/mpi/c/bindings.h"
26+
#include "ompi/runtime/params.h"
27+
#include "ompi/communicator/communicator.h"
28+
#include "ompi/errhandler/errhandler.h"
29+
#include "ompi/datatype/ompi_datatype.h"
30+
#include "ompi/attribute/attribute.h"
31+
#include "ompi/memchecker.h"
32+
33+
PROTOTYPE ERROR_CLASS type_get_value_index(DATATYPE value_type,
34+
DATATYPE index_type,
35+
DATATYPE_OUT pair_type)
36+
{
37+
int ret;
38+
39+
MEMCHECKER(
40+
memchecker_datatype(type);
41+
);
42+
43+
if( MPI_PARAM_CHECK ) {
44+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
45+
if (NULL == value_type || MPI_DATATYPE_NULL == value_type ||
46+
NULL == index_type || MPI_DATATYPE_NULL == index_type ||
47+
NULL == pair_type) {
48+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_TYPE,
49+
FUNC_NAME );
50+
}
51+
}
52+
53+
if (OMPI_SUCCESS != (ret = ompi_datatype_get_value_index( value_type, index_type, pair_type))) {
54+
OMPI_ERRHANDLER_NOHANDLE_RETURN( ret, ret, FUNC_NAME );
55+
}
56+
57+
return MPI_SUCCESS;
58+
}

0 commit comments

Comments
 (0)