@@ -140,6 +140,11 @@ OMPI_DECLSPEC OBJ_CLASS_DECLARATION(ompi_communicator_t);
140140#define OMPI_COMM_BLOCK_WORLD 16
141141#define OMPI_COMM_BLOCK_OTHERS 8
142142
143+ /**
144+ * Placeholder to use in array of ompi communicators during CID allocation
145+ */
146+ #define OMPI_COMM_SENTINEL 0x00000001
147+
143148/* A macro comparing two CIDs */
144149#define OMPI_COMM_CID_IS_LOWER (comm1 ,comm2 ) ( ((comm1)->c_index < (comm2)->c_index)? 1:0)
145150
@@ -552,8 +557,27 @@ static inline bool ompi_comm_compare_cids (const ompi_communicator_t *comm1, con
552557 * No error checking is done*/
553558static inline ompi_communicator_t * ompi_comm_lookup (const uint32_t c_index )
554559{
560+ ompi_communicator_t * comm = NULL ;
555561 /* array of pointers to communicators, indexed by context ID */
556- return (ompi_communicator_t * ) opal_pointer_array_get_item (& ompi_mpi_communicators , c_index );
562+ comm = (ompi_communicator_t * ) opal_pointer_array_get_item (& ompi_mpi_communicators , c_index );
563+ /*
564+ * OMPI_COMM_SENTINEL indicates the slot is being used for CID allocation
565+ * and is not a valid communicator
566+ */
567+ if ((ompi_communicator_t * )OMPI_COMM_SENTINEL == comm ) {
568+ comm = NULL ;
569+ }
570+
571+ return comm ;
572+ }
573+
574+ /**
575+ * Number of entries in the ompi_mpi_communicators pointer array.
576+ * Note this includes entries which may have NULL or OMPI_COMM_SENTINEL values.
577+ */
578+ static inline int ompi_comm_get_num_communicators (void )
579+ {
580+ return opal_pointer_array_get_size (& ompi_mpi_communicators );
557581}
558582
559583static inline ompi_communicator_t * ompi_comm_lookup_cid (const ompi_comm_extended_cid_t cid )
0 commit comments