Skip to content

Commit

Permalink
comm: beef up args checking for some comm constructors
Browse files Browse the repository at this point in the history
The MPI_Comm_create_from_group and especially the
MPI_Intercomm_create_from_groups functions are recent additions
to the standard (MPI 4.0) and users may get confused easily
trying to use them.

So better parameter checking is needed.

Related to #12906 where an incorrect code example showed up.

Signed-off-by: Howard Pritchard <[email protected]>
(cherry picked from commit a0486e0)
  • Loading branch information
hppritcha committed Dec 16, 2024
1 parent aeb713f commit 3796286
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
16 changes: 12 additions & 4 deletions ompi/mpi/c/comm_create_from_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,31 @@ int MPI_Comm_create_from_group (MPI_Group group, const char *tag, MPI_Info info,
if ( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);

if (NULL == errhandler ||
MPI_ERRHANDLER_NULL == errhandler ||
( OMPI_ERRHANDLER_TYPE_COMM != errhandler->eh_mpi_object_type &&
OMPI_ERRHANDLER_TYPE_PREDEFINED != errhandler->eh_mpi_object_type) ) {
return ompi_errhandler_invoke (NULL, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG,FUNC_NAME);
}

if (NULL == tag) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_TAG, FUNC_NAME);
}

if (NULL == group) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_GROUP, FUNC_NAME);
}

if (NULL == info || ompi_info_is_freed(info)) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_INFO, FUNC_NAME);
}

if (NULL == newcomm) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG, FUNC_NAME);
}
}
Expand Down
39 changes: 28 additions & 11 deletions ompi/mpi/c/intercomm_create_from_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* and Technology (RIST). All rights reserved.
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2018-2021 Triad National Security, LLC. All rights
* Copyright (c) 2018-2024 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
Expand Down Expand Up @@ -50,7 +50,7 @@ int MPI_Intercomm_create_from_groups (MPI_Group local_group, int local_leader, M
int remote_leader, const char *tag, MPI_Info info, MPI_Errhandler errhandler,
MPI_Comm *newintercomm)
{
int rc;
int rc, my_grp_rank, remote_grp_size;

MEMCHECKER(
memchecker_comm(local_comm);
Expand All @@ -60,26 +60,43 @@ int MPI_Intercomm_create_from_groups (MPI_Group local_group, int local_leader, M
if (MPI_PARAM_CHECK) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);

if (NULL == errhandler) {
return MPI_ERR_ARG;
}
if (NULL == errhandler ||
MPI_ERRHANDLER_NULL == errhandler ||
( OMPI_ERRHANDLER_TYPE_COMM != errhandler->eh_mpi_object_type &&
OMPI_ERRHANDLER_TYPE_PREDEFINED != errhandler->eh_mpi_object_type) ) {
return ompi_errhandler_invoke (NULL, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG,FUNC_NAME);

if (NULL == local_group || NULL == remote_group) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
MPI_ERR_GROUP, FUNC_NAME);
}

if (NULL == info || ompi_info_is_freed(info)) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_INFO, FUNC_NAME);
}
if (NULL == tag) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_TAG, FUNC_NAME);
}
if (NULL == newintercomm) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG, FUNC_NAME);
}

my_grp_rank = ompi_group_rank((ompi_group_t *)local_group);
if (local_leader == my_grp_rank) {

if (NULL == local_group || NULL == remote_group) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_GROUP, FUNC_NAME);
}

remote_grp_size = ompi_group_size((ompi_group_t *)remote_group);
if (remote_leader >= remote_grp_size) {
rc = ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG, FUNC_NAME);
return rc;
}
}
}

rc = ompi_intercomm_create_from_groups (local_group, local_leader, remote_group, remote_leader, tag,
Expand Down

0 comments on commit 3796286

Please sign in to comment.