Skip to content

Commit f6882a8

Browse files
committed
mpiext_affinity_str.c: minor stylistic updates
No real functional changes: * Reduce #if's a little -- have a single "no hwloc" and "hwloc" section. * Make a common subroutine (no_hwloc_support()) for when we don't have any hwloc support
1 parent fc69c0b commit f6882a8

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

ompi/mpiext/affinity/c/mpiext_affinity_str.c

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2009 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2010-2012 Cisco Systems, Inc. All rights reserved.
5+
* Copyright (c) 2010-2015 Cisco Systems, Inc. All rights reserved.
66
* Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
77
* Copyright (c) 2012 Los Alamos National Security, LLC. All rights
88
* reserved.
@@ -38,41 +38,69 @@ static const char FUNC_NAME[] = "OMPI_Affinity";
3838
static const char ompi_nobind_str[] = "Open MPI did not bind this process";
3939
static const char not_bound_str[] = "Not bound (i.e., bound to all processors)";
4040

41+
/**************************************************************************
42+
* Utility routine
43+
**************************************************************************/
44+
45+
static no_hwloc_support(char ompi_bound[OMPI_AFFINITY_STRING_MAX],
46+
char current_binding[OMPI_AFFINITY_STRING_MAX],
47+
char exists[OMPI_AFFINITY_STRING_MAX])
48+
{
49+
strncpy(ompi_bound, "Not supported", OMPI_AFFINITY_STRING_MAX);
50+
strncpy(current_binding, "Not supported", OMPI_AFFINITY_STRING_MAX);
51+
strncpy(exists, "Not supported", OMPI_AFFINITY_STRING_MAX);
52+
}
53+
54+
/**************************************************************************
55+
* If we have no hwloc support compiled in, do almost nothing.
56+
**************************************************************************/
57+
58+
#if !OPAL_HAVE_HWLOC
59+
/*
60+
* If hwloc support was not compiled in, then just return "Not
61+
* supported".
62+
*/
63+
int OMPI_Affinity_str(ompi_affinity_fmt_t fmt_type,
64+
char ompi_bound[OMPI_AFFINITY_STRING_MAX],
65+
char current_binding[OMPI_AFFINITY_STRING_MAX],
66+
char exists[OMPI_AFFINITY_STRING_MAX])
67+
{
68+
no_hwloc_support(ompi_bound, current_binding, exists);
69+
return MPI_SUCCESS;
70+
}
71+
#endif // !OPAL_HAVE_HWLOC
72+
73+
/**************************************************************************
74+
* If we have hwloc support compiled in, do the actual work.
75+
**************************************************************************/
76+
4177
#if OPAL_HAVE_HWLOC
78+
4279
static int get_rsrc_ompi_bound(char str[OMPI_AFFINITY_STRING_MAX]);
4380
static int get_rsrc_current_binding(char str[OMPI_AFFINITY_STRING_MAX]);
4481
static int get_rsrc_exists(char str[OMPI_AFFINITY_STRING_MAX]);
4582
static int get_layout_ompi_bound(char str[OMPI_AFFINITY_STRING_MAX]);
4683
static int get_layout_current_binding(char str[OMPI_AFFINITY_STRING_MAX]);
4784
static int get_layout_exists(char str[OMPI_AFFINITY_STRING_MAX]);
48-
#endif /* OPAL_HAVE_HWLOC */
4985

50-
/*---------------------------------------------------------------------------*/
5186

5287
int OMPI_Affinity_str(ompi_affinity_fmt_t fmt_type,
53-
char ompi_bound[OMPI_AFFINITY_STRING_MAX],
88+
char ompi_bound[OMPI_AFFINITY_STRING_MAX],
5489
char current_binding[OMPI_AFFINITY_STRING_MAX],
5590
char exists[OMPI_AFFINITY_STRING_MAX])
5691
{
57-
#if OPAL_HAVE_HWLOC
5892
int ret;
59-
#endif /* OPAL_HAVE_HWLOC */
6093

6194
memset(ompi_bound, 0, OMPI_AFFINITY_STRING_MAX);
6295
memset(current_binding, 0, OMPI_AFFINITY_STRING_MAX);
6396

6497
/* If we have no hwloc support, return nothing */
65-
#if OPAL_HAVE_HWLOC
66-
if (NULL == opal_hwloc_topology)
67-
#endif /* OPAL_HAVE_HWLOC */
68-
{
69-
strncpy(ompi_bound, "Not supported", OMPI_AFFINITY_STRING_MAX);
70-
strncpy(current_binding, "Not supported", OMPI_AFFINITY_STRING_MAX);
71-
strncpy(exists, "Not supported", OMPI_AFFINITY_STRING_MAX);
98+
if (NULL == opal_hwloc_topology) {
99+
no_hwloc_support(ompi_bound, current_binding, exists);
100+
72101
return MPI_SUCCESS;
73102
}
74103

75-
#if OPAL_HAVE_HWLOC
76104
/* Otherwise, return useful information */
77105
switch (fmt_type) {
78106
case OMPI_AFFINITY_RSRC_STRING_FMT:
@@ -94,10 +122,8 @@ int OMPI_Affinity_str(ompi_affinity_fmt_t fmt_type,
94122
}
95123

96124
return MPI_SUCCESS;
97-
#endif /* OPAL_HAVE_HWLOC */
98125
}
99126

100-
#if OPAL_HAVE_HWLOC
101127
/*---------------------------------------------------------------------------*/
102128

103129
/*

0 commit comments

Comments
 (0)