@@ -51,6 +51,8 @@ int main(int argc, char *argv[])
5151 MPI_Comm comm ;
5252 MPI_Info info ;
5353 int ret ;
54+ int value = 0 ;
55+ int expected_value = 3 ;
5456
5557 MPI_Init (& argc , & argv );
5658 MPI_Comm_rank (MPI_COMM_WORLD , & mcw_rank );
@@ -181,6 +183,60 @@ int main(int argc, char *argv[])
181183
182184 sync_hr ();
183185
186+ /*
187+ * Test MPI_COMM_TYPE_HW_GUIDED:
188+ * - Test with "mpi_hw_resource_type" = "mpi_shared_memory"
189+ * - Mix in some MPI_UNDEFINED values to make sure those are handled properly
190+ */
191+ expected_value = 3 ;
192+ if (expected_value > mcw_size ) {
193+ expected_value = mcw_size ;
194+ }
195+ MPI_Info_create (& info );
196+ MPI_Info_set (info , "mpi_hw_resource_type" , "mpi_shared_memory" );
197+ if (mcw_rank == 0 && verbose ) {
198+ printf ("MPI_COMM_TYPE_HW_GUIDED: Trying MPI Standard value %s with some MPI_UNDEFINED\n" , "mpi_shared_memory" );
199+ }
200+ if (mcw_rank < expected_value ) {
201+ ret = MPI_Comm_split_type (MPI_COMM_WORLD , MPI_COMM_TYPE_HW_GUIDED , 0 , info , & comm );
202+ } else {
203+ ret = MPI_Comm_split_type (MPI_COMM_WORLD , MPI_UNDEFINED , 0 , info , & comm );
204+ }
205+ if (ret != MPI_SUCCESS ) {
206+ printf ("MPI_COMM_TYPE_HW_GUIDED (%s) failed\n" , split_topo [i ]);
207+ errs ++ ;
208+ } else if (comm != MPI_COMM_NULL ) {
209+ MPI_Comm_rank (comm , & rank );
210+ MPI_Comm_size (comm , & size );
211+ value = 1 ;
212+ if (rank == 0 && verbose ) {
213+ printf ("MPI_COMM_TYPE_HW_GUIDED (%s): %d/%d Created shared subcommunicator of size %d\n" ,
214+ "mpi_shared_memory" , mcw_rank , mcw_size , size );
215+ }
216+ MPI_Comm_free (& comm );
217+ } else if (verbose ) {
218+ value = 0 ;
219+ printf ("MPI_COMM_TYPE_HW_GUIDED (%s): %d/%d Returned MPI_COMM_NULL\n" ,
220+ "mpi_shared_memory" , mcw_rank , mcw_size );
221+ }
222+ MPI_Info_free (& info );
223+
224+ if (mcw_rank == 0 ) {
225+ MPI_Reduce (MPI_IN_PLACE , & value , 1 , MPI_INT , MPI_SUM , 0 , MPI_COMM_WORLD );
226+ if (expected_value != value ) {
227+ printf ("MPI_COMM_TYPE_HW_GUIDED (%s): Failed: Verify expected %d == actual %d\n" ,
228+ "mpi_shared_memory" , expected_value , value );
229+ } else if (verbose ) {
230+ printf ("MPI_COMM_TYPE_HW_GUIDED (%s): Passed: Verify expected %d == actual %d\n" ,
231+ "mpi_shared_memory" , expected_value , value );
232+ }
233+ } else {
234+ MPI_Reduce (& value , NULL , 1 , MPI_INT , MPI_SUM , 0 , MPI_COMM_WORLD );
235+ }
236+ MPI_Barrier (MPI_COMM_WORLD );
237+
238+ sync_hr ();
239+
184240 /*
185241 * Test MPI_COMM_TYPE_HW_GUIDED:
186242 * - info with correct key, but different values a different ranks, it must throw an error
0 commit comments