Skip to content

Commit 6c2aa8e

Browse files
committed
add comm_from/toint
simpler to hard code abi/ompi variants. For ABI version add an offset to the values normally used for original "f2c/c2f" ops to push the values normally returned by "c2f" functions to be greater than any ABI defined constants. Signed-off-by: Howard Pritchard <[email protected]>
1 parent 40fffb9 commit 6c2aa8e

File tree

8 files changed

+246
-0
lines changed

8 files changed

+246
-0
lines changed

ompi/include/mpi.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ OMPI_DECLSPEC int MPI_Comm_idup_with_info(MPI_Comm comm, MPI_Info info, MPI_Com
16421642
OMPI_DECLSPEC MPI_Comm MPI_Comm_f2c(MPI_Fint comm);
16431643
OMPI_DECLSPEC int MPI_Comm_free_keyval(int *comm_keyval);
16441644
OMPI_DECLSPEC int MPI_Comm_free(MPI_Comm *comm);
1645+
OMPI_DECLSPEC MPI_Comm MPI_Comm_fromint(int comm);
16451646
OMPI_DECLSPEC int MPI_Comm_get_attr(MPI_Comm comm, int comm_keyval,
16461647
void *attribute_val, int *flag);
16471648
OMPI_DECLSPEC int MPI_Dist_graph_create(MPI_Comm comm_old, int n, const int nodes[],
@@ -1695,6 +1696,7 @@ OMPI_DECLSPEC int MPI_Comm_spawn_multiple(int count, char *array_of_commands[],
16951696
OMPI_DECLSPEC int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm);
16961697
OMPI_DECLSPEC int MPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm);
16971698
OMPI_DECLSPEC int MPI_Comm_test_inter(MPI_Comm comm, int *flag);
1699+
OMPI_DECLSPEC int MPI_Comm_toint(MPI_Comm comm);
16981700
OMPI_DECLSPEC int MPI_Compare_and_swap(const void *origin_addr, const void *compare_addr,
16991701
void *result_addr, MPI_Datatype datatype, int target_rank,
17001702
MPI_Aint target_disp, MPI_Win win);
@@ -2820,6 +2822,7 @@ OMPI_DECLSPEC int PMPI_Comm_idup_with_info(MPI_Comm comm, MPI_Info info, MPI_Co
28202822
OMPI_DECLSPEC MPI_Comm PMPI_Comm_f2c(MPI_Fint comm);
28212823
OMPI_DECLSPEC int PMPI_Comm_free_keyval(int *comm_keyval);
28222824
OMPI_DECLSPEC int PMPI_Comm_free(MPI_Comm *comm);
2825+
OMPI_DECLSPEC MPI_Comm PMPI_Comm_fromint(int comm);
28232826
OMPI_DECLSPEC int PMPI_Comm_get_attr(MPI_Comm comm, int comm_keyval,
28242827
void *attribute_val, int *flag);
28252828
OMPI_DECLSPEC int PMPI_Dist_graph_create(MPI_Comm comm_old, int n, const int nodes[],
@@ -2873,6 +2876,7 @@ OMPI_DECLSPEC int PMPI_Comm_spawn_multiple(int count, char *array_of_commands[]
28732876
OMPI_DECLSPEC int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm);
28742877
OMPI_DECLSPEC int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm);
28752878
OMPI_DECLSPEC int PMPI_Comm_test_inter(MPI_Comm comm, int *flag);
2879+
OMPI_DECLSPEC int PMPI_Comm_toint(MPI_Comm comm);
28762880
OMPI_DECLSPEC int PMPI_Compare_and_swap(const void *origin_addr, const void *compare_addr,
28772881
void *result_addr, MPI_Datatype datatype, int target_rank,
28782882
MPI_Aint target_disp, MPI_Win win);

ompi/mpi/c/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ endif
552552
# have to deal manually
553553
#
554554
extra_interface_profile_sources = \
555+
comm_fromint_ompi.c \
556+
comm_toint_ompi.c \
555557
pcontrol.c \
556558
wtick.c
557559

ompi/mpi/c/Makefile_abi.include

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ extra_abi_fns = \
4949
abi_get_version.c \
5050
aint_add_abi.c \
5151
aint_diff_abi.c \
52+
comm_fromint_abi.c \
53+
comm_toint_abi.c \
5254
pcontrol.c \
5355
wtick.c
5456

ompi/mpi/c/abi_converters.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
extern "C" {
1515
#endif
1616

17+
/*
18+
* see section 20.3.4 of the MPI 5.0 standard
19+
*/
20+
#define OMPI_ABI_HANDLE_BASE_OFFSET 16384
21+
1722
__opal_attribute_always_inline__ static inline int ompi_convert_abi_error_intern_error(int error_class)
1823
{
1924
switch (error_class) {

ompi/mpi/c/comm_fromint_abi.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND. */
2+
/* -*- Mode: C; c-basic-offset:4 ; -*- */
3+
/*
4+
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
5+
* University Research and Technology
6+
* Corporation. All rights reserved.
7+
* Copyright (c) 2004-2007 The University of Tennessee and The University
8+
* of Tennessee Research Foundation. All rights
9+
* reserved.
10+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
11+
* University of Stuttgart. All rights reserved.
12+
* Copyright (c) 2004-2005 The Regents of the University of California.
13+
* All rights reserved.
14+
* Copyright (c) 2006-2012 Cisco Systems, Inc. All rights reserved.
15+
* Copyright (c) 2015 Research Organization for Information Science
16+
* and Technology (RIST). All rights reserved.
17+
* Copyright (c) 2024-2025 Triad National Security, LLC. All rights
18+
* reserved.
19+
* $COPYRIGHT$
20+
*
21+
* Additional copyrights may follow
22+
*
23+
* $HEADER$
24+
*/
25+
#include "ompi_config.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+
32+
#include "ompi/mpi/c/abi.h"
33+
#include "ompi/mpi/c/abi_converters.h"
34+
35+
#if OMPI_BUILD_MPI_PROFILING
36+
#if OPAL_HAVE_WEAK_SYMBOLS
37+
#pragma weak MPI_Comm_fromint = PMPI_Comm_fromint
38+
#endif
39+
#define MPI_Comm_fromint PMPI_Comm_fromint
40+
#endif
41+
42+
static const char FUNC_NAME[] = "MPI_Comm_fromint";
43+
44+
MPI_Comm_ABI_INTERNAL MPI_Comm_fromint(int comm)
45+
{
46+
int o_index;
47+
intptr_t comm_tmp;
48+
49+
if ( MPI_PARAM_CHECK ) {
50+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
51+
}
52+
53+
comm_tmp = (intptr_t)comm;
54+
if (MPI_COMM_SELF_ABI_INTERNAL >= (MPI_Comm_ABI_INTERNAL)comm_tmp) {
55+
return (MPI_Comm_ABI_INTERNAL)comm_tmp;
56+
}
57+
58+
o_index = comm - OMPI_ABI_HANDLE_BASE_OFFSET;
59+
60+
return (MPI_Comm_ABI_INTERNAL)opal_pointer_array_get_item(&ompi_comm_f_to_c_table, o_index);
61+
}

ompi/mpi/c/comm_fromint_ompi.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND. */
2+
/* -*- Mode: C; c-basic-offset:4 ; -*- */
3+
/*
4+
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
5+
* University Research and Technology
6+
* Corporation. All rights reserved.
7+
* Copyright (c) 2004-2007 The University of Tennessee and The University
8+
* of Tennessee Research Foundation. All rights
9+
* reserved.
10+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
11+
* University of Stuttgart. All rights reserved.
12+
* Copyright (c) 2004-2005 The Regents of the University of California.
13+
* All rights reserved.
14+
* Copyright (c) 2006-2012 Cisco Systems, Inc. All rights reserved.
15+
* Copyright (c) 2015 Research Organization for Information Science
16+
* and Technology (RIST). All rights reserved.
17+
* Copyright (c) 2024-2025 Triad National Security, LLC. All rights
18+
* reserved.
19+
* $COPYRIGHT$
20+
*
21+
* Additional copyrights may follow
22+
*
23+
* $HEADER$
24+
*/
25+
#include "ompi_config.h"
26+
27+
#include "ompi/runtime/params.h"
28+
#include "ompi/communicator/communicator.h"
29+
#include "ompi/errhandler/errhandler.h"
30+
31+
#if OMPI_BUILD_MPI_PROFILING
32+
#if OPAL_HAVE_WEAK_SYMBOLS
33+
#pragma weak MPI_Comm_fromint = PMPI_Comm_fromint
34+
#endif
35+
#define MPI_Comm_fromint PMPI_Comm_fromint
36+
#endif
37+
38+
static const char FUNC_NAME[] = "MPI_Comm_fromint";
39+
40+
MPI_Comm MPI_Comm_fromint(int comm)
41+
{
42+
int o_index;
43+
if ( MPI_PARAM_CHECK ) {
44+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
45+
}
46+
47+
o_index = comm;
48+
49+
return (MPI_Comm)opal_pointer_array_get_item(&ompi_comm_f_to_c_table, o_index);
50+
}

ompi/mpi/c/comm_toint_abi.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND. */
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) 2006-2012 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2015 Research Organization for Information Science
15+
* and Technology (RIST). All rights reserved.
16+
* Copyright (c) 2024-2025 Triad National Security, LLC. All rights
17+
* 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+
31+
#include "ompi/mpi/c/abi.h"
32+
#include "ompi/mpi/c/abi_converters.h"
33+
34+
#if OMPI_BUILD_MPI_PROFILING
35+
#if OPAL_HAVE_WEAK_SYMBOLS
36+
#pragma weak MPI_Comm_toint = PMPI_Comm_toint
37+
#endif
38+
#define MPI_Comm_toint PMPI_Comm_toint
39+
#endif
40+
41+
static const char FUNC_NAME[] = "MPI_Comm_toint";
42+
43+
int MPI_Comm_toint(MPI_Comm_ABI_INTERNAL comm)
44+
{
45+
int o_index;
46+
ompi_communicator_t *comm_ptr;
47+
MPI_Comm comm_tmp;
48+
49+
if ( MPI_PARAM_CHECK ) {
50+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
51+
comm_tmp = ompi_convert_abi_comm_intern_comm(comm);
52+
if (ompi_comm_invalid(comm_tmp)) {
53+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_COMM, FUNC_NAME);
54+
}
55+
}
56+
57+
if (MPI_COMM_SELF_ABI_INTERNAL >= (MPI_Comm_ABI_INTERNAL)comm) {
58+
intptr_t comm_int = (intptr_t)comm;
59+
return (int)(comm_int & (OMPI_ABI_HANDLE_BASE_OFFSET-1));
60+
}
61+
62+
comm_ptr = (ompi_communicator_t *)comm;
63+
o_index = comm_ptr->c_f_to_c_index;
64+
o_index += OMPI_ABI_HANDLE_BASE_OFFSET;
65+
66+
return o_index;
67+
}

ompi/mpi/c/comm_toint_ompi.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND. */
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) 2006-2012 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2015 Research Organization for Information Science
15+
* and Technology (RIST). All rights reserved.
16+
* Copyright (c) 2024 Triad National Security, LLC. All rights
17+
* 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+
31+
#if OMPI_BUILD_MPI_PROFILING
32+
#if OPAL_HAVE_WEAK_SYMBOLS
33+
#pragma weak MPI_Comm_toint = PMPI_Comm_toint
34+
#endif
35+
#define MPI_Comm_toint PMPI_Comm_toint
36+
#endif
37+
38+
static const char FUNC_NAME[] = "MPI_Comm_toint";
39+
40+
int MPI_Comm_toint(MPI_Comm comm)
41+
{
42+
int o_index;
43+
44+
if ( MPI_PARAM_CHECK ) {
45+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
46+
if (ompi_comm_invalid(comm)) {
47+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_COMM, FUNC_NAME);
48+
}
49+
}
50+
51+
o_index = comm->c_f_to_c_index;
52+
53+
return o_index;
54+
55+
}

0 commit comments

Comments
 (0)