1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #include "hydra.h"
7 #include "debugger.h"
8
9 struct MPIR_PROCDESC *MPIR_proctable = NULL;
10 int MPIR_proctable_size = 0;
11 int MPIR_i_am_starter = 0;
12 int MPIR_partial_attach_ok = 0;
13
14 volatile int MPIR_debug_state = 0;
15 char *MPIR_debug_abort_string = 0;
16
17 volatile int MPIR_being_debugged = 0;
18
19 int (*MPIR_breakpointFn) (void) = MPIR_Breakpoint;
20
MPIR_Breakpoint(void)21 int MPIR_Breakpoint(void)
22 {
23 return 0;
24 }
25
HYDT_dbg_setup_procdesc(struct HYD_pg * pg)26 HYD_status HYDT_dbg_setup_procdesc(struct HYD_pg * pg)
27 {
28 struct HYD_proxy *proxy;
29 struct HYD_exec *exec;
30 int i, j, k, np, round;
31 HYD_status status = HYD_SUCCESS;
32
33 HYDU_FUNC_ENTER();
34
35 HYDU_MALLOC_OR_JUMP(MPIR_proctable, struct MPIR_PROCDESC *,
36 pg->pg_process_count * sizeof(struct MPIR_PROCDESC), status);
37
38 round = 0;
39 /* We need to allocate the MPIR_proctable in COMM_WORLD rank
40 * order. We do this in multiple rounds. In each round, we
41 * allocate the proctable entries for the executables on the proxy
42 * that form a contiguous rank list. Then we move to the next
43 * proxy. When we run out of proxies, we go back to the first
44 * proxy and find the next set of contiguous ranks on that
45 * proxy. */
46 for (proxy = pg->proxy_list, i = 0;; proxy = proxy->next) {
47 j = 0;
48 k = 0;
49 if (!proxy) {
50 proxy = pg->proxy_list;
51 round++;
52 }
53 for (exec = proxy->exec_list; exec; exec = exec->next) {
54 for (np = 0; np < exec->proc_count; np++) {
55 if (k + np >= ((round + 1) * proxy->node->core_count))
56 break;
57 if (k + np < round * proxy->node->core_count)
58 continue;
59 /* avoid storing multiple copies of the host name */
60 if (i > 0 && strcmp(MPIR_proctable[i - 1].host_name, proxy->node->hostname) == 0)
61 MPIR_proctable[i].host_name = MPIR_proctable[i - 1].host_name;
62 else
63 MPIR_proctable[i].host_name = MPL_strdup(proxy->node->hostname);
64 MPIR_proctable[i].pid = proxy->pid[(proxy->node->core_count * round) + j];
65 j++;
66 if (exec->exec[0]) {
67 /* avoid storing multiple copies of the executable name */
68 if (i > 0 && strcmp(exec->exec[0], MPIR_proctable[i - 1].executable_name) == 0)
69 MPIR_proctable[i].executable_name = MPIR_proctable[i - 1].executable_name;
70 else
71 MPIR_proctable[i].executable_name = MPL_strdup(exec->exec[0]);
72 } else {
73 MPIR_proctable[i].executable_name = NULL;
74 }
75 i++;
76 }
77 k += exec->proc_count;
78 }
79
80 if (i >= pg->pg_process_count)
81 break;
82 }
83
84 MPIR_proctable_size = pg->pg_process_count;
85 MPIR_debug_state = MPIR_DEBUG_SPAWNED;
86 (*MPIR_breakpointFn) ();
87
88 fn_exit:
89 HYDU_FUNC_EXIT();
90 return status;
91
92 fn_fail:
93 goto fn_exit;
94 }
95
HYDT_dbg_free_procdesc(void)96 void HYDT_dbg_free_procdesc(void)
97 {
98 int i;
99
100 for (i = 0; i < MPIR_proctable_size; i++) {
101 /* skip over duplicate pointers when freeing */
102 if (MPIR_proctable[i].host_name) {
103 if (i == 0 || MPIR_proctable[i].host_name != MPIR_proctable[i - 1].host_name)
104 MPL_free(MPIR_proctable[i].host_name);
105 }
106 if (MPIR_proctable[i].executable_name) {
107 if (i == 0 ||
108 MPIR_proctable[i].executable_name != MPIR_proctable[i - 1].executable_name)
109 MPL_free(MPIR_proctable[i].executable_name);
110 }
111 }
112 MPL_free(MPIR_proctable);
113 }
114