Skip to content

Commit 8d71197

Browse files
authored
Merge pull request #12964 from hppritcha/better_arg_checks_for_comm_create_from_group
comm: beef up args checking for some comm constructors
2 parents 232c47e + a0486e0 commit 8d71197

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

ompi/mpi/c/comm_create_from_group.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* reserved.
1616
* Copyright (c) 2015 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
18-
* Copyright (c) 2021 Triad National Security, LLC. All rights
18+
* Copyright (c) 2021-2024 Triad National Security, LLC. All rights
1919
* reserved.
2020
* $COPYRIGHT$
2121
*
@@ -54,23 +54,31 @@ int MPI_Comm_create_from_group (MPI_Group group, const char *tag, MPI_Info info,
5454
if ( MPI_PARAM_CHECK ) {
5555
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
5656

57+
if (NULL == errhandler ||
58+
MPI_ERRHANDLER_NULL == errhandler ||
59+
( OMPI_ERRHANDLER_TYPE_COMM != errhandler->eh_mpi_object_type &&
60+
OMPI_ERRHANDLER_TYPE_PREDEFINED != errhandler->eh_mpi_object_type) ) {
61+
return ompi_errhandler_invoke (NULL, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
62+
MPI_ERR_ARG,FUNC_NAME);
63+
}
64+
5765
if (NULL == tag) {
58-
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
66+
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
5967
MPI_ERR_TAG, FUNC_NAME);
6068
}
6169

6270
if (NULL == group) {
63-
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
71+
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
6472
MPI_ERR_GROUP, FUNC_NAME);
6573
}
6674

6775
if (NULL == info || ompi_info_is_freed(info)) {
68-
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
76+
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
6977
MPI_ERR_INFO, FUNC_NAME);
7078
}
7179

7280
if (NULL == newcomm) {
73-
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
81+
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
7482
MPI_ERR_ARG, FUNC_NAME);
7583
}
7684
}

ompi/mpi/c/intercomm_create_from_groups.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* and Technology (RIST). All rights reserved.
1818
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
1919
* reserved.
20-
* Copyright (c) 2018-2021 Triad National Security, LLC. All rights
20+
* Copyright (c) 2018-2024 Triad National Security, LLC. All rights
2121
* reserved.
2222
* $COPYRIGHT$
2323
*
@@ -50,7 +50,7 @@ int MPI_Intercomm_create_from_groups (MPI_Group local_group, int local_leader, M
5050
int remote_leader, const char *tag, MPI_Info info, MPI_Errhandler errhandler,
5151
MPI_Comm *newintercomm)
5252
{
53-
int rc;
53+
int rc, my_grp_rank, remote_grp_size;
5454

5555
MEMCHECKER(
5656
memchecker_comm(local_comm);
@@ -60,26 +60,43 @@ int MPI_Intercomm_create_from_groups (MPI_Group local_group, int local_leader, M
6060
if (MPI_PARAM_CHECK) {
6161
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
6262

63-
if (NULL == errhandler) {
64-
return MPI_ERR_ARG;
65-
}
63+
if (NULL == errhandler ||
64+
MPI_ERRHANDLER_NULL == errhandler ||
65+
( OMPI_ERRHANDLER_TYPE_COMM != errhandler->eh_mpi_object_type &&
66+
OMPI_ERRHANDLER_TYPE_PREDEFINED != errhandler->eh_mpi_object_type) ) {
67+
return ompi_errhandler_invoke (NULL, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
68+
MPI_ERR_ARG,FUNC_NAME);
6669

67-
if (NULL == local_group || NULL == remote_group) {
68-
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
69-
MPI_ERR_GROUP, FUNC_NAME);
7070
}
71+
7172
if (NULL == info || ompi_info_is_freed(info)) {
72-
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
73+
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
7374
MPI_ERR_INFO, FUNC_NAME);
7475
}
7576
if (NULL == tag) {
76-
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
77+
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
7778
MPI_ERR_TAG, FUNC_NAME);
7879
}
7980
if (NULL == newintercomm) {
80-
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
81+
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
8182
MPI_ERR_ARG, FUNC_NAME);
8283
}
84+
85+
my_grp_rank = ompi_group_rank((ompi_group_t *)local_group);
86+
if (local_leader == my_grp_rank) {
87+
88+
if (NULL == local_group || NULL == remote_group) {
89+
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
90+
MPI_ERR_GROUP, FUNC_NAME);
91+
}
92+
93+
remote_grp_size = ompi_group_size((ompi_group_t *)remote_group);
94+
if (remote_leader >= remote_grp_size) {
95+
rc = ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
96+
MPI_ERR_ARG, FUNC_NAME);
97+
return rc;
98+
}
99+
}
83100
}
84101

85102
rc = ompi_intercomm_create_from_groups (local_group, local_leader, remote_group, remote_leader, tag,

0 commit comments

Comments
 (0)