Skip to content

Commit fe0c02c

Browse files
committed
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 a53118e commit fe0c02c

File tree

2 files changed

+61
-44
lines changed

2 files changed

+61
-44
lines changed

ompi/mca/osc/monitoring/configure.m4

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ dnl
1515
# $1 = filename
1616
# $2 = osc component names
1717
#
18-
AC_DEFUN([mca_ompi_osc_monitoring_generate_templates],[
19-
m4_ifval([$1], [
20-
AC_CONFIG_COMMANDS([$1],
21-
[filename="$1"
22-
components=`echo "$2" | sed -e 's/,/ /g' -e 's/monitoring//'`
23-
cat <<EOF >$filename
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
2427
/* $filename
2528
*
2629
* This file was generated from ompi/mca/osc/monitoring/configure.m4
@@ -40,56 +43,56 @@ AC_DEFUN([mca_ompi_osc_monitoring_generate_templates],[
4043
#ifndef MCA_OSC_MONITORING_GEN_TEMPLATE_H
4144
#define MCA_OSC_MONITORING_GEN_TEMPLATE_H
4245

43-
#include <string.h>
4446
#include <ompi_config.h>
4547
#include <ompi/mca/osc/osc.h>
4648
#include <ompi/mca/osc/monitoring/osc_monitoring_template.h>
4749

48-
/***************************************/
49-
/* Include template generating macros */
50+
/************************************************************/
51+
/* Include template generating macros and inlined functions */
5052

5153
EOF
52-
# Generate each case in order to register the proper template functions
53-
for comp in $components
54-
do
55-
echo "OSC_MONITORING_MODULE_TEMPLATE_GENERATE(${comp})" >>$filename
56-
done
57-
cat <<EOF >>$filename
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
5860

59-
/***************************************/
61+
/************************************************************/
6062

61-
static inline int
62-
ompi_mca_osc_monitoring_set_template(ompi_osc_base_component_t *best_component,
63-
ompi_osc_base_module_t *module)
64-
{
65-
/* Sorry for the lack on indentation, but the portability won over the cleanliness */
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[[]] = {
6669
EOF
67-
for comp in $components
68-
do
69-
echo "if ( 0 == strcmp(\"${comp}\", best_component->osc_version.mca_component_name) ) {" >>$filename
70-
echo " OSC_MONITORING_SET_TEMPLATE_FCT_NAME(${comp}) (module);" >>$filename
71-
echo " } else " >>$filename
72-
done
73-
cat <<EOF >>$filename
74-
return OMPI_ERR_NOT_SUPPORTED;
75-
return OMPI_SUCCESS;
76-
}
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+
};
7777
7878
#endif /* MCA_OSC_MONITORING_GEN_TEMPLATE_H */
7979
EOF
80-
unset filename components])
80+
unset filename components
81+
])
8182
])dnl
82-
])dnl
83+
])dnl
8384

8485
# MCA_ompi_osc_monitoring_CONFIG()
8586
# ------------------------------------------------
86-
AC_DEFUN([MCA_ompi_osc_monitoring_CONFIG],[
87-
AC_CONFIG_FILES([ompi/mca/osc/monitoring/Makefile])
87+
AC_DEFUN(
88+
[MCA_ompi_osc_monitoring_CONFIG],
89+
[AC_CONFIG_FILES([ompi/mca/osc/monitoring/Makefile])
8890

89-
AS_IF([test "$MCA_BUILD_ompi_common_monitoring_DSO_TRUE" = ''],
90-
[$1],
91-
[$2])
91+
AS_IF([test "$MCA_BUILD_ompi_common_monitoring_DSO_TRUE" = ''],
92+
[$1],
93+
[$2])
9294

93-
mca_ompi_osc_monitoring_generate_templates([ompi/mca/osc/monitoring/osc_monitoring_template_gen.h],
94-
[mca_ompi_osc_m4_config_component_list, mca_ompi_osc_no_config_component_list])dnl
95-
])dnl
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_component.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
#include <ompi/mca/osc/base/base.h>
1919
#include <opal/mca/base/mca_base_component_repository.h>
2020

21-
/**************************************/
22-
/* Include templated macros */
21+
/**************************************************/
22+
/* Include templated macros and inlined functions */
2323

2424
#include "osc_monitoring_template_gen.h"
2525

26-
/***************************************/
26+
/**************************************************/
2727

2828
static int mca_osc_monitoring_component_init(bool enable_progress_threads,
2929
bool enable_mpi_threads)
@@ -52,6 +52,20 @@ static int mca_osc_monitoring_component_query(struct ompi_win_t *win, void **bas
5252
return mca_osc_monitoring_component.priority;
5353
}
5454

55+
static inline int
56+
ompi_mca_osc_monitoring_set_template(ompi_osc_base_component_t *best_component,
57+
ompi_osc_base_module_t *module)
58+
{
59+
osc_monitoring_components_list_t comp = osc_monitoring_components_list[0];
60+
for (unsigned i = 0; NULL != comp.name; comp = osc_monitoring_components_list[++i]) {
61+
if ( 0 == strcmp(comp.name, best_component->osc_version.mca_component_name) ) {
62+
comp.fct(module);
63+
return OMPI_SUCCESS;
64+
}
65+
}
66+
return OMPI_ERR_NOT_SUPPORTED;
67+
}
68+
5569
static int mca_osc_monitoring_component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit,
5670
struct ompi_communicator_t *comm, struct opal_info_t *info,
5771
int flavor, int *model)

0 commit comments

Comments
 (0)