-
Notifications
You must be signed in to change notification settings - Fork 884
/
Copy pathorted_submit.c
3306 lines (2989 loc) · 122 KB
/
orted_submit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2008 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006-2017 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2007-2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2007-2017 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2013-2018 Intel, Inc. All rights reserved.
* Copyright (c) 2015-2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2017-2021 IBM Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "orte_config.h"
#include "orte/constants.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <errno.h>
#include <signal.h>
#include <ctype.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif /* HAVE_SYS_WAIT_H */
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */
#include <fcntl.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include <poll.h>
#include "opal/dss/dss.h"
#include "opal/mca/event/event.h"
#include "opal/mca/installdirs/installdirs.h"
#include "opal/mca/hwloc/base/base.h"
#include "opal/mca/base/base.h"
#include "opal/mca/pmix/pmix.h"
#include "opal/util/argv.h"
#include "opal/util/output.h"
#include "opal/util/basename.h"
#include "opal/util/cmd_line.h"
#include "opal/util/opal_environ.h"
#include "opal/util/opal_getcwd.h"
#include "opal/util/show_help.h"
#include "opal/util/fd.h"
#include "opal/sys/atomic.h"
#if OPAL_ENABLE_FT_CR == 1
#include "opal/runtime/opal_cr.h"
#endif
#include "opal/version.h"
#include "opal/runtime/opal.h"
#include "opal/runtime/opal_info_support.h"
#include "opal/util/os_path.h"
#include "opal/util/path.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/dss/dss.h"
#include "orte/mca/odls/odls_types.h"
#include "orte/mca/plm/plm.h"
#include "orte/mca/rmaps/rmaps_types.h"
#include "orte/mca/rmaps/base/base.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/grpcomm/grpcomm.h"
#include "orte/mca/oob/base/base.h"
#include "orte/mca/plm/base/plm_private.h"
#include "orte/mca/rml/rml.h"
#include "orte/mca/rml/base/rml_contact.h"
#include "orte/mca/routed/routed.h"
#include "orte/mca/schizo/base/base.h"
#include "orte/mca/state/state.h"
#include "orte/runtime/runtime.h"
#include "orte/runtime/orte_globals.h"
#include "orte/runtime/orte_wait.h"
#include "orte/runtime/orte_quit.h"
#include "orte/util/pre_condition_transports.h"
#include "orte/util/show_help.h"
#include "orted_submit.h"
#include "orted-mpir/orted_mpir.h"
/**
* Global struct for catching orte command line options.
*/
orte_cmd_options_t orte_cmd_options = {0};
opal_cmd_line_t *orte_cmd_line = NULL;
static char **global_mca_env = NULL;
static orte_std_cntr_t total_num_apps = 0;
static bool want_prefix_by_default = (bool) ORTE_WANT_ORTERUN_PREFIX_BY_DEFAULT;
static opal_pointer_array_t tool_jobs;
static int timeout_seconds;
static orte_timer_t *orte_memprofile_timeout;
int orte_debugger_attach_fd = -1;
bool orte_debugger_fifo_active=false;
opal_event_t *orte_debugger_attach=NULL;
/*
* Local functions
*/
static int create_app(int argc, char* argv[],
orte_job_t *jdata,
orte_app_context_t **app,
bool *made_app, char ***app_env);
static int init_globals(void);
static int parse_globals(int argc, char* argv[], opal_cmd_line_t *cmd_line);
static int parse_locals(orte_job_t *jdata, int argc, char* argv[]);
static void set_classpath_jar_file(orte_app_context_t *app, int index, char *jarfile);
static int parse_appfile(orte_job_t *jdata, char *filename, char ***env);
static void orte_timeout_wakeup(int sd, short args, void *cbdata);
static void orte_profile_wakeup(int sd, short args, void *cbdata);
static void profile_recv(int status, orte_process_name_t* sender,
opal_buffer_t *buffer, orte_rml_tag_t tag,
void* cbdata);
static void launch_recv(int status, orte_process_name_t* sender,
opal_buffer_t *buffer,
orte_rml_tag_t tag, void *cbdata);
static void complete_recv(int status, orte_process_name_t* sender,
opal_buffer_t *buffer,
orte_rml_tag_t tag, void *cbdata);
static void attach_debugger(int fd, short event, void *arg);
static void build_debugger_args(orte_app_context_t *debugger);
static void open_fifo (void);
static void run_debugger(char *basename, opal_cmd_line_t *cmd_line,
int argc, char *argv[], int num_procs);
static void print_help(void);
static void orte_debugger_init_before_spawn(orte_job_t *jdata);
/* local objects */
typedef struct {
opal_object_t super;
orte_job_t *jdata;
int index;
orte_submit_cbfunc_t launch_cb;
void *launch_cbdata;
orte_submit_cbfunc_t complete_cb;
void *complete_cbdata;
} trackr_t;
static void tcon(trackr_t *p)
{
p->jdata = NULL;
p->launch_cb = NULL;
p->launch_cbdata = NULL;
p->complete_cb = NULL;
p->complete_cbdata = NULL;
}
static void tdes(trackr_t *p)
{
if (NULL != p->jdata) {
OBJ_RELEASE(p->jdata);
}
}
static OBJ_CLASS_INSTANCE(trackr_t,
opal_object_t,
tcon, tdes);
int orte_submit_init(int argc, char *argv[],
opal_cmd_line_init_t *opts)
{
int rc, i;
char *param;
/* init the globals */
memset(&orte_cmd_options, 0, sizeof(orte_cmd_options));
/* find our basename (the name of the executable) so that we can
use it in pretty-print error messages */
orte_basename = opal_basename(argv[0]);
/* search the argv for MCA params */
for (i=0; NULL != argv[i]; i++) {
if (':' == argv[i][0] ||
NULL == argv[i+1] || NULL == argv[i+2]) {
break;
}
if (0 == strncmp(argv[i], "-"OPAL_MCA_CMD_LINE_ID, strlen("-"OPAL_MCA_CMD_LINE_ID)) ||
0 == strncmp(argv[i], "--"OPAL_MCA_CMD_LINE_ID, strlen("--"OPAL_MCA_CMD_LINE_ID)) ||
0 == strncmp(argv[i], "-g"OPAL_MCA_CMD_LINE_ID, strlen("-g"OPAL_MCA_CMD_LINE_ID)) ||
0 == strncmp(argv[i], "--g"OPAL_MCA_CMD_LINE_ID, strlen("--g"OPAL_MCA_CMD_LINE_ID))) {
(void) mca_base_var_env_name (argv[i+1], ¶m);
opal_setenv(param, argv[i+2], true, &environ);
free(param);
} else if (0 == strcmp(argv[i], "-am") ||
0 == strcmp(argv[i], "--am")) {
(void)mca_base_var_env_name("mca_base_param_file_prefix", ¶m);
opal_setenv(param, argv[i+1], true, &environ);
free(param);
} else if (0 == strcmp(argv[i], "-tune") ||
0 == strcmp(argv[i], "--tune")) {
(void)mca_base_var_env_name("mca_base_envar_file_prefix", ¶m);
opal_setenv(param, argv[i+1], true, &environ);
free(param);
}
}
/* init only the util portion of OPAL */
if (OPAL_SUCCESS != (rc = opal_init_util(&argc, &argv))) {
return rc;
}
/* open the SCHIZO framework so we can setup the command line */
if (ORTE_SUCCESS != (rc = mca_base_framework_open(&orte_schizo_base_framework, 0))) {
ORTE_ERROR_LOG(rc);
return rc;
}
if (ORTE_SUCCESS != (rc = orte_schizo_base_select())) {
ORTE_ERROR_LOG(rc);
return rc;
}
OBJ_CONSTRUCT(&tool_jobs, opal_pointer_array_t);
opal_pointer_array_init(&tool_jobs, 256, INT_MAX, 128);
/* setup the cmd line */
orte_cmd_line = OBJ_NEW(opal_cmd_line_t);
/* if they were provided, add the opts */
if (NULL != opts) {
if (OPAL_SUCCESS != (rc = opal_cmd_line_add(orte_cmd_line, opts))) {
return rc;
}
}
/* setup the rest of the cmd line only once */
if (OPAL_SUCCESS != (rc = orte_schizo.define_cli(orte_cmd_line))) {
return rc;
}
/* now that options have been defined, finish setup */
mca_base_cmd_line_setup(orte_cmd_line);
/* parse the result to get values */
if (OPAL_SUCCESS != (rc = opal_cmd_line_parse(orte_cmd_line,
true, false, argc, argv)) ) {
if (OPAL_ERR_SILENT != rc) {
fprintf(stderr, "%s: command line error (%s)\n", argv[0],
opal_strerror(rc));
}
return rc;
}
/* see if print version is requested. Do this before
* check for help so that --version --help works as
* one might expect. */
if (orte_cmd_options.version) {
char *str, *project_name = NULL;
if (0 == strcmp(orte_basename, "mpirun")) {
project_name = "Open MPI";
} else {
project_name = "OpenRTE";
}
str = opal_info_make_version_str("all",
OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
OPAL_GREEK_VERSION,
OPAL_REPO_REV);
if (NULL != str) {
fprintf(stdout, "%s (%s) %s\n\nReport bugs to %s\n",
orte_basename, project_name, str, PACKAGE_BUGREPORT);
free(str);
}
exit(0);
}
/* check if we are running as root - if we are, then only allow
* us to proceed if the allow-run-as-root flag was given. Otherwise,
* exit with a giant warning flag
*/
if (0 == geteuid() && !orte_cmd_options.run_as_root) {
/* show_help is not yet available, so print an error manually */
fprintf(stderr, "--------------------------------------------------------------------------\n");
if (orte_cmd_options.help) {
fprintf(stderr, "%s cannot provide the help message when run as root.\n\n", orte_basename);
} else {
fprintf(stderr, "%s has detected an attempt to run as root.\n\n", orte_basename);
}
fprintf(stderr, "Running as root is *strongly* discouraged as any mistake (e.g., in\n");
fprintf(stderr, "defining TMPDIR) or bug can result in catastrophic damage to the OS\n");
fprintf(stderr, "file system, leaving your system in an unusable state.\n\n");
fprintf(stderr, "We strongly suggest that you run %s as a non-root user.\n\n", orte_basename);
fprintf(stderr, "You can override this protection by adding the --allow-run-as-root\n");
fprintf(stderr, "option to your command line. However, we reiterate our strong advice\n");
fprintf(stderr, "against doing so - please do so at your own risk.\n");
fprintf(stderr, "--------------------------------------------------------------------------\n");
exit(1);
}
/* process any mca params */
rc = mca_base_cmd_line_process_args(orte_cmd_line, &environ, &environ);
if (ORTE_SUCCESS != rc) {
return rc;
}
/* Need to initialize OPAL so that install_dirs are filled in */
if (OPAL_SUCCESS != (rc = opal_init(&argc, &argv))) {
return rc;
}
/* Check for help request */
if (NULL != orte_cmd_options.help) {
print_help();
/* If someone asks for help, that should be all we do */
exit(0);
}
/* if they already set our proc type, then leave it alone */
if (ORTE_PROC_TYPE_NONE == orte_process_info.proc_type) {
/* set the flags - if they gave us a -hnp option, then
* we are a tool. If not, then we are an HNP */
if (NULL == orte_cmd_options.hnp) {
orte_process_info.proc_type = ORTE_PROC_HNP;
} else {
orte_process_info.proc_type = ORTE_PROC_TOOL;
}
}
if (ORTE_PROC_IS_TOOL) {
if (0 == strncasecmp(orte_cmd_options.hnp, "file", strlen("file"))) {
char input[1024], *filename;
FILE *fp;
/* it is a file - get the filename */
filename = strchr(orte_cmd_options.hnp, ':');
if (NULL == filename) {
/* filename is not correctly formatted */
orte_show_help("help-orte-top.txt", "orte-top:hnp-filename-bad", true, "uri", orte_cmd_options.hnp);
exit(1);
}
++filename; /* space past the : */
if (0 >= strlen(filename)) {
/* they forgot to give us the name! */
orte_show_help("help-orte-top.txt", "orte-top:hnp-filename-bad", true, "uri", orte_cmd_options.hnp);
exit(1);
}
/* open the file and extract the uri */
fp = fopen(filename, "r");
if (NULL == fp) { /* can't find or read file! */
orte_show_help("help-orte-top.txt", "orte-top:hnp-filename-access", true, orte_cmd_options.hnp);
exit(1);
}
/* initialize the input to NULLs to ensure any input
* string is NULL-terminated */
memset(input, 0, 1024);
if (NULL == fgets(input, 1024, fp)) {
/* something malformed about file */
fclose(fp);
orte_show_help("help-orte-top.txt", "orte-top:hnp-file-bad", true, orte_cmd_options.hnp);
exit(1);
}
fclose(fp);
input[strlen(input)-1] = '\0'; /* remove newline */
/* construct the target hnp info */
opal_setenv(OPAL_MCA_PREFIX"orte_hnp_uri", input, true, &environ);
} else {
/* should just be the uri itself - construct the target hnp info */
opal_setenv(OPAL_MCA_PREFIX"orte_hnp_uri", orte_cmd_options.hnp, true, &environ);
}
/* we are never allowed to operate as a distributed tool,
* so insist on the ess/tool component */
opal_setenv(OPAL_MCA_PREFIX"ess", "tool", true, &environ);
} else {
/* may look strange, but the way we handle prefix is a little weird
* and probably needs to be addressed more fully at some future point.
* For now, we have a conflict between app_files and cmd line usage.
* Since app_files are used by the C/R system, we will make an
* adjustment here to avoid perturbing that system.
*
* We cannot just have the cmd line parser place any found value
* in the global struct as the app_file parser would replace it.
* So handle this specific cmd line option manually.
*/
orte_cmd_options.prefix = NULL;
orte_cmd_options.path_to_mpirun = NULL;
if (opal_cmd_line_is_taken(orte_cmd_line, "prefix") ||
'/' == argv[0][0] || want_prefix_by_default) {
size_t param_len;
if ('/' == argv[0][0]) {
char* tmp_basename = NULL;
/* If they specified an absolute path, strip off the
/bin/<exec_name>" and leave just the prefix */
orte_cmd_options.path_to_mpirun = opal_dirname(argv[0]);
/* Quick sanity check to ensure we got
something/bin/<exec_name> and that the installation
tree is at least more or less what we expect it to
be */
tmp_basename = opal_basename(orte_cmd_options.path_to_mpirun);
if (0 == strcmp("bin", tmp_basename)) {
char* tmp = orte_cmd_options.path_to_mpirun;
orte_cmd_options.path_to_mpirun = opal_dirname(tmp);
free(tmp);
} else {
free(orte_cmd_options.path_to_mpirun);
orte_cmd_options.path_to_mpirun = NULL;
}
free(tmp_basename);
}
/* if both are given, check to see if they match */
if (opal_cmd_line_is_taken(orte_cmd_line, "prefix") &&
NULL != orte_cmd_options.path_to_mpirun) {
char *tmp_basename;
/* if they don't match, then that merits a warning */
param = strdup(opal_cmd_line_get_param(orte_cmd_line, "prefix", 0, 0));
/* ensure we strip any trailing '/' */
if (0 == strcmp(OPAL_PATH_SEP, &(param[strlen(param)-1]))) {
param[strlen(param)-1] = '\0';
}
tmp_basename = strdup(orte_cmd_options.path_to_mpirun);
if (0 == strcmp(OPAL_PATH_SEP, &(tmp_basename[strlen(tmp_basename)-1]))) {
tmp_basename[strlen(tmp_basename)-1] = '\0';
}
if (0 != strcmp(param, tmp_basename)) {
orte_show_help("help-orterun.txt", "orterun:double-prefix",
true, orte_basename, orte_basename,
param, tmp_basename, orte_basename);
/* use the prefix over the path-to-mpirun so that
* people can specify the backend prefix as different
* from the local one
*/
free(orte_cmd_options.path_to_mpirun);
orte_cmd_options.path_to_mpirun = NULL;
}
free(tmp_basename);
} else if (NULL != orte_cmd_options.path_to_mpirun) {
param = strdup(orte_cmd_options.path_to_mpirun);
} else if (opal_cmd_line_is_taken(orte_cmd_line, "prefix")){
/* must be --prefix alone */
param = strdup(opal_cmd_line_get_param(orte_cmd_line, "prefix", 0, 0));
} else {
/* --enable-orterun-prefix-default was given to orterun */
param = strdup(opal_install_dirs.prefix);
}
if (NULL != param) {
/* "Parse" the param, aka remove superfluous path_sep. */
param_len = strlen(param);
while (0 == strcmp (OPAL_PATH_SEP, &(param[param_len-1]))) {
param[param_len-1] = '\0';
param_len--;
if (0 == param_len) {
orte_show_help("help-orterun.txt", "orterun:empty-prefix",
true, orte_basename, orte_basename);
free(param);
return ORTE_ERR_FATAL;
}
}
orte_cmd_options.prefix = param;
}
want_prefix_by_default = true;
}
}
/* Setup MCA params */
orte_register_params();
if (orte_cmd_options.debug) {
orte_devel_level_output = true;
}
/* Initialize our Open RTE environment
* Set the flag telling orte_init that I am NOT a
* singleton, but am "infrastructure" - prevents setting
* up incorrect infrastructure that only a singleton would
* require
*/
if (ORTE_SUCCESS != (rc = orte_init(&argc, &argv,
orte_process_info.proc_type))) {
/* cannot call ORTE_ERROR_LOG as it could be the errmgr
* never got loaded!
*/
return rc;
}
/* finalize OPAL. As it was opened again from orte_init->opal_init
* we continue to have a reference count on it. So we have to finalize it twice...
*/
opal_finalize();
if (ORTE_PROC_IS_TOOL) {
opal_value_t val;
/* extract the name */
if (ORTE_SUCCESS != orte_rml_base_parse_uris(orte_process_info.my_hnp_uri, ORTE_PROC_MY_HNP, NULL)) {
orte_show_help("help-orte-top.txt", "orte-top:hnp-uri-bad", true, orte_process_info.my_hnp_uri);
exit(1);
}
/* set the info in our contact table */
OBJ_CONSTRUCT(&val, opal_value_t);
val.key = OPAL_PMIX_PROC_URI;
val.type = OPAL_STRING;
val.data.string = orte_process_info.my_hnp_uri;
if (OPAL_SUCCESS != opal_pmix.store_local(ORTE_PROC_MY_HNP, &val)) {
val.key = NULL;
val.data.string = NULL;
OBJ_DESTRUCT(&val);
orte_show_help("help-orte-top.txt", "orte-top:hnp-uri-bad", true, orte_process_info.my_hnp_uri);
orte_finalize();
exit(1);
}
val.key = NULL;
val.data.string = NULL;
OBJ_DESTRUCT(&val);
/* set the route to be direct */
if (ORTE_SUCCESS != orte_routed.update_route(NULL, ORTE_PROC_MY_HNP, ORTE_PROC_MY_HNP)) {
orte_show_help("help-orte-top.txt", "orte-top:hnp-uri-bad", true, orte_process_info.my_hnp_uri);
orte_finalize();
exit(1);
}
/* set the target hnp as our lifeline so we will terminate if it exits */
orte_routed.set_lifeline(NULL, ORTE_PROC_MY_HNP);
/* setup to listen for HNP response to my commands */
orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, ORTE_RML_TAG_NOTIFY_COMPLETE,
ORTE_RML_PERSISTENT, complete_recv, NULL);
orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, ORTE_RML_TAG_LAUNCH_RESP,
ORTE_RML_PERSISTENT, launch_recv, NULL);
} else {
/* save the environment for launch purposes. This MUST be
* done so that we can pass it to any local procs we
* spawn - otherwise, those local procs won't see any
* non-MCA envars were set in the enviro prior to calling
* orterun
*/
orte_launch_environ = opal_argv_copy(environ);
/* clear params from the environment so our children
* don't pick them up */
opal_unsetenv(OPAL_MCA_PREFIX"ess", &orte_launch_environ);
opal_unsetenv(OPAL_MCA_PREFIX"pmix", &orte_launch_environ);
}
return ORTE_SUCCESS;
}
static void print_help()
{
char *str = NULL, *args;
char *project_name = NULL;
if (0 == strcmp(orte_basename, "mpirun")) {
project_name = "Open MPI";
} else {
project_name = "OpenRTE";
}
args = opal_cmd_line_get_usage_msg(orte_cmd_line);
str = opal_show_help_string("help-orterun.txt", "orterun:usage", false,
orte_basename, project_name, OPAL_VERSION,
orte_basename, args,
PACKAGE_BUGREPORT);
if (NULL != str) {
printf("%s", str);
free(str);
}
free(args);
}
void orte_submit_finalize(void)
{
trackr_t *trk;
int i, rc;
for (i=0; i < tool_jobs.size; i++) {
if (NULL != (trk = (trackr_t*)opal_pointer_array_get_item(&tool_jobs, i))) {
OBJ_RELEASE(trk);
}
}
OBJ_DESTRUCT(&tool_jobs);
/* close the SCHIZO framework */
if (ORTE_SUCCESS != (rc = mca_base_framework_close(&orte_schizo_base_framework))) {
ORTE_ERROR_LOG(rc);
return;
}
/* finalize only the util portion of OPAL */
if (OPAL_SUCCESS != (rc = opal_finalize_util())) {
return;
}
/* destruct the cmd line object */
if (NULL != orte_cmd_line) {
OBJ_RELEASE(orte_cmd_line);
}
/* if it was created, remove the debugger attach fifo */
if (0 <= orte_debugger_attach_fd) {
if (orte_debugger_fifo_active) {
opal_event_del(orte_debugger_attach);
free(orte_debugger_attach);
}
close(orte_debugger_attach_fd);
unlink(MPIR_attach_fifo);
}
if (NULL != orte_cmd_options.prefix) {
free(orte_cmd_options.prefix);
}
if (NULL != orte_launch_environ) {
opal_argv_free(orte_launch_environ);
}
if (NULL != orte_basename) {
free(orte_basename);
}
}
int orte_submit_cancel(int index) {
int rc;
trackr_t *trk;
opal_buffer_t *req;
orte_daemon_cmd_flag_t cmd = ORTE_DAEMON_TERMINATE_JOB_CMD;
/* get the tracker */
if (NULL == (trk = (trackr_t*)opal_pointer_array_get_item(&tool_jobs, index))) {
opal_output(0, "TRACKER ID %d RETURNED INDEX TO NULL OBJECT", index);
return ORTE_ERROR;
}
/* create and send request with command and jobid */
req = OBJ_NEW(opal_buffer_t);
if (OPAL_SUCCESS != (rc = opal_dss.pack(req, &cmd, 1, ORTE_DAEMON_CMD))) {
ORTE_ERROR_LOG(rc);
return rc;
}
if (OPAL_SUCCESS != (rc = opal_dss.pack(req, &trk->jdata->jobid, 1, ORTE_JOBID))) {
ORTE_ERROR_LOG(rc);
return rc;
}
rc = orte_rml.send_buffer_nb(orte_mgmt_conduit,
ORTE_PROC_MY_HNP, req, ORTE_RML_TAG_DAEMON,
orte_rml_send_callback, NULL);
if (ORTE_SUCCESS != rc) {
ORTE_ERROR_LOG(rc);
OBJ_RELEASE(req);
return rc;
}
return ORTE_ERR_OP_IN_PROGRESS;
}
int orte_submit_halt(void)
{
int rc;
opal_buffer_t *req;
orte_daemon_cmd_flag_t cmd = ORTE_DAEMON_HALT_DVM_CMD;
req = OBJ_NEW(opal_buffer_t);
if (OPAL_SUCCESS != (rc = opal_dss.pack(req, &cmd, 1, ORTE_DAEMON_CMD))) {
ORTE_ERROR_LOG(rc);
return rc;
}
rc = orte_rml.send_buffer_nb(orte_mgmt_conduit,
ORTE_PROC_MY_HNP, req,
ORTE_RML_TAG_DAEMON,
orte_rml_send_callback, NULL);
if (ORTE_SUCCESS != rc) {
ORTE_ERROR_LOG(rc);
OBJ_RELEASE(req);
return rc;
}
return ORTE_ERR_OP_IN_PROGRESS;
}
//
// The real thing
//
int orte_submit_job(char *argv[], int *index,
orte_submit_cbfunc_t launch_cb,
void *launch_cbdata,
orte_submit_cbfunc_t complete_cb,
void *complete_cbdata)
{
opal_buffer_t *req;
int rc, n;
orte_app_idx_t i;
orte_daemon_cmd_flag_t cmd = ORTE_DAEMON_SPAWN_JOB_CMD;
char *param;
orte_job_t *jdata = NULL, *daemons;
orte_app_context_t *app, *dapp;
trackr_t *trk;
int argc;
/* bozo check - we don't allow recursive calls of submit */
if (NULL != getenv("OMPI_UNIVERSE_SIZE")) {
fprintf(stderr, "\n\n**********************************************************\n\n");
fprintf(stderr, "%s does not support recursive calls\n", orte_basename);
fprintf(stderr, "\n**********************************************************\n");
return ORTE_ERR_FATAL;
}
/* reset the globals every time thru as the argv
* will modify them */
init_globals();
argc = opal_argv_count(argv);
/* parse the cmd line - do this every time thru so we can
* repopulate the globals */
if (OPAL_SUCCESS != (rc = opal_cmd_line_parse(orte_cmd_line, true, false,
argc, argv)) ) {
if (OPAL_ERR_SILENT != rc) {
fprintf(stderr, "%s: command line error (%s)\n", argv[0],
opal_strerror(rc));
}
return rc;
}
/* Check for some "global" command line params */
parse_globals(argc, argv, orte_cmd_line);
/* create a new job object to hold the info for this one - the
* jobid field will be filled in by the PLM when the job is
* launched
*/
jdata = OBJ_NEW(orte_job_t);
if (NULL == jdata) {
/* cannot call ORTE_ERROR_LOG as the errmgr
* hasn't been loaded yet!
*/
return ORTE_ERR_OUT_OF_RESOURCE;
}
/* see if they specified the personality */
if (NULL != orte_cmd_options.personality) {
jdata->personality = opal_argv_split(orte_cmd_options.personality, ',');
} else {
/* default to OMPI */
opal_argv_append_nosize(&jdata->personality, "ompi");
}
trk = OBJ_NEW(trackr_t);
trk->jdata = jdata;
trk->launch_cb = launch_cb;
trk->launch_cbdata = launch_cbdata;
trk->complete_cb = complete_cb;
trk->complete_cbdata = complete_cbdata;
trk->index = opal_pointer_array_add(&tool_jobs, trk);
/* pass our tracker ID */
orte_set_attribute(&jdata->attributes, ORTE_JOB_ROOM_NUM, ORTE_ATTR_GLOBAL, &trk->index, OPAL_INT);
/* check for stdout/err directives */
/* if we were asked to tag output, mark it so */
if (orte_cmd_options.tag_output) {
orte_set_attribute(&jdata->attributes, ORTE_JOB_TAG_OUTPUT, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
}
/* if we were asked to timestamp output, mark it so */
if (orte_cmd_options.timestamp_output) {
orte_set_attribute(&jdata->attributes, ORTE_JOB_TIMESTAMP_OUTPUT, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
}
/* if we were asked to output to files, pass it along */
if (NULL != orte_cmd_options.output_filename) {
/* if the given filename isn't an absolute path, then
* convert it to one so the name will be relative to
* the directory where prun was given as that is what
* the user will have seen */
if (!opal_path_is_absolute(orte_cmd_options.output_filename)) {
char cwd[OPAL_PATH_MAX], *path;
getcwd(cwd, sizeof(cwd));
path = opal_os_path(false, cwd, orte_cmd_options.output_filename, NULL);
orte_set_attribute(&jdata->attributes, ORTE_JOB_OUTPUT_TO_FILE, ORTE_ATTR_GLOBAL, path, OPAL_STRING);
free(path);
} else {
orte_set_attribute(&jdata->attributes, ORTE_JOB_OUTPUT_TO_FILE, ORTE_ATTR_GLOBAL, orte_cmd_options.output_filename, OPAL_STRING);
}
}
/* if we were asked to merge stderr to stdout, mark it so */
if (orte_cmd_options.merge) {
orte_set_attribute(&jdata->attributes, ORTE_JOB_MERGE_STDERR_STDOUT, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
}
/* check what user wants us to do with stdin */
if (NULL != orte_cmd_options.stdin_target) {
if (0 == strcmp(orte_cmd_options.stdin_target, "all")) {
jdata->stdin_target = ORTE_VPID_WILDCARD;
} else if (0 == strcmp(orte_cmd_options.stdin_target, "none")) {
jdata->stdin_target = ORTE_VPID_INVALID;
} else {
jdata->stdin_target = strtoul(orte_cmd_options.stdin_target, NULL, 10);
}
}
/* if we want the argv's indexed, indicate that */
if (orte_cmd_options.index_argv) {
orte_set_attribute(&jdata->attributes, ORTE_JOB_INDEX_ARGV, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
}
/* Parse each app, adding it to the job object */
parse_locals(jdata, argc, argv);
if (0 == jdata->num_apps) {
/* This should never happen -- this case should be caught in
create_app(), but let's just double check... */
orte_show_help("help-orterun.txt", "orterun:nothing-to-do",
true, orte_basename);
ORTE_UPDATE_EXIT_STATUS(ORTE_ERROR_DEFAULT_EXIT_CODE);
return ORTE_ERR_FATAL;
}
/* create the map object to communicate policies */
jdata->map = OBJ_NEW(orte_job_map_t);
if (NULL != orte_cmd_options.mapping_policy) {
if (ORTE_SUCCESS != (rc = orte_rmaps_base_set_mapping_policy(jdata, &jdata->map->mapping, NULL, orte_cmd_options.mapping_policy))) {
ORTE_ERROR_LOG(rc);
return rc;
}
} else if (orte_cmd_options.pernode) {
ORTE_SET_MAPPING_POLICY(jdata->map->mapping, ORTE_MAPPING_PPR);
ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_GIVEN);
/* define the ppr */
jdata->map->ppr = strdup("1:node");
} else if (0 < orte_cmd_options.npernode) {
ORTE_SET_MAPPING_POLICY(jdata->map->mapping, ORTE_MAPPING_PPR);
ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_GIVEN);
/* define the ppr */
(void)asprintf(&jdata->map->ppr, "%d:node", orte_cmd_options.npernode);
} else if (0 < orte_cmd_options.npersocket) {
ORTE_SET_MAPPING_POLICY(jdata->map->mapping, ORTE_MAPPING_PPR);
ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_GIVEN);
/* define the ppr */
(void)asprintf(&jdata->map->ppr, "%d:socket", orte_cmd_options.npersocket);
}
/* if the user specified cpus/rank, set it */
if (0 < orte_cmd_options.cpus_per_proc) {
jdata->map->cpus_per_rank = orte_cmd_options.cpus_per_proc;
}
/* if the user specified a ranking policy, then set it */
if (NULL != orte_cmd_options.ranking_policy) {
if (ORTE_SUCCESS != (rc = orte_rmaps_base_set_ranking_policy(&jdata->map->ranking,
jdata->map->mapping,
orte_cmd_options.ranking_policy))) {
ORTE_ERROR_LOG(rc);
return rc;
}
}
/* if the user specified a binding policy, then set it */
if (NULL != orte_cmd_options.binding_policy) {
if (ORTE_SUCCESS != (rc = opal_hwloc_base_set_binding_policy(&jdata->map->binding,
orte_cmd_options.binding_policy))) {
ORTE_ERROR_LOG(rc);
return rc;
}
}
/* if they asked for nolocal, mark it so */
if (orte_cmd_options.nolocal) {
ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_USE_LOCAL);
}
if (orte_cmd_options.no_oversubscribe) {
ORTE_SET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE);
}
if (orte_cmd_options.oversubscribe) {
ORTE_UNSET_MAPPING_DIRECTIVE(jdata->map->mapping, ORTE_MAPPING_NO_OVERSUBSCRIBE);
}
if (orte_cmd_options.report_bindings) {
orte_set_attribute(&jdata->attributes, ORTE_JOB_REPORT_BINDINGS, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
}
if (orte_cmd_options.cpu_list) {
orte_set_attribute(&jdata->attributes, ORTE_JOB_CPU_LIST, ORTE_ATTR_GLOBAL, orte_cmd_options.cpu_list, OPAL_STRING);
}
/* if recovery was enabled on the cmd line, do so */
if (orte_enable_recovery) {
ORTE_FLAG_SET(jdata, ORTE_JOB_FLAG_RECOVERABLE);
if (0 == orte_max_restarts) {
/* mark this job as continuously operating */
orte_set_attribute(&jdata->attributes, ORTE_JOB_CONTINUOUS_OP, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
}
}
/* record the max restarts */
if (0 < orte_max_restarts) {
for (i=0; i < jdata->num_apps; i++) {
if (NULL != (app = (orte_app_context_t*)opal_pointer_array_get_item(jdata->apps, i))) {
orte_set_attribute(&app->attributes, ORTE_APP_MAX_RESTARTS, ORTE_ATTR_GLOBAL, &orte_max_restarts, OPAL_INT32);
}
}
}
/* if continuous operation was specified */
if (orte_cmd_options.continuous) {
/* mark this job as continuously operating */
orte_set_attribute(&jdata->attributes, ORTE_JOB_CONTINUOUS_OP, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
}
/* check for debugger test envars and forward them if necessary */
if (NULL != getenv("ORTE_TEST_DEBUGGER_ATTACH")) {
char *evar;
evar = getenv("ORTE_TEST_DEBUGGER_SLEEP");
for (n=0; n < (int)jdata->num_apps; n++) {
if (NULL != (app = (orte_app_context_t*)opal_pointer_array_get_item(jdata->apps, n))) {
opal_setenv("ORTE_TEST_DEBUGGER_ATTACH", "1", true, &app->env);
if (NULL != evar) {
opal_setenv("ORTE_TEST_DEBUGGER_SLEEP", evar, true, &app->env);
}
}
}
}
/* check for suicide test directives */
if (NULL != getenv("ORTE_TEST_HNP_SUICIDE") ||
NULL != getenv("ORTE_TEST_ORTED_SUICIDE")) {
/* don't forward IO from this process so we can
* see any debug after daemon termination */
ORTE_FLAG_UNSET(jdata, ORTE_JOB_FLAG_FORWARD_OUTPUT);
}
/* check for a job timeout specification, to be provided in seconds
* as that is what MPICH used
*/
param = NULL;
if (0 < orte_cmd_options.timeout ||
NULL != (param = getenv("MPIEXEC_TIMEOUT"))) {
if (NULL != param) {
timeout_seconds = strtol(param, NULL, 10);
/* both cannot be present, or they must agree */
if (0 < orte_cmd_options.timeout && timeout_seconds != orte_cmd_options.timeout) {
orte_show_help("help-orterun.txt", "orterun:timeoutconflict", false,
orte_basename, orte_cmd_options.timeout, param);
exit(1);
}
} else {
timeout_seconds = orte_cmd_options.timeout;
}
if (NULL == (orte_mpiexec_timeout = OBJ_NEW(orte_timer_t))) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
ORTE_UPDATE_EXIT_STATUS(ORTE_ERR_OUT_OF_RESOURCE);
//goto DONE;
}
orte_mpiexec_timeout->tv.tv_sec = timeout_seconds;
orte_mpiexec_timeout->tv.tv_usec = 0;
opal_event_evtimer_set(orte_event_base, orte_mpiexec_timeout->ev,
orte_timeout_wakeup, jdata);
opal_event_set_priority(orte_mpiexec_timeout->ev, ORTE_ERROR_PRI);
opal_event_evtimer_add(orte_mpiexec_timeout->ev, &orte_mpiexec_timeout->tv);
}
/* check for diagnostic memory profile */
if (NULL != (param = getenv("OMPI_MEMPROFILE"))) {
timeout_seconds = strtol(param, NULL, 10);
if (NULL == (orte_memprofile_timeout = OBJ_NEW(orte_timer_t))) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
ORTE_UPDATE_EXIT_STATUS(ORTE_ERR_OUT_OF_RESOURCE);
//goto DONE;
}
orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, ORTE_RML_TAG_MEMPROFILE,
ORTE_RML_PERSISTENT, profile_recv, NULL);
orte_memprofile_timeout->tv.tv_sec = timeout_seconds;
orte_memprofile_timeout->tv.tv_usec = 0;
opal_event_evtimer_set(orte_event_base, orte_memprofile_timeout->ev,
orte_profile_wakeup, jdata);
opal_event_set_priority(orte_memprofile_timeout->ev, ORTE_ERROR_PRI);
opal_event_evtimer_add(orte_memprofile_timeout->ev, &orte_memprofile_timeout->tv);
}
if (ORTE_PROC_IS_HNP) {
/* get the daemon job object */
daemons = orte_get_job_data_object(ORTE_PROC_MY_NAME->jobid);
/* check for request to report uri */
if (NULL != orte_cmd_options.report_uri) {