Skip to content

Commit cad26bd

Browse files
authored
Merge pull request #1 from hppritcha/sessions_new
fix fortran problems with sessions
2 parents 6bee5eb + d7b7326 commit cad26bd

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

ompi/communicator/comm_init.c

Lines changed: 44 additions & 4 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;
@@ -157,7 +183,7 @@ int ompi_comm_init_mpi3 (void)
157183

158184
/* Setup MPI_COMM_WORLD */
159185
OBJ_CONSTRUCT(&ompi_mpi_comm_world, ompi_communicator_t);
160-
assert(ompi_mpi_comm_world.comm.c_f_to_c_index == 1);
186+
assert(ompi_mpi_comm_world.comm.c_f_to_c_index == OMPI_MPI_COMM_WORLD);
161187

162188
ret = ompi_group_from_pset (ompi_mpi_instance_default, "mpi://world", &group);
163189
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
@@ -211,7 +237,7 @@ int ompi_comm_init_mpi3 (void)
211237
}
212238
/* Setup MPI_COMM_SELF */
213239
OBJ_CONSTRUCT(&ompi_mpi_comm_self, ompi_communicator_t);
214-
assert(ompi_mpi_comm_self.comm.c_f_to_c_index == 2);
240+
assert(ompi_mpi_comm_self.comm.c_f_to_c_index == OMPI_MPI_COMM_SELF);
215241

216242
ret = ompi_group_from_pset (ompi_mpi_instance_default, "mpi://self", &group);
217243
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
@@ -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)