1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2005 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2015 Los Alamos National Security, LLC. All rights
14 * reserved.
15 * Copyright (c) 2016-2017 Intel, Inc. All rights reserved.
16 * $COPYRIGHT$
17 *
18 * Additional copyrights may follow
19 *
20 * $HEADER$
21 *
22 * These symbols are in a file by themselves to provide nice linker
23 * semantics. Since linkers generally pull in symbols by object
24 * files, keeping these symbols as the only symbols in this file
25 * prevents utility programs such as "ompi_info" from having to import
26 * entire components just to query their version and parameters.
27 */
28
29 #include "orte_config.h"
30 #include "orte/constants.h"
31
32 #include "opal/mca/pmix/pmix.h"
33 #include "opal/mca/pmix/base/base.h"
34
35 #include "orte/util/proc_info.h"
36 #include "orte/util/show_help.h"
37 #include "orte/mca/schizo/schizo.h"
38
39 #include "orte/mca/ess/ess.h"
40 #include "orte/mca/ess/singleton/ess_singleton.h"
41
42 extern orte_ess_base_module_t orte_ess_singleton_module;
43
44 static int component_open(void);
45 static int component_close(void);
46 static int component_query(mca_base_module_t **module, int *priority);
47 static int component_register(void);
48
49 /*
50 * Instantiate the public struct with all of our public information
51 * and pointers to our public functions in it
52 */
53 orte_ess_singleton_component_t mca_ess_singleton_component = {
54 {
55 /* First, the mca_component_t struct containing meta information
56 about the component itself */
57 .base_version = {
58 ORTE_ESS_BASE_VERSION_3_0_0,
59
60 /* Component name and version */
61 .mca_component_name = "singleton",
62 MCA_BASE_MAKE_VERSION(component, ORTE_MAJOR_VERSION, ORTE_MINOR_VERSION,
63 ORTE_RELEASE_VERSION),
64
65 /* Component open and close functions */
66 .mca_open_component = component_open,
67 .mca_close_component = component_close,
68 .mca_query_component = component_query,
69 .mca_register_component_params = component_register,
70 },
71 .base_data = {
72 /* The component is not checkpoint ready */
73 MCA_BASE_METADATA_PARAM_NONE
74 },
75 },
76 .server_uri = NULL,
77 .isolated = false
78 };
79
80 static int component_register(void)
81 {
82 int ret;
83
84 mca_ess_singleton_component.server_uri = NULL;
85 ret = mca_base_component_var_register(&mca_ess_singleton_component.super.base_version,
86 "server",
87 "Server to be used as HNP - [file|FILE]:<filename> or just uri",
88 MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
89 OPAL_INFO_LVL_9,
90 MCA_BASE_VAR_SCOPE_READONLY,
91 &mca_ess_singleton_component.server_uri);
92 (void) mca_base_var_register_synonym(ret, "orte", "orte", NULL, "server", 0);
93
94 ret = mca_base_component_var_register(&mca_ess_singleton_component.super.base_version,
95 "isolated",
96 "Do not start a supporting daemon as this process will never attempt to spawn",
97 MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
98 OPAL_INFO_LVL_9,
99 MCA_BASE_VAR_SCOPE_READONLY,
100 &mca_ess_singleton_component.isolated);
101
102 return ORTE_SUCCESS;
103 }
104
105 static int component_open(void)
106 {
107 return ORTE_SUCCESS;
108 }
109
110 static int component_query(mca_base_module_t **module, int *priority)
111 {
112 orte_schizo_launch_environ_t ret;
113
114 /* if we are an HNP, daemon, or tool, then we
115 * are definitely not a singleton!
116 */
117 if (ORTE_PROC_IS_HNP ||
118 ORTE_PROC_IS_DAEMON ||
119 ORTE_PROC_IS_TOOL) {
120 *module = NULL;
121 *priority = 0;
122 return ORTE_ERROR;
123 }
124
125 /* find out what our environment looks like */
126 ret = orte_schizo.check_launch_environment();
127 if (ORTE_SCHIZO_UNMANAGED_SINGLETON != ret &&
128 ORTE_SCHIZO_MANAGED_SINGLETON != ret) {
129 /* not us */
130 *module = NULL;
131 *priority = 0;
132 return ORTE_ERROR;
133 }
134
135 /* we may be incorrectly trying to run as a singleton - e.g.,
136 * someone direct-launched us under SLURM without building
137 * ORTE --with-slurm or in a slurm environment (so we didn't
138 * autodetect slurm). Try to detect that here. Sadly, we
139 * cannot just use the schizo framework to help us here as
140 * the corresponding schizo component may not have even
141 * been build. So we have to do things a little uglier */
142
143 if (ORTE_SCHIZO_UNMANAGED_SINGLETON == ret) {
144 /* see if we are in a SLURM allocation */
145 if (NULL != getenv("SLURM_NODELIST")) {
146 /* emit a hopefully helpful error message and abort */
147 orte_show_help("help-ess-base.txt", "slurm-error2", true);
148 *module = NULL;
149 *priority = 0;
150 return ORTE_ERR_SILENT;
151 }
152 /* see if we are under ALPS */
153 if (NULL != getenv("ALPS_APP_ID")) {
154 orte_show_help("help-ess-base.txt", "alps-error2", true);
155 *module = NULL;
156 *priority = 0;
157 return ORTE_ERR_SILENT;
158 }
159 }
160
161 /* okay, we want to be selected as we must be a singleton */
162 *priority = 100;
163 *module = (mca_base_module_t *)&orte_ess_singleton_module;
164 return ORTE_SUCCESS;
165 }
166
167
168 static int component_close(void)
169 {
170 return ORTE_SUCCESS;
171 }