Skip to content

Commit 9f00382

Browse files
committed
sessions: fix a problem with fortran comm handles
Sessions related changes changed the order of initialization of pre-defined communicators used in the World Process Model. This led to issues for MPI Fortran applications since the predefined handles for MPI_COMM_WORLD, MPI_COMM_SELF, and MPI_COMM_NULL were wrong, leading to a meltdown with any call to MPI using communicators from the Fortran interfaces. Further, when using sessions, there's no guarantee when the app might finally cause MPI_Init, so the original algorithm for adding entries to the comm struct f_to_c pointer array no longer works as-is. This commit fixes these issues with Fortran interfaces and MPI communicator handles. Signed-off-by: Howard Pritchard <howardp@lanl.gov>
1 parent b122090 commit 9f00382

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

ompi/communicator/comm_init.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* and Technology (RIST). All rights reserved.
2323
* Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
2424
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
25-
* Copyright (c) 2018 Triad National Security, LLC. All rights
25+
* Copyright (c) 2018-2019 Triad National Security, LLC. All rights
2626
* reserved.
2727
* $COPYRIGHT$
2828
*
@@ -49,6 +49,7 @@
4949
#include "ompi/dpm/dpm.h"
5050
#include "ompi/memchecker.h"
5151
#include "ompi/instance/instance.h"
52+
#include "ompi/mpi/fortran/use-mpi-f08/constants.h"
5253

5354
/*
5455
** Table for Fortran <-> C communicator handle conversion
@@ -112,6 +113,31 @@ int ompi_comm_init(void)
112113
return OMPI_ERROR;
113114
}
114115

116+
/*
117+
* reserve indices in the F to C table for:
118+
* MPI_COMM_WORLD
119+
* MPI_COMM_SELF
120+
* MPI_COMM_NULL
121+
*/
122+
123+
if (OPAL_SUCCESS != opal_pointer_array_set_item(&ompi_comm_f_to_c_table,
124+
OMPI_MPI_COMM_NULL,
125+
(void *)-1L)) {
126+
return OMPI_ERROR;
127+
}
128+
129+
if (OPAL_SUCCESS != opal_pointer_array_set_item(&ompi_comm_f_to_c_table,
130+
OMPI_MPI_COMM_WORLD,
131+
(void *)-1L)) {
132+
return OMPI_ERROR;
133+
}
134+
135+
if (OPAL_SUCCESS != opal_pointer_array_set_item(&ompi_comm_f_to_c_table,
136+
OMPI_MPI_COMM_SELF,
137+
(void *)-1L)) {
138+
return OMPI_ERROR;
139+
}
140+
115141
/* Setup MPI_COMM_NULL */
116142
OBJ_CONSTRUCT(&ompi_mpi_comm_null, ompi_communicator_t);
117143
ompi_mpi_comm_null.comm.c_local_group = &ompi_mpi_group_null.group;
@@ -380,7 +406,7 @@ static int ompi_comm_finalize (void)
380406

381407
static void ompi_comm_construct(ompi_communicator_t* comm)
382408
{
383-
comm->c_f_to_c_index = opal_pointer_array_add(&ompi_comm_f_to_c_table, comm);
409+
int idx;
384410
comm->c_name[0] = '\0';
385411
comm->c_index = MPI_UNDEFINED;
386412
comm->c_flags = 0;
@@ -393,6 +419,20 @@ static void ompi_comm_construct(ompi_communicator_t* comm)
393419
comm->c_topo = NULL;
394420
comm->c_coll = NULL;
395421

422+
/*
423+
* magic numerology - see TOPDIR/ompi/include/mpif-values.pl
424+
*/
425+
idx = (comm == ompi_mpi_comm_world_addr) ? OMPI_MPI_COMM_WORLD :
426+
(comm == ompi_mpi_comm_self_addr) ? OMPI_MPI_COMM_SELF :
427+
(comm == ompi_mpi_comm_null_addr) ? OMPI_MPI_COMM_NULL : -1;
428+
if (-1 == idx) {
429+
comm->c_f_to_c_index = opal_pointer_array_add(&ompi_comm_f_to_c_table,
430+
comm);
431+
} else {
432+
opal_pointer_array_set_item(&ompi_comm_f_to_c_table, idx, comm);
433+
comm->c_f_to_c_index = idx;
434+
}
435+
396436
/* A keyhash will be created if/when an attribute is cached on
397437
this communicator */
398438
comm->c_keyhash = NULL;

0 commit comments

Comments
 (0)