[mpich2-commits] r4072 - in mpich2/trunk/src/pm/hydra: include launcher/mpiexec launcher/utils pm/central utils/args utils/launch
balaji at mcs.anl.gov
balaji at mcs.anl.gov
Sat Mar 14 18:24:19 CDT 2009
Author: balaji
Date: 2009-03-14 18:24:19 -0500 (Sat, 14 Mar 2009)
New Revision: 4072
Modified:
mpich2/trunk/src/pm/hydra/include/hydra_utils.h
mpich2/trunk/src/pm/hydra/launcher/mpiexec/mpiexec.c
mpich2/trunk/src/pm/hydra/launcher/mpiexec/utils.c
mpich2/trunk/src/pm/hydra/launcher/utils/lchu.c
mpich2/trunk/src/pm/hydra/launcher/utils/lchu.h
mpich2/trunk/src/pm/hydra/pm/central/central_launch.c
mpich2/trunk/src/pm/hydra/utils/args/args.c
mpich2/trunk/src/pm/hydra/utils/launch/allocate.c
Log:
Allocate/free resources in a more organized manner, so we don't leak
memory. With this commit, there should not be any memory leaks at least
for simple programs.
Modified: mpich2/trunk/src/pm/hydra/include/hydra_utils.h
===================================================================
--- mpich2/trunk/src/pm/hydra/include/hydra_utils.h 2009-03-14 22:26:02 UTC (rev 4071)
+++ mpich2/trunk/src/pm/hydra/include/hydra_utils.h 2009-03-14 23:24:19 UTC (rev 4072)
@@ -59,12 +59,15 @@
struct HYD_Partition_list *next;
};
+HYD_Status HYDU_Allocate_Partition(struct HYD_Partition_list **partition);
+void HYDU_Free_partition_list(struct HYD_Partition_list *partition);
+
HYD_Status HYDU_Append_env(HYD_Env_t * env_list, char **client_arg);
HYD_Status HYDU_Append_exec(char **exec, char **client_arg);
HYD_Status HYDU_Append_wdir(char **client_arg, char *wdir);
-HYD_Status HYDU_Allocate_Partition(struct HYD_Partition_list **partition);
+HYD_Status HYDU_Dump_args(char **args);
+void HYDU_Free_args(char **args);
HYD_Status HYDU_Create_process(char **client_arg, int *in, int *out, int *err, int *pid);
-HYD_Status HYDU_Dump_args(char **args);
HYD_Status HYDU_Get_base_path(char *execname, char **path);
HYD_Status HYDU_Chdir(const char *dir);
Modified: mpich2/trunk/src/pm/hydra/launcher/mpiexec/mpiexec.c
===================================================================
--- mpich2/trunk/src/pm/hydra/launcher/mpiexec/mpiexec.c 2009-03-14 22:26:02 UTC (rev 4071)
+++ mpich2/trunk/src/pm/hydra/launcher/mpiexec/mpiexec.c 2009-03-14 23:24:19 UTC (rev 4072)
@@ -126,11 +126,7 @@
}
/* Free the mpiexec params */
- HYDU_FREE(handle.wdir);
- HYD_LCHU_Free_env_list();
- HYD_LCHU_Free_exec();
- HYD_LCHU_Free_host_list();
- HYD_LCHU_Free_proc_params();
+ HYD_LCHU_Free_params();
fn_exit:
HYDU_FUNC_EXIT();
Modified: mpich2/trunk/src/pm/hydra/launcher/mpiexec/utils.c
===================================================================
--- mpich2/trunk/src/pm/hydra/launcher/mpiexec/utils.c 2009-03-14 22:26:02 UTC (rev 4071)
+++ mpich2/trunk/src/pm/hydra/launcher/mpiexec/utils.c 2009-03-14 23:24:19 UTC (rev 4072)
@@ -103,11 +103,7 @@
HYDU_FUNC_ENTER();
- handle.debug = -1;
- handle.enablex = -1;
- handle.wdir = NULL;
- handle.host_file = NULL;
- handle.proxy_port = -1;
+ HYD_LCHU_Init_params();
status = HYDU_Get_base_path(argv[0], &handle.base_path);
if (status != HYD_SUCCESS) {
@@ -120,13 +116,7 @@
HYDU_Error_printf("unable to get the global env list\n");
goto fn_fail;
}
- handle.system_env = NULL;
- handle.user_env = NULL;
- handle.prop = HYD_ENV_PROP_UNSET;
- handle.prop_env = NULL;
- handle.proc_params = NULL;
-
local_params_started = 0;
while (--argc && ++argv) {
Modified: mpich2/trunk/src/pm/hydra/launcher/utils/lchu.c
===================================================================
--- mpich2/trunk/src/pm/hydra/launcher/utils/lchu.c 2009-03-14 22:26:02 UTC (rev 4071)
+++ mpich2/trunk/src/pm/hydra/launcher/utils/lchu.c 2009-03-14 23:24:19 UTC (rev 4072)
@@ -10,6 +10,108 @@
HYD_Handle handle;
+void HYD_LCHU_Init_params()
+{
+ handle.base_path = NULL;
+ handle.proxy_port = -1;
+ handle.bootstrap = NULL;
+
+ handle.debug = -1;
+ handle.enablex = -1;
+ handle.wdir = NULL;
+ handle.host_file = NULL;
+
+ handle.global_env = NULL;
+ handle.system_env = NULL;
+ handle.user_env = NULL;
+ handle.prop = HYD_ENV_PROP_UNSET;
+ handle.prop_env = NULL;
+
+ handle.in = -1;
+ handle.stdin_cb = NULL;
+
+ /* FIXME: Should the timers be initialized? */
+
+ handle.proc_params = NULL;
+ handle.func_depth = 0;
+ handle.stdin_buf_offset = 0;
+ handle.stdin_buf_count = 0;
+}
+
+
+void HYD_LCHU_Free_params()
+{
+ if (handle.base_path) {
+ HYDU_FREE(handle.base_path);
+ handle.base_path = NULL;
+ }
+ if (handle.bootstrap) {
+ HYDU_FREE(handle.bootstrap);
+ handle.bootstrap = NULL;
+ }
+
+ if (handle.wdir) {
+ HYDU_FREE(handle.wdir);
+ handle.wdir = NULL;
+ }
+ if (handle.host_file) {
+ HYDU_FREE(handle.host_file);
+ handle.host_file = NULL;
+ }
+
+ if (handle.global_env) {
+ HYDU_Env_free_list(handle.global_env);
+ handle.global_env = NULL;
+ }
+
+ if (handle.system_env) {
+ HYDU_Env_free_list(handle.system_env);
+ handle.system_env = NULL;
+ }
+
+ if (handle.user_env) {
+ HYDU_Env_free_list(handle.user_env);
+ handle.user_env = NULL;
+ }
+
+ if (handle.prop_env) {
+ HYDU_Env_free_list(handle.prop_env);
+ handle.prop_env = NULL;
+ }
+
+ if (handle.proc_params) {
+ HYD_LCHU_Free_proc_params();
+ handle.proc_params = NULL;
+ }
+}
+
+
+void HYD_LCHU_Free_proc_params()
+{
+ struct HYD_Proc_params *proc_params, *run;
+
+ HYDU_FUNC_ENTER();
+
+ proc_params = handle.proc_params;
+ while (proc_params) {
+ run = proc_params->next;
+ HYDU_Free_args(proc_params->exec);
+ HYDU_Free_partition_list(proc_params->partition);
+ proc_params->partition = NULL;
+
+ HYDU_Env_free_list(proc_params->user_env);
+ proc_params->user_env = NULL;
+ HYDU_Env_free_list(proc_params->prop_env);
+ proc_params->prop_env = NULL;
+
+ HYDU_FREE(proc_params);
+ proc_params = run;
+ }
+
+ HYDU_FUNC_EXIT();
+}
+
+
HYD_Status HYD_LCHU_Create_host_list(void)
{
FILE *fp = NULL;
@@ -218,66 +320,3 @@
fn_fail:
goto fn_exit;
}
-
-
-HYD_Status HYD_LCHU_Free_env_list(void)
-{
- struct HYD_Proc_params *proc_params;
- HYD_Status status = HYD_SUCCESS;
-
- HYDU_FUNC_ENTER();
-
- HYDU_Env_free_list(handle.global_env);
- HYDU_Env_free_list(handle.system_env);
- HYDU_Env_free_list(handle.user_env);
- HYDU_Env_free_list(handle.prop_env);
-
- proc_params = handle.proc_params;
- while (proc_params) {
- HYDU_Env_free_list(proc_params->user_env);
- HYDU_Env_free_list(proc_params->prop_env);
- proc_params = proc_params->next;
- }
-
- HYDU_FUNC_EXIT();
- return status;
-}
-
-
-HYD_Status HYD_LCHU_Free_exec(void)
-{
- struct HYD_Proc_params *proc_params;
- int i;
- HYD_Status status = HYD_SUCCESS;
-
- HYDU_FUNC_ENTER();
-
- proc_params = handle.proc_params;
- while (proc_params) {
- for (i = 0; proc_params->exec[i]; i++)
- HYDU_FREE(proc_params->exec[i]);
- proc_params = proc_params->next;
- }
-
- HYDU_FUNC_EXIT();
- return status;
-}
-
-
-HYD_Status HYD_LCHU_Free_proc_params(void)
-{
- struct HYD_Proc_params *proc_params, *run;
- HYD_Status status = HYD_SUCCESS;
-
- HYDU_FUNC_ENTER();
-
- proc_params = handle.proc_params;
- while (proc_params) {
- run = proc_params->next;
- HYDU_FREE(proc_params);
- proc_params = run;
- }
-
- HYDU_FUNC_EXIT();
- return status;
-}
Modified: mpich2/trunk/src/pm/hydra/launcher/utils/lchu.h
===================================================================
--- mpich2/trunk/src/pm/hydra/launcher/utils/lchu.h 2009-03-14 22:26:02 UTC (rev 4071)
+++ mpich2/trunk/src/pm/hydra/launcher/utils/lchu.h 2009-03-14 23:24:19 UTC (rev 4072)
@@ -9,11 +9,10 @@
#include "hydra.h"
+void HYD_LCHU_Init_params(void);
+void HYD_LCHU_Free_params(void);
+void HYD_LCHU_Free_proc_params(void);
HYD_Status HYD_LCHU_Create_host_list(void);
-HYD_Status HYD_LCHU_Free_host_list(void);
HYD_Status HYD_LCHU_Create_env_list(void);
-HYD_Status HYD_LCHU_Free_env_list(void);
-HYD_Status HYD_LCHU_Free_exec(void);
-HYD_Status HYD_LCHU_Free_proc_params(void);
#endif /* LCHU_H_INCLUDED */
Modified: mpich2/trunk/src/pm/hydra/pm/central/central_launch.c
===================================================================
--- mpich2/trunk/src/pm/hydra/pm/central/central_launch.c 2009-03-14 22:26:02 UTC (rev 4071)
+++ mpich2/trunk/src/pm/hydra/pm/central/central_launch.c 2009-03-14 23:24:19 UTC (rev 4072)
@@ -144,6 +144,8 @@
}
arg++;
+ HYDU_Free_args(path_str);
+
status = HYDU_String_int_to_str(partition->proc_count, &str);
if (status != HYD_SUCCESS) {
HYDU_Error_printf
Modified: mpich2/trunk/src/pm/hydra/utils/args/args.c
===================================================================
--- mpich2/trunk/src/pm/hydra/utils/args/args.c 2009-03-14 22:26:02 UTC (rev 4071)
+++ mpich2/trunk/src/pm/hydra/utils/args/args.c 2009-03-14 23:24:19 UTC (rev 4072)
@@ -102,6 +102,19 @@
}
+void HYDU_Free_args(char **args)
+{
+ int arg;
+
+ HYDU_FUNC_ENTER();
+
+ for (arg = 0; args[arg]; arg++)
+ HYDU_FREE(args[arg]);
+
+ HYDU_FUNC_EXIT();
+}
+
+
HYD_Status HYDU_Get_base_path(char *execname, char **path)
{
char *loc;
Modified: mpich2/trunk/src/pm/hydra/utils/launch/allocate.c
===================================================================
--- mpich2/trunk/src/pm/hydra/utils/launch/allocate.c 2009-03-14 22:26:02 UTC (rev 4071)
+++ mpich2/trunk/src/pm/hydra/utils/launch/allocate.c 2009-03-14 23:24:19 UTC (rev 4072)
@@ -34,3 +34,39 @@
fn_fail:
goto fn_exit;
}
+
+
+void HYDU_Free_partition_list(struct HYD_Partition_list *partition)
+{
+ struct HYD_Partition_list *run, *p;
+ int arg;
+
+ HYDU_FUNC_ENTER();
+
+ p = partition;
+ run = p;
+ while (run) {
+ run = p->next;
+
+ if (p->name) {
+ HYDU_FREE(p->name);
+ p->name = NULL;
+ }
+
+ if (p->mapping) {
+ for (arg = 0; p->mapping[arg]; arg++) {
+ HYDU_FREE(p->mapping[arg]);
+ p->mapping[arg] = NULL;
+ }
+ HYDU_FREE(p->mapping);
+ p->mapping = NULL;
+ }
+
+ HYDU_Free_args(p->args);
+ HYDU_FREE(p);
+
+ p = run;
+ }
+
+ HYDU_FUNC_EXIT();
+}
More information about the mpich2-commits
mailing list