Skip to content

Commit a4557d4

Browse files
author
Ralph Castain
committed
Add new component to support OpenMP envars per request from IBM and LLNL
1 parent 628364a commit a4557d4

File tree

7 files changed

+292
-2
lines changed

7 files changed

+292
-2
lines changed

orte/mca/rtc/omp/Makefile.am

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Copyright (c) 2015 Intel, Inc. All rights reserved
3+
# $COPYRIGHT$
4+
#
5+
# Additional copyrights may follow
6+
#
7+
# $HEADER$
8+
#
9+
10+
sources = \
11+
rtc_omp.c \
12+
rtc_omp.h \
13+
rtc_omp_component.c
14+
15+
# Make the output library in this directory, and name it either
16+
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
17+
# (for static builds).
18+
19+
if MCA_BUILD_orte_rtc_omp_DSO
20+
component_noinst =
21+
component_install = mca_rtc_omp.la
22+
else
23+
component_noinst = libmca_rtc_omp.la
24+
component_install =
25+
endif
26+
27+
mcacomponentdir = $(ortelibdir)
28+
mcacomponent_LTLIBRARIES = $(component_install)
29+
mca_rtc_omp_la_SOURCES = $(sources)
30+
mca_rtc_omp_la_LDFLAGS = -module -avoid-version
31+
32+
noinst_LTLIBRARIES = $(component_noinst)
33+
libmca_rtc_omp_la_SOURCES =$(sources)
34+
libmca_rtc_omp_la_LDFLAGS = -module -avoid-version

orte/mca/rtc/omp/owner.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# owner/status file
3+
# owner: institution that is responsible for this package
4+
# status: e.g. active, maintenance, unmaintained
5+
#
6+
owner: INTEL
7+
status: active

orte/mca/rtc/omp/rtc_omp.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright (c) 2015 Intel, Inc. All rights reserved
3+
* $COPYRIGHT$
4+
*
5+
* Additional copyrights may follow
6+
*
7+
* $HEADER$
8+
*/
9+
10+
#include "orte_config.h"
11+
#include "orte/constants.h"
12+
#include "orte/types.h"
13+
14+
#include <errno.h>
15+
#ifdef HAVE_UNISTD_H
16+
#include <unistd.h>
17+
#endif /* HAVE_UNISTD_H */
18+
#ifdef HAVE_STRING_H
19+
#include <string.h>
20+
#endif /* HAVE_STRING_H */
21+
22+
#include "opal/mca/hwloc/hwloc.h"
23+
#include "opal/util/argv.h"
24+
#include "opal/util/opal_environ.h"
25+
26+
#include "orte/util/show_help.h"
27+
#include "orte/util/error_strings.h"
28+
#include "orte/runtime/orte_globals.h"
29+
#include "orte/mca/errmgr/errmgr.h"
30+
#include "orte/mca/rmaps/rmaps_types.h"
31+
32+
#include "orte/mca/rtc/base/base.h"
33+
#include "rtc_omp.h"
34+
35+
static int init(void);
36+
static void finalize(void);
37+
static void set(orte_job_t *jdata,
38+
orte_proc_t *proc,
39+
char ***environ_copy,
40+
int write_fd);
41+
42+
orte_rtc_base_module_t orte_rtc_omp_module = {
43+
init,
44+
finalize,
45+
NULL,
46+
set,
47+
NULL
48+
};
49+
50+
static int init(void)
51+
{
52+
return ORTE_SUCCESS;
53+
}
54+
55+
static void finalize(void)
56+
{
57+
return;
58+
}
59+
60+
static void set(orte_job_t *jobdat,
61+
orte_proc_t *child,
62+
char ***environ_copy,
63+
int write_fd)
64+
{
65+
char *param;
66+
char *cpu_bitmap;
67+
char **ranges, *ptr, *tmp, **newrange, **results;
68+
int i, start, end;
69+
70+
opal_output_verbose(2, orte_rtc_base_framework.framework_output,
71+
"%s hwloc:set on child %s",
72+
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
73+
(NULL == child) ? "NULL" : ORTE_NAME_PRINT(&child->name));
74+
75+
if (NULL == jobdat || NULL == child) {
76+
/* nothing for us to do */
77+
opal_output_verbose(2, orte_rtc_base_framework.framework_output,
78+
"%s hwloc:set jobdat %s child %s - nothing to do",
79+
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
80+
(NULL == jobdat) ? "NULL" : ORTE_JOBID_PRINT(jobdat->jobid),
81+
(NULL == child) ? "NULL" : ORTE_NAME_PRINT(&child->name));
82+
return;
83+
}
84+
85+
/* See if we are bound */
86+
cpu_bitmap = NULL;
87+
if (!orte_get_attribute(&child->attributes, ORTE_PROC_CPU_BITMAP, (void**)&cpu_bitmap, OPAL_STRING) ||
88+
NULL == cpu_bitmap || 0 == strlen(cpu_bitmap)) {
89+
/* we are not bound, so indicate that by setting OMP_PROC_BIND = false */
90+
opal_setenv("OMP_PROC_BIND", "0", true, environ_copy);
91+
} else {
92+
/* we are bound to something, so indicate that by setting OMP_PROC_BIND = true */
93+
opal_setenv("OMP_PROC_BIND", "1", true, environ_copy);
94+
/* compose OMP_PLACES to indicate where we are bound - sadly, the OMP folks
95+
* use a different syntax than HWLOC, an so we can't just provide the bitmap
96+
* string. So we will traverse the bitmap and convert as required */
97+
ranges = opal_argv_split(cpu_bitmap, ',');
98+
newrange = NULL;
99+
results = NULL;
100+
for (i=0; NULL != ranges[i]; i++) {
101+
if (NULL == (ptr = strchr(ranges[i], '-'))) {
102+
opal_argv_append_nosize(&newrange, ranges[i]);
103+
} else {
104+
/* terminate any existing range */
105+
if (NULL != newrange) {
106+
param = opal_argv_join(newrange, ',');
107+
asprintf(&tmp, "{%s}", param);
108+
opal_argv_append_nosize(&results, tmp);
109+
free(tmp);
110+
free(param);
111+
opal_argv_free(newrange);
112+
newrange = NULL;
113+
}
114+
*ptr = '\0';
115+
++ptr;
116+
start = strtol(ranges[i], NULL, 10);
117+
end = strtol(ptr, NULL, 10);
118+
asprintf(&tmp, "{%d:%d}", start, end - start + 1);
119+
opal_argv_append_nosize(&results, tmp);
120+
free(tmp);
121+
}
122+
}
123+
opal_argv_free(ranges);
124+
if (NULL != newrange) {
125+
param = opal_argv_join(newrange, ',');
126+
asprintf(&tmp, "{%s}", param);
127+
opal_argv_append_nosize(&results, tmp);
128+
free(tmp);
129+
free(param);
130+
opal_argv_free(newrange);
131+
newrange = NULL;
132+
}
133+
param = opal_argv_join(results, ',');
134+
opal_argv_free(results);
135+
opal_setenv("OMP_PLACES", param, true, environ_copy);
136+
free(param);
137+
}
138+
if (NULL != cpu_bitmap) {
139+
free(cpu_bitmap);
140+
}
141+
}

orte/mca/rtc/omp/rtc_omp.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2015 Intel, Inc. All rights reserved
3+
* $COPYRIGHT$
4+
*
5+
* Additional copyrights may follow
6+
*
7+
* $HEADER$
8+
*/
9+
/**
10+
* @file
11+
*/
12+
#ifndef ORTE_RTC_OMP_H
13+
#define ORTE_RTC_OMP_H
14+
15+
#include "orte_config.h"
16+
17+
#include "orte/mca/rtc/rtc.h"
18+
19+
BEGIN_C_DECLS
20+
21+
ORTE_MODULE_DECLSPEC extern orte_rtc_base_component_t mca_rtc_omp_component;
22+
23+
extern orte_rtc_base_module_t orte_rtc_omp_module;
24+
25+
26+
END_C_DECLS
27+
28+
#endif /* ORTE_RTC_OMP_H */
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2015 Intel, Inc. All rights reserved
4+
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
5+
* reserved.
6+
* $COPYRIGHT$
7+
*
8+
* Additional copyrights may follow
9+
*
10+
* $HEADER$
11+
*/
12+
13+
#include "orte_config.h"
14+
#include "orte/constants.h"
15+
16+
#include "opal/mca/base/base.h"
17+
18+
#include "rtc_omp.h"
19+
20+
/*
21+
* Local functions
22+
*/
23+
24+
static int rtc_omp_query(mca_base_module_t **module, int *priority);
25+
static int rtc_omp_register(void);
26+
27+
static int my_priority;
28+
29+
orte_rtc_base_component_t mca_rtc_omp_component = {
30+
.base_version = {
31+
ORTE_RTC_BASE_VERSION_1_0_0,
32+
33+
.mca_component_name = "omp",
34+
MCA_BASE_MAKE_VERSION(component, ORTE_MAJOR_VERSION, ORTE_MINOR_VERSION,
35+
ORTE_RELEASE_VERSION),
36+
.mca_query_component = rtc_omp_query,
37+
.mca_register_component_params = rtc_omp_register,
38+
},
39+
.base_data = {
40+
/* The component is checkpoint ready */
41+
MCA_BASE_METADATA_PARAM_CHECKPOINT
42+
},
43+
};
44+
45+
46+
static int rtc_omp_register(void)
47+
{
48+
mca_base_component_t *c = &mca_rtc_omp_component.base_version;
49+
50+
/* set below the default */
51+
my_priority = 50;
52+
(void) mca_base_component_var_register (c, "priority", "Priority of the OMP rtc component",
53+
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
54+
OPAL_INFO_LVL_9,
55+
MCA_BASE_VAR_SCOPE_READONLY,
56+
&my_priority);
57+
58+
return ORTE_SUCCESS;
59+
}
60+
61+
62+
static int rtc_omp_query(mca_base_module_t **module, int *priority)
63+
{
64+
/* Only run on the HNP */
65+
66+
*priority = my_priority;
67+
*module = (mca_base_module_t *)&orte_rtc_omp_module;
68+
69+
return ORTE_SUCCESS;
70+
}

orte/runtime/data_type_support/orte_dt_packing_fns.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,11 @@ int orte_dt_pack_map(opal_buffer_t *buffer, const void *src,
570570
ORTE_ERROR_LOG(rc);
571571
return rc;
572572
}
573-
573+
/* pack the cpus/rank */
574+
if (ORTE_SUCCESS != (rc = opal_dss_pack_buffer(buffer, &(maps[i]->cpus_per_rank), 1, OPAL_INT16))) {
575+
ORTE_ERROR_LOG(rc);
576+
return rc;
577+
}
574578
/* pack the display map flag */
575579
if (ORTE_SUCCESS != (rc = opal_dss_pack_buffer(buffer, &(maps[i]->display_map), 1, OPAL_BOOL))) {
576580
ORTE_ERROR_LOG(rc);

orte/runtime/data_type_support/orte_dt_unpacking_fns.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,13 @@ int orte_dt_unpack_map(opal_buffer_t *buffer, void *dest,
641641
ORTE_ERROR_LOG(rc);
642642
return rc;
643643
}
644-
644+
/* unpack the cpus/rank */
645+
n = 1;
646+
if (ORTE_SUCCESS != (rc = opal_dss_unpack_buffer(buffer,
647+
&(maps[i]->cpus_per_rank), &n, OPAL_INT16))) {
648+
ORTE_ERROR_LOG(rc);
649+
return rc;
650+
}
645651
/* unpack the display map flag */
646652
n = 1;
647653
if (ORTE_SUCCESS != (rc = opal_dss_unpack_buffer(buffer,

0 commit comments

Comments
 (0)