Skip to content

Commit 08ec754

Browse files
committed
Remove inter-dependencies between OSC modules.
The osc monitoring component needed to include other OSC components header in order to be able tu access communicator through the component specific ompi_osc_*_module_t structures. This commit remove the dependency, and resolve the issue open-mpi#4523. Signed-off-by: Clement Foyer <clement.foyer@inria.fr>
1 parent 1a4df7a commit 08ec754

File tree

4 files changed

+47
-36
lines changed

4 files changed

+47
-36
lines changed

ompi/mca/osc/monitoring/osc_monitoring_accumulate.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* If this fails the destination is not part of my MPI_COM_WORLD \
3030
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
3131
*/ \
32-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
32+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
3333
size_t type_size; \
3434
ompi_datatype_type_size(dt, &type_size); \
3535
mca_common_monitoring_record_osc(world_rank, type_size, SEND); \
@@ -56,7 +56,7 @@
5656
* If this fails the destination is not part of my MPI_COM_WORLD \
5757
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
5858
*/ \
59-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
59+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
6060
size_t type_size, data_size; \
6161
ompi_datatype_type_size(origin_datatype, &type_size); \
6262
data_size = origin_count*type_size; \
@@ -88,7 +88,7 @@
8888
* If this fails the destination is not part of my MPI_COM_WORLD \
8989
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
9090
*/ \
91-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
91+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
9292
size_t type_size, data_size; \
9393
ompi_datatype_type_size(origin_datatype, &type_size); \
9494
data_size = origin_count*type_size; \
@@ -116,7 +116,7 @@
116116
* If this fails the destination is not part of my MPI_COM_WORLD \
117117
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
118118
*/ \
119-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
119+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
120120
size_t type_size, data_size; \
121121
ompi_datatype_type_size(origin_datatype, &type_size); \
122122
data_size = origin_count*type_size; \
@@ -140,7 +140,7 @@
140140
* If this fails the destination is not part of my MPI_COM_WORLD \
141141
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
142142
*/ \
143-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
143+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
144144
size_t type_size, data_size; \
145145
ompi_datatype_type_size(origin_datatype, &type_size); \
146146
data_size = origin_count*type_size; \
@@ -162,7 +162,7 @@
162162
* If this fails the destination is not part of my MPI_COM_WORLD \
163163
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
164164
*/ \
165-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
165+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
166166
size_t type_size; \
167167
ompi_datatype_type_size(dt, &type_size); \
168168
mca_common_monitoring_record_osc(world_rank, type_size, SEND); \

ompi/mca/osc/monitoring/osc_monitoring_comm.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* If this fails the destination is not part of my MPI_COM_WORLD \
3131
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
3232
*/ \
33-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
33+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
3434
size_t type_size, data_size; \
3535
ompi_datatype_type_size(origin_datatype, &type_size); \
3636
data_size = origin_count*type_size; \
@@ -55,7 +55,7 @@
5555
* If this fails the destination is not part of my MPI_COM_WORLD \
5656
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
5757
*/ \
58-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
58+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(target_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
5959
size_t type_size, data_size; \
6060
ompi_datatype_type_size(origin_datatype, &type_size); \
6161
data_size = origin_count*type_size; \
@@ -78,7 +78,7 @@
7878
* If this fails the destination is not part of my MPI_COM_WORLD \
7979
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
8080
*/ \
81-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(source_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
81+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(source_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
8282
size_t type_size, data_size; \
8383
ompi_datatype_type_size(origin_datatype, &type_size); \
8484
data_size = origin_count*type_size; \
@@ -103,7 +103,7 @@
103103
* If this fails the destination is not part of my MPI_COM_WORLD \
104104
* Lookup its name in the rank hastable to get its MPI_COMM_WORLD rank \
105105
*/ \
106-
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(source_rank, ompi_osc_monitoring_## template ##_get_comm(win), &world_rank)) { \
106+
if(OPAL_SUCCESS == mca_common_monitoring_get_world_rank(source_rank, ompi_osc_monitoring_get_comm(win), &world_rank)) { \
107107
size_t type_size, data_size; \
108108
ompi_datatype_type_size(origin_datatype, &type_size); \
109109
data_size = origin_count*type_size; \

ompi/mca/osc/monitoring/osc_monitoring_component.c

+34-16
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,52 @@
1919
#include <opal/mca/base/mca_base_component_repository.h>
2020

2121
/***************************************/
22-
/* Include template generating macros */
23-
#include "osc_monitoring_template.h"
2422

25-
#include <ompi/mca/osc/rdma/osc_rdma.h>
26-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(rdma, ompi_osc_rdma_module_t, comm)
27-
#undef GET_MODULE
23+
static opal_hash_table_t *win_to_comm_ht = NULL;
2824

29-
#include <ompi/mca/osc/sm/osc_sm.h>
30-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(sm, ompi_osc_sm_module_t, comm)
31-
#undef GET_MODULE
25+
static inline struct ompi_communicator_t*
26+
ompi_osc_monitoring_get_comm(ompi_win_t *win)
27+
{
28+
ompi_communicator_t *comm = NULL;
29+
uint64_t key = *((uint64_t*)&win);
30+
int ret = opal_hash_table_get_value_uint64(win_to_comm_ht, key,
31+
(void *)&comm);
32+
return OPAL_SUCCESS == ret ? comm : NULL;
33+
}
3234

33-
#include <ompi/mca/osc/pt2pt/osc_pt2pt.h>
34-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(pt2pt, ompi_osc_pt2pt_module_t, comm)
35-
#undef GET_MODULE
35+
/***************************************/
36+
/* Include template generating macros */
37+
#include "osc_monitoring_template.h"
3638

37-
#ifdef OMPI_WITH_OSC_PORTALS4
38-
#include <ompi/mca/osc/portals4/osc_portals4.h>
39-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(portals4, ompi_osc_portals4_module_t, comm)
40-
#undef GET_MODULE
41-
#endif /* OMPI_WITH_OSC_PORTALS4 */
39+
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(rdma)
40+
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(sm)
41+
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(pt2pt)
42+
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(portals4)
4243

4344
/***************************************/
4445

4546
static int mca_osc_monitoring_component_init(bool enable_progress_threads,
4647
bool enable_mpi_threads)
4748
{
4849
OPAL_MONITORING_PRINT_INFO("osc_component_init");
50+
/* Initialize win to comm translation hashtable */
51+
win_to_comm_ht = OBJ_NEW(opal_hash_table_t);
52+
if ( !win_to_comm_ht ||
53+
OPAL_SUCCESS != opal_hash_table_init(win_to_comm_ht, 2048) )
54+
{
55+
OPAL_MONITORING_PRINT_ERR("osc: Unable to grow hash_table: no "
56+
"memory left available.");
57+
return OMPI_ERR_OUT_OF_RESOURCE;
58+
}
4959
return mca_common_monitoring_init();
5060
}
5161

5262
static int mca_osc_monitoring_component_finish(void)
5363
{
5464
OPAL_MONITORING_PRINT_INFO("osc_component_finish");
65+
/* Initialize win to comm translation hashtable */
66+
opal_hash_table_remove_all( win_to_comm_ht );
67+
OBJ_RELEASE(win_to_comm_ht);
5568
mca_common_monitoring_finalize();
5669
return OMPI_SUCCESS;
5770
}
@@ -124,6 +137,11 @@ static int mca_osc_monitoring_component_select(struct ompi_win_t *win, void **ba
124137
return ret;
125138
}
126139
}
140+
if( OPAL_SUCCESS != opal_hash_table_set_value_uint64(win_to_comm_ht, win, (void *)comm) ) {
141+
/* failed to allocate memory or growing the hash table */
142+
OPAL_MONITORING_PRINT_ERR("osc: Unable to grow hash_table: no memory left available.");
143+
return OMPI_ERR_OUT_OF_RESOURCE;
144+
}
127145
return ret;
128146
}
129147

ompi/mca/osc/monitoring/osc_monitoring_template.h

+3-10
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
#include "osc_monitoring_module.h"
2424
#include "osc_monitoring_passive_target.h"
2525

26-
/* module_type correspond to the ompi_osc_## template ##_module_t type
27-
* comm correspond to the comm field name in ompi_osc_## template ##_module_t
26+
/* comm correspond to the comm field name in ompi_osc_## template ##_module_t
2827
*
2928
* The magic used here is that for a given module type (given with the
3029
* {template} parameter), we generate a set of every functions defined
@@ -37,17 +36,11 @@
3736
* the original function that had been saved in the
3837
* ompi_osc_monitoring_module_## template ##_template variable.
3938
*/
40-
#define OSC_MONITORING_MODULE_TEMPLATE_GENERATE(template, module_type, comm) \
39+
#define OSC_MONITORING_MODULE_TEMPLATE_GENERATE(template) \
4140
/* Generate the proper symbol for the \
4241
ompi_osc_monitoring_module_## template ##_template variable */ \
4342
OMPI_OSC_MONITORING_MODULE_GENERATE(template); \
44-
OMPI_OSC_MONITORING_MODULE_INIT_GENERATE(template); \
45-
/* Generate module specific module->comm accessor */ \
46-
static inline struct ompi_communicator_t* \
47-
ompi_osc_monitoring_## template ##_get_comm(ompi_win_t*win) \
48-
{ \
49-
return ((module_type*)win->w_osc_module)->comm; \
50-
} \
43+
OMPI_OSC_MONITORING_MODULE_INIT_GENERATE(template); \
5144
/* Generate each module specific functions */ \
5245
OSC_MONITORING_GENERATE_TEMPLATE_ACCUMULATE(template) \
5346
OSC_MONITORING_GENERATE_TEMPLATE_ACTIVE_TARGET(template) \

0 commit comments

Comments
 (0)