11/*
2- * Copyright (c) 2013-2015 The University of Tennessee and The University
2+ * Copyright (c) 2013-2016 The University of Tennessee and The University
33 * of Tennessee Research Foundation. All rights
44 * reserved.
55 * Copyright (c) 2013-2015 Inria. All rights reserved.
@@ -55,47 +55,60 @@ mca_pml_monitoring_module_t mca_pml_monitoring = {
5555 INT_MAX
5656};
5757
58+ /**
59+ * This PML monitors only the processes in the MPI_COMM_WORLD. As OMPI is now lazily
60+ * adding peers on the first call to add_procs we need to check how many processes
61+ * are in the MPI_COMM_WORLD to create the storage with the right size.
62+ */
5863int mca_pml_monitoring_add_procs (struct ompi_proc_t * * procs ,
5964 size_t nprocs )
6065{
61- /**
62- * Create the monitoring hashtable only for my MPI_COMM_WORLD. We choose
63- * to ignore by now all other processes.
64- */
65- if (NULL == translation_ht ) {
66- size_t i ;
67- uint64_t key ;
68- opal_process_name_t tmp ;
69-
70- nbprocs = nprocs ;
66+ opal_process_name_t tmp , wp_name ;
67+ size_t i , peer_rank , nprocs_world ;
68+ uint64_t key ;
7169
70+ if (NULL == translation_ht ) {
7271 translation_ht = OBJ_NEW (opal_hash_table_t );
7372 opal_hash_table_init (translation_ht , 2048 );
73+ /* get my rank in the MPI_COMM_WORLD */
74+ my_rank = ompi_comm_rank ((ompi_communicator_t * )& ompi_mpi_comm_world );
75+ }
7476
77+ nprocs_world = ompi_comm_size ((ompi_communicator_t * )& ompi_mpi_comm_world );
78+ /* For all procs in the same MPI_COMM_WORLD we need to add them to the hash table */
79+ for ( i = 0 ; i < nprocs ; i ++ ) {
7580
76- for ( i = 0 ; i < nprocs ; i ++ ) {
77- /* rank : ompi_proc_local_proc in procs */
78- if ( procs [i ] == ompi_proc_local_proc )
79- my_rank = i ;
80- /* Extract the peer procname from the procs array */
81- if ( ompi_proc_is_sentinel (procs [i ]) ) {
82- tmp = ompi_proc_sentinel_to_name ((uintptr_t )procs [i ]);
83- } else {
84- tmp = procs [i ]-> super .proc_name ;
85- }
81+ /* Extract the peer procname from the procs array */
82+ if ( ompi_proc_is_sentinel (procs [i ]) ) {
83+ tmp = ompi_proc_sentinel_to_name ((uintptr_t )procs [i ]);
84+ } else {
85+ tmp = procs [i ]-> super .proc_name ;
86+ }
87+ if ( tmp .jobid != ompi_proc_local_proc -> super .proc_name .jobid )
88+ continue ;
89+
90+ for ( peer_rank = 0 ; peer_rank < nprocs_world ; peer_rank ++ ) {
91+ wp_name = ompi_group_get_proc_name (((ompi_communicator_t * )& ompi_mpi_comm_world )-> c_remote_group , peer_rank );
92+ if ( 0 != opal_compare_proc ( tmp , wp_name ) )
93+ continue ;
94+
95+ /* Find the rank of the peer in MPI_COMM_WORLD */
8696 key = * ((uint64_t * )& tmp );
8797 /* store the rank (in COMM_WORLD) of the process
88- with its name (a uniq opal ID) as key in the hash table*/
98+ with its name (a uniq opal ID) as key in the hash table*/
8999 if ( OPAL_SUCCESS != opal_hash_table_set_value_uint64 (translation_ht ,
90- key , (void * )(uintptr_t )i ) ) {
100+ key , (void * )(uintptr_t )peer_rank ) ) {
91101 return OMPI_ERR_OUT_OF_RESOURCE ; /* failed to allocate memory or growing the hash table */
92102 }
103+ break ;
93104 }
94105 }
95106 return pml_selected_module .pml_add_procs (procs , nprocs );
96107}
97108
98-
109+ /**
110+ * Pass the information down the PML stack.
111+ */
99112int mca_pml_monitoring_del_procs (struct ompi_proc_t * * procs ,
100113 size_t nprocs )
101114{
@@ -117,11 +130,16 @@ void finalize_monitoring( void )
117130 free (messages_count );
118131 opal_hash_table_remove_all ( translation_ht );
119132 free (translation_ht );
120-
121133}
122134
135+ /**
136+ * We have delayed the initialization until the first send so that we know that
137+ * the MPI_COMM_WORLD (which is the only communicator we are interested on at
138+ * this point) is correctly initialized.
139+ */
123140static void initialize_monitoring ( void )
124141{
142+ nbprocs = ompi_comm_size ((ompi_communicator_t * )& ompi_mpi_comm_world );
125143 sent_data = (uint64_t * )calloc (nbprocs , sizeof (uint64_t ));
126144 messages_count = (uint64_t * )calloc (nbprocs , sizeof (uint64_t ));
127145 filtered_sent_data = (uint64_t * )calloc (nbprocs , sizeof (uint64_t ));
@@ -147,7 +165,7 @@ void monitor_send_data(int world_rank, size_t data_size, int tag)
147165 initialize_monitoring ();
148166
149167 /* distinguishses positive and negative tags if requested */
150- if ((tag < 0 ) && (1 == filter_monitoring ())) {
168+ if ( (tag < 0 ) && (1 == filter_monitoring ()) ) {
151169 filtered_sent_data [world_rank ] += data_size ;
152170 filtered_messages_count [world_rank ]++ ;
153171 } else { /* if filtered monitoring is not activated data is aggregated indifferently */
@@ -156,12 +174,13 @@ void monitor_send_data(int world_rank, size_t data_size, int tag)
156174 }
157175}
158176
159- int mca_pml_monitoring_get_messages_count (const struct mca_base_pvar_t * pvar , void * value , void * obj_handle )
177+ int mca_pml_monitoring_get_messages_count (const struct mca_base_pvar_t * pvar ,
178+ void * value ,
179+ void * obj_handle )
160180{
161181 ompi_communicator_t * comm = (ompi_communicator_t * ) obj_handle ;
162- int comm_size = ompi_comm_size (comm );
182+ int i , comm_size = ompi_comm_size (comm );
163183 uint64_t * values = (uint64_t * ) value ;
164- int i ;
165184
166185 if (comm != & ompi_mpi_comm_world .comm || NULL == messages_count )
167186 return OMPI_ERROR ;
@@ -173,7 +192,9 @@ int mca_pml_monitoring_get_messages_count (const struct mca_base_pvar_t *pvar, v
173192 return OMPI_SUCCESS ;
174193}
175194
176- int mca_pml_monitoring_get_messages_size (const struct mca_base_pvar_t * pvar , void * value , void * obj_handle )
195+ int mca_pml_monitoring_get_messages_size (const struct mca_base_pvar_t * pvar ,
196+ void * value ,
197+ void * obj_handle )
177198{
178199 ompi_communicator_t * comm = (ompi_communicator_t * ) obj_handle ;
179200 int comm_size = ompi_comm_size (comm );
0 commit comments