Skip to content

Commit efecde9

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 #4523. Extend the common monitoring API. * Now it's possible to translate from local rank to world rank from both the communicator and the group. * Remove useless hashtable as we directly use the w_group contained in window structure. Add automatic generation at config time. The templates are expanded at configure time. It creates a new header file that generates all the variables/functions needed. Adding this during the autogen automagicaly generates for each of the available modules the proper functions. Only keep a generated argv-style array. Following Jeff's advice, the configure.m4 file generate a simple array of module variables to be iterated over to find the proper module. Signed-off-by: Clement Foyer <[email protected]>
1 parent a4755b6 commit efecde9

File tree

8 files changed

+222
-158
lines changed

8 files changed

+222
-158
lines changed

ompi/mca/common/monitoring/common_monitoring.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ OMPI_DECLSPEC void mca_common_monitoring_record_osc(int world_rank, size_t data_
6666
/* Records COLL communications. */
6767
OMPI_DECLSPEC void mca_common_monitoring_record_coll(int world_rank, size_t data_size);
6868

69-
/* Translate the rank from the given communicator of a process to its rank in MPI_COMM_RANK. */
70-
static inline int mca_common_monitoring_get_world_rank(int dst, struct ompi_communicator_t*comm,
71-
int*world_rank)
69+
/* Translate the rank from the given rank of a process to its rank in MPI_COMM_RANK. */
70+
static inline int mca_common_monitoring_get_world_rank_grp(int dest, ompi_group_t *group,
71+
int *world_rank)
7272
{
7373
opal_process_name_t tmp;
7474

7575
/* find the processor of the destination */
76-
ompi_proc_t *proc = ompi_group_get_proc_ptr(comm->c_remote_group, dst, true);
76+
ompi_proc_t *proc = ompi_group_get_proc_ptr(group, dest, true);
7777
if( ompi_proc_is_sentinel(proc) ) {
7878
tmp = ompi_proc_sentinel_to_name((uintptr_t)proc);
7979
} else {
@@ -94,6 +94,13 @@ static inline int mca_common_monitoring_get_world_rank(int dst, struct ompi_comm
9494
return ret;
9595
}
9696

97+
/* Translate the rank from the given communicator of a process to its rank in MPI_COMM_RANK. */
98+
static inline int mca_common_monitoring_get_world_rank(int dst, struct ompi_communicator_t*comm,
99+
int*world_rank)
100+
{
101+
return mca_common_monitoring_get_world_rank_grp(dst, comm->c_remote_group, world_rank);
102+
}
103+
97104
/* Return the current status of the monitoring system 0 if off or the
98105
* seperation between internal tags and external tags is disabled. Any
99106
* other positive value if the segregation between point-to-point and

ompi/mca/osc/monitoring/Makefile.am

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2016 Inria. All rights reserved.
2+
# Copyright (c) 2016-2017 Inria. All rights reserved.
33
# Copyright (c) 2017 IBM Corporation. All rights reserved.
44
# $COPYRIGHT$
55
#
@@ -32,8 +32,11 @@ mcacomponent_LTLIBRARIES = $(component_install)
3232
mca_osc_monitoring_la_SOURCES = $(monitoring_sources)
3333
mca_osc_monitoring_la_LDFLAGS = -module -avoid-version
3434
mca_osc_monitoring_la_LIBADD = $(top_builddir)/ompi/lib@[email protected] \
35-
$(OMPI_TOP_BUILDDIR)/ompi/mca/common/monitoring/libmca_common_monitoring.la
35+
$(OMPI_TOP_BUILDDIR)/ompi/mca/common/monitoring/libmca_common_monitoring.la
3636

3737
noinst_LTLIBRARIES = $(component_noinst)
3838
libmca_osc_monitoring_la_SOURCES = $(monitoring_sources)
3939
libmca_osc_monitoring_la_LDFLAGS = -module -avoid-version
40+
41+
distclean-local:
42+
rm -f $(builddir)/osc_monitoring_template_gen.h

ompi/mca/osc/monitoring/configure.m4

Lines changed: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,98 @@
1-
# -*- shell-script -*-
2-
#
3-
# Copyright (c) 2016 Inria. All rights reserved.
4-
# $COPYRIGHT$
1+
dnl -*- shell-script -*-
2+
dnl
3+
dnl Copyright (c) 2016-2017 Inria. All rights reserved.
4+
dnl $COPYRIGHT$
5+
dnl
6+
dnl Additional copyrights may follow
7+
dnl
8+
dnl $HEADER$
9+
dnl
10+
11+
# mca_ompi_osc_monitoring_generate_templates
512
#
6-
# Additional copyrights may follow
13+
# Append to file $1 an array of components by listing component names in $2.
714
#
8-
# $HEADER$
15+
# $1 = filename
16+
# $2 = osc component names
917
#
18+
AC_DEFUN(
19+
[MCA_OMPI_OSC_MONITORING_GENERATE_TEMPLATES],
20+
[m4_ifval(
21+
[$1],
22+
[AC_CONFIG_COMMANDS(
23+
[$1],
24+
[filename="$1"
25+
components=`echo "$2" | sed -e 's/,/ /g' -e 's/monitoring//'`
26+
cat <<EOF >$filename
27+
/* $filename
28+
*
29+
* This file was generated from ompi/mca/osc/monitoring/configure.m4
30+
*
31+
* DO NOT EDIT THIS FILE.
32+
*
33+
*/
34+
/*
35+
* Copyright (c) 2017 Inria. All rights reserved.
36+
* \$COPYRIGHT$
37+
*
38+
* Additional copyrights may follow
39+
*
40+
* \$HEADER$
41+
*/
42+
43+
#ifndef MCA_OSC_MONITORING_GEN_TEMPLATE_H
44+
#define MCA_OSC_MONITORING_GEN_TEMPLATE_H
45+
46+
#include <ompi_config.h>
47+
#include <ompi/mca/osc/osc.h>
48+
#include <ompi/mca/osc/monitoring/osc_monitoring_template.h>
49+
50+
/************************************************************/
51+
/* Include template generating macros and inlined functions */
52+
53+
EOF
54+
# Generate each case in order to register the proper template functions
55+
for comp in $components
56+
do
57+
echo "OSC_MONITORING_MODULE_TEMPLATE_GENERATE(${comp})" >>$filename
58+
done
59+
cat <<EOF >>$filename
60+
61+
/************************************************************/
62+
63+
typedef struct {
64+
const char * name;
65+
ompi_osc_base_module_t * (*fct) (ompi_osc_base_module_t *);
66+
} osc_monitoring_components_list_t;
67+
68+
static const osc_monitoring_components_list_t osc_monitoring_components_list[[]] = {
69+
EOF
70+
for comp in $components
71+
do
72+
echo " { .name = \"${comp}\", .fct = OSC_MONITORING_SET_TEMPLATE_FCT_NAME(${comp}) }," >>$filename
73+
done
74+
cat <<EOF >>$filename
75+
{ .name = NULL, .fct = NULL }
76+
};
77+
78+
#endif /* MCA_OSC_MONITORING_GEN_TEMPLATE_H */
79+
EOF
80+
unset filename components
81+
])
82+
])dnl
83+
])dnl
1084

1185
# MCA_ompi_osc_monitoring_CONFIG()
1286
# ------------------------------------------------
13-
AC_DEFUN([MCA_ompi_osc_monitoring_CONFIG],[
14-
AC_CONFIG_FILES([ompi/mca/osc/monitoring/Makefile])
15-
16-
AS_IF([test "$MCA_BUILD_ompi_common_monitoring_DSO_TRUE" = ''],
17-
[$1],
18-
[$2])
19-
OPAL_CHECK_PORTALS4([osc_monitoring],
20-
[AC_DEFINE([OMPI_WITH_OSC_PORTALS4], [1], [Whether or not to generate template for osc_portals4])],
21-
[])
22-
])dnl
87+
AC_DEFUN(
88+
[MCA_ompi_osc_monitoring_CONFIG],
89+
[AC_CONFIG_FILES([ompi/mca/osc/monitoring/Makefile])
90+
91+
AS_IF([test "$MCA_BUILD_ompi_common_monitoring_DSO_TRUE" = ''],
92+
[$1],
93+
[$2])
94+
95+
MCA_OMPI_OSC_MONITORING_GENERATE_TEMPLATES(
96+
[ompi/mca/osc/monitoring/osc_monitoring_template_gen.h],
97+
[mca_ompi_osc_m4_config_component_list, mca_ompi_osc_no_config_component_list])dnl
98+
])dnl

ompi/mca/osc/monitoring/osc_monitoring_accumulate.h

Lines changed: 6 additions & 6 deletions
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_grp(target_rank, win->w_group, &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_grp(target_rank, win->w_group, &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_grp(target_rank, win->w_group, &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_grp(target_rank, win->w_group, &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_grp(target_rank, win->w_group, &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_grp(target_rank, win->w_group, &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

Lines changed: 4 additions & 4 deletions
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_grp(target_rank, win->w_group, &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_grp(target_rank, win->w_group, &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_grp(source_rank, win->w_group, &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_grp(source_rank, win->w_group, &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

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include <ompi_config.h>
11+
#include <string.h>
1112
#include "osc_monitoring.h"
1213
#include <ompi/constants.h>
1314
#include <ompi/communicator/communicator.h>
@@ -18,29 +19,12 @@
1819
#include <ompi/mca/osc/base/base.h>
1920
#include <opal/mca/base/mca_base_component_repository.h>
2021

21-
/***************************************/
22-
/* Include template generating macros */
23-
#include "osc_monitoring_template.h"
22+
/**************************************************/
23+
/* Include templated macros and inlined functions */
2424

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
25+
#include "osc_monitoring_template_gen.h"
2826

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
32-
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
36-
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 */
42-
43-
/***************************************/
27+
/**************************************************/
4428

4529
static int mca_osc_monitoring_component_init(bool enable_progress_threads,
4630
bool enable_mpi_threads)
@@ -69,6 +53,20 @@ static int mca_osc_monitoring_component_query(struct ompi_win_t *win, void **bas
6953
return mca_osc_monitoring_component.priority;
7054
}
7155

56+
static inline int
57+
ompi_mca_osc_monitoring_set_template(ompi_osc_base_component_t *best_component,
58+
ompi_osc_base_module_t *module)
59+
{
60+
osc_monitoring_components_list_t comp = osc_monitoring_components_list[0];
61+
for (unsigned i = 0; NULL != comp.name; comp = osc_monitoring_components_list[++i]) {
62+
if ( 0 == strcmp(comp.name, best_component->osc_version.mca_component_name) ) {
63+
comp.fct(module);
64+
return OMPI_SUCCESS;
65+
}
66+
}
67+
return OMPI_ERR_NOT_SUPPORTED;
68+
}
69+
7270
static int mca_osc_monitoring_component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit,
7371
struct ompi_communicator_t *comm, struct opal_info_t *info,
7472
int flavor, int *model)
@@ -108,20 +106,11 @@ static int mca_osc_monitoring_component_select(struct ompi_win_t *win, void **ba
108106
ret = best_component->osc_select(win, base, size, disp_unit, comm, info, flavor, model);
109107
if( OMPI_SUCCESS == ret ) {
110108
/* Intercept module functions with ours, based on selected component */
111-
if( 0 == strcmp("rdma", best_component->osc_version.mca_component_name) ) {
112-
OSC_MONITORING_SET_TEMPLATE(rdma, win->w_osc_module);
113-
} else if( 0 == strcmp("sm", best_component->osc_version.mca_component_name) ) {
114-
OSC_MONITORING_SET_TEMPLATE(sm, win->w_osc_module);
115-
} else if( 0 == strcmp("pt2pt", best_component->osc_version.mca_component_name) ) {
116-
OSC_MONITORING_SET_TEMPLATE(pt2pt, win->w_osc_module);
117-
#ifdef OMPI_WITH_OSC_PORTALS4
118-
} else if( 0 == strcmp("portals4", best_component->osc_version.mca_component_name) ) {
119-
OSC_MONITORING_SET_TEMPLATE(portals4, win->w_osc_module);
120-
#endif /* OMPI_WITH_OSC_PORTALS4 */
121-
} else {
109+
ret = ompi_mca_osc_monitoring_set_template(best_component, win->w_osc_module);
110+
if (OMPI_ERR_NOT_SUPPORTED == ret) {
122111
OPAL_MONITORING_PRINT_WARN("osc: monitoring disabled: no module for this component "
123112
"(%s)", best_component->osc_version.mca_component_name);
124-
return ret;
113+
return OMPI_SUCCESS;
125114
}
126115
}
127116
return ret;
@@ -150,4 +139,3 @@ ompi_osc_monitoring_component_t mca_osc_monitoring_component = {
150139
},
151140
.priority = INT_MAX
152141
};
153-

0 commit comments

Comments
 (0)