diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/testbed/gnunet_testbed_mpi_spawn.c | 143 |
1 files changed, 48 insertions, 95 deletions
diff --git a/src/testbed/gnunet_testbed_mpi_spawn.c b/src/testbed/gnunet_testbed_mpi_spawn.c index 2ff1972a6..702ce149d 100644 --- a/src/testbed/gnunet_testbed_mpi_spawn.c +++ b/src/testbed/gnunet_testbed_mpi_spawn.c | |||
@@ -1,14 +1,12 @@ | |||
1 | #include "platform.h" | 1 | #include "platform.h" |
2 | #include "gnunet_util_lib.h" | 2 | #include "gnunet_util_lib.h" |
3 | #include "gnunet_resolver_service.h" | ||
4 | #include "gnunet_testbed_service.h" | ||
5 | #include <mpi.h> | 3 | #include <mpi.h> |
6 | 4 | ||
7 | /** | 5 | /** |
8 | * Generic logging shorthand | 6 | * Generic logging shorthand |
9 | */ | 7 | */ |
10 | #define LOG(kind,...) \ | 8 | #define LOG(kind,...) \ |
11 | GNUNET_log_from (kind, "gnunet-mpi-test", __VA_ARGS__) | 9 | fprintf (stderr, __VA_ARGS__) |
12 | 10 | ||
13 | /** | 11 | /** |
14 | * Debug logging shorthand | 12 | * Debug logging shorthand |
@@ -17,131 +15,86 @@ | |||
17 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 15 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
18 | 16 | ||
19 | /** | 17 | /** |
20 | * Timeout for resolving IPs | ||
21 | */ | ||
22 | #define RESOLVE_TIMEOUT \ | ||
23 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
24 | |||
25 | /** | ||
26 | * Global result | 18 | * Global result |
27 | */ | 19 | */ |
28 | static int ret; | 20 | static int ret; |
29 | 21 | ||
30 | /** | ||
31 | * The host list | ||
32 | */ | ||
33 | static struct GNUNET_TESTBED_Host **hosts; | ||
34 | 22 | ||
35 | /** | 23 | /** |
36 | * Number of hosts in the host list | 24 | * Execution start point |
37 | */ | ||
38 | static unsigned int nhosts; | ||
39 | |||
40 | /** | ||
41 | * Main function that will be run by the scheduler. | ||
42 | * | ||
43 | * @param cls closure | ||
44 | * @param args remaining command-line arguments | ||
45 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
46 | * @param config configuration | ||
47 | */ | 25 | */ |
48 | static void | 26 | int |
49 | run (void *cls, char *const *args, const char *cfgfile, | 27 | main (int argc, char *argv[]) |
50 | const struct GNUNET_CONFIGURATION_Handle *config) | ||
51 | { | 28 | { |
29 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
30 | GNUNET_GETOPT_OPTION_END | ||
31 | }; | ||
52 | struct GNUNET_OS_Process *proc; | 32 | struct GNUNET_OS_Process *proc; |
33 | char **argv2; | ||
53 | unsigned long code; | 34 | unsigned long code; |
54 | enum GNUNET_OS_ProcessStatusType proc_status; | 35 | enum GNUNET_OS_ProcessStatusType proc_status; |
55 | int rank; | 36 | int rank; |
37 | int chstat; | ||
56 | unsigned int host; | 38 | unsigned int host; |
39 | unsigned int cnt; | ||
57 | 40 | ||
41 | ret = -1; | ||
42 | if (argc < 2) | ||
43 | { | ||
44 | printf ("Need arguments: gnunet-testbed-mpi-spawn <cmd> <cmd_args>"); | ||
45 | return 1; | ||
46 | } | ||
47 | if (MPI_SUCCESS != MPI_Init (&argc, &argv)) | ||
48 | { | ||
49 | GNUNET_break (0); | ||
50 | return 2; | ||
51 | } | ||
58 | if (MPI_SUCCESS != MPI_Comm_rank (MPI_COMM_WORLD, &rank)) | 52 | if (MPI_SUCCESS != MPI_Comm_rank (MPI_COMM_WORLD, &rank)) |
59 | { | 53 | { |
60 | GNUNET_break (0); | 54 | GNUNET_break (0); |
61 | return; | 55 | ret = 3; |
56 | goto finalize; | ||
62 | } | 57 | } |
63 | if (0 != rank) | 58 | if (0 != rank) |
64 | { | 59 | { |
65 | ret = GNUNET_OK; | 60 | ret = 0; |
66 | return; | 61 | goto finalize; |
67 | } | 62 | } |
68 | PRINTF ("Spawning process\n"); | 63 | PRINTF ("Spawning process\n"); |
64 | argv2 = GNUNET_malloc (sizeof (char *) * (argc - 1)); | ||
65 | for (cnt = 1; cnt < argc; cnt++) | ||
66 | argv2[cnt - 1] = argv[cnt]; | ||
69 | proc = | 67 | proc = |
70 | GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, | 68 | GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, |
71 | NULL, args[0], args); | 69 | NULL, argv2[0], argv2); |
72 | if (NULL == proc) | 70 | if (NULL == proc) |
73 | { | 71 | { |
74 | printf ("Cannot exec\n"); | 72 | LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot exec\n"); |
75 | return; | 73 | ret = 5; |
74 | goto finalize; | ||
76 | } | 75 | } |
77 | do | 76 | do |
78 | { | 77 | { |
79 | (void) sleep (1); | 78 | (void) sleep (1); |
80 | ret = GNUNET_OS_process_status (proc, &proc_status, &code); | 79 | chstat = GNUNET_OS_process_status (proc, &proc_status, &code); |
81 | } | 80 | } |
82 | while (GNUNET_NO == ret); | 81 | while (GNUNET_NO == chstat); |
83 | GNUNET_assert (GNUNET_NO != ret); | 82 | if (GNUNET_OK != chstat) |
84 | if (GNUNET_OK == ret) | 83 | { |
85 | { | 84 | ret = 6; |
86 | if (0 != code) | 85 | goto finalize; |
87 | { | ||
88 | LOG (GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n"); | ||
89 | ret = GNUNET_SYSERR; | ||
90 | GNUNET_break (0); | ||
91 | return; | ||
92 | } | ||
93 | } | 86 | } |
94 | else | 87 | if (0 != code) |
95 | { | 88 | { |
96 | ret = GNUNET_SYSERR; | 89 | LOG (GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n"); |
97 | GNUNET_break (0); | 90 | ret = 50 + (int) code; |
98 | return; | 91 | goto finalize; |
99 | } | 92 | } |
100 | if (0 == (nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler (config, &hosts))) | 93 | ret = 0; |
101 | { | ||
102 | GNUNET_break (0); | ||
103 | ret = GNUNET_SYSERR; | ||
104 | return; | ||
105 | } | ||
106 | for (host = 0; host < nhosts; host++) | ||
107 | GNUNET_TESTBED_host_destroy (hosts[host]); | ||
108 | GNUNET_free (hosts); | ||
109 | hosts = NULL; | ||
110 | ret = GNUNET_OK; | ||
111 | } | ||
112 | |||
113 | |||
114 | /** | ||
115 | * Execution start point | ||
116 | */ | ||
117 | int | ||
118 | main (int argc, char *argv[]) | ||
119 | { | ||
120 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
121 | GNUNET_GETOPT_OPTION_END | ||
122 | }; | ||
123 | unsigned int host; | ||
124 | int rres; | ||
125 | 94 | ||
126 | ret = GNUNET_SYSERR; | 95 | finalize: |
127 | if (argc < 2) | ||
128 | { | ||
129 | printf ("Need arguments: gnunet-testbed-mpi-spawn <cmd> <cmd_args>"); | ||
130 | return 1; | ||
131 | } | ||
132 | if (MPI_SUCCESS != MPI_Init (&argc, &argv)) | ||
133 | { | ||
134 | GNUNET_break (0); | ||
135 | return 1; | ||
136 | } | ||
137 | rres = | ||
138 | GNUNET_PROGRAM_run (argc, argv, | ||
139 | "gnunet-testbed-mpi-spawn <cmd> <cmd_args>", | ||
140 | _("Spawns cmd after starting my the MPI run-time"), | ||
141 | options, &run, NULL); | ||
142 | (void) MPI_Finalize (); | 96 | (void) MPI_Finalize (); |
143 | if ((GNUNET_OK == rres) && (GNUNET_OK == ret)) | 97 | if (0 != ret) |
144 | return 0; | 98 | LOG (GNUNET_ERROR_TYPE_ERROR, "Something went wrong. Error: %d\n", ret); |
145 | printf ("Something went wrong\n"); | 99 | return ret; |
146 | return 1; | ||
147 | } | 100 | } |