[mpich2-commits] r7653 - in mpich2/trunk/src/pm/hydra/ui: include mpich utils

balaji at mcs.anl.gov balaji at mcs.anl.gov
Mon Jan 3 07:04:35 CST 2011


Author: balaji
Date: 2011-01-03 07:04:35 -0600 (Mon, 03 Jan 2011)
New Revision: 7653

Modified:
   mpich2/trunk/src/pm/hydra/ui/include/ui.h
   mpich2/trunk/src/pm/hydra/ui/mpich/mpiexec.c
   mpich2/trunk/src/pm/hydra/ui/mpich/utils.c
   mpich2/trunk/src/pm/hydra/ui/utils/uiu.c
Log:
Generalize the management of 'prepend regex'. Allow a regular
expression to be prepended to the output. -prepend-rank is a subset of
this generalized capability.

Modified: mpich2/trunk/src/pm/hydra/ui/include/ui.h
===================================================================
--- mpich2/trunk/src/pm/hydra/ui/include/ui.h	2011-01-03 13:03:34 UTC (rev 7652)
+++ mpich2/trunk/src/pm/hydra/ui/include/ui.h	2011-01-03 13:04:35 UTC (rev 7653)
@@ -8,7 +8,7 @@
 #define UI_H_INCLUDED
 
 struct HYD_ui_info {
-    int prepend_rank;
+    char *prepend_regex;
 };
 
 extern struct HYD_ui_info HYD_ui_info;

Modified: mpich2/trunk/src/pm/hydra/ui/mpich/mpiexec.c
===================================================================
--- mpich2/trunk/src/pm/hydra/ui/mpich/mpiexec.c	2011-01-03 13:03:34 UTC (rev 7652)
+++ mpich2/trunk/src/pm/hydra/ui/mpich/mpiexec.c	2011-01-03 13:04:35 UTC (rev 7653)
@@ -109,6 +109,7 @@
     printf("    -ppn                             processes per node\n");
     printf("    -profile                         turn on internal profiling\n");
     printf("    -prepend-rank                    prepend rank to output\n");
+    printf("    -prepend-regex                  prepend regex to output\n");
     printf
         ("    -nameserver                      name server information (host:port format)\n");
     printf("    -disable-auto-cleanup            don't cleanup processes on error\n");

Modified: mpich2/trunk/src/pm/hydra/ui/mpich/utils.c
===================================================================
--- mpich2/trunk/src/pm/hydra/ui/mpich/utils.c	2011-01-03 13:03:34 UTC (rev 7652)
+++ mpich2/trunk/src/pm/hydra/ui/mpich/utils.c	2011-01-03 13:04:35 UTC (rev 7653)
@@ -280,9 +280,26 @@
 
 static HYD_status prepend_rank_fn(char *arg, char ***argv)
 {
-    return HYDU_set_int(arg, argv, &HYD_ui_info.prepend_rank, 1);
+    return HYDU_set_str(arg, argv, &HYD_ui_info.prepend_regex, "[%r]");
 }
 
+static void prepend_regex_help_fn(void)
+{
+    printf("\n");
+    printf("-prepend-regex: Prepend this regular expression to stdout and stderr\n");
+    printf("   Regular expressions can include:\n");
+    printf("       %%r: Process rank\n");
+    printf("       %%g: Process group ID\n");
+    printf("       %%p: Proxy ID\n");
+    printf("       %%h: Hostname\n");
+    printf("\n");
+}
+
+static HYD_status prepend_regex_fn(char *arg, char ***argv)
+{
+    return HYDU_set_str_and_incr(arg, argv, &HYD_ui_info.prepend_regex);
+}
+
 static void wdir_help_fn(void)
 {
     printf("\n");
@@ -915,6 +932,7 @@
     {"profile", profile_fn, profile_help_fn},
     {"prepend-rank", prepend_rank_fn, prepend_rank_help_fn},
     {"l", prepend_rank_fn, prepend_rank_help_fn},
+    {"prepend-regex", prepend_regex_fn, prepend_regex_help_fn},
     {"wdir", wdir_fn, wdir_help_fn},
     {"configfile", config_fn, config_help_fn},
 
@@ -1000,9 +1018,6 @@
     if (HYD_ui_mpich_info.ranks_per_proc == -1)
         HYD_ui_mpich_info.ranks_per_proc = 1;
 
-    if (HYD_ui_info.prepend_rank == -1)
-        HYD_ui_info.prepend_rank = 0;
-
     if (HYD_server_info.enable_profiling == -1)
         HYD_server_info.enable_profiling = 0;
 

Modified: mpich2/trunk/src/pm/hydra/ui/utils/uiu.c
===================================================================
--- mpich2/trunk/src/pm/hydra/ui/utils/uiu.c	2011-01-03 13:03:34 UTC (rev 7652)
+++ mpich2/trunk/src/pm/hydra/ui/utils/uiu.c	2011-01-03 13:04:35 UTC (rev 7653)
@@ -37,7 +37,7 @@
     HYD_server_info.num_pmi_calls = 0;
 #endif /* ENABLE_PROFILING */
 
-    HYD_ui_info.prepend_rank = -1;
+    HYD_ui_info.prepend_regex = NULL;
 }
 
 void HYD_uiu_free_params(void)
@@ -68,6 +68,9 @@
     if (HYD_server_info.pg_list.next)
         HYDU_free_pg_list(HYD_server_info.pg_list.next);
 
+    if (HYD_ui_info.prepend_regex)
+        HYDU_FREE(HYD_ui_info.prepend_regex);
+
     /* Re-initialize everything to default values */
     HYD_uiu_init_params();
 }
@@ -143,66 +146,110 @@
     return;
 }
 
-HYD_status HYD_uiu_stdout_cb(int pgid, int proxy_id, int rank, void *_buf, int buflen)
+static HYD_status stdoe_cb(int fd, int pgid, int proxy_id, int rank, void *_buf, int buflen)
 {
-    int sent, closed, mark, i;
+    int sent, closed, mark, i, offset;
     char *buf = (char *) _buf;
+    char *prepend, *tprepend;
+    char *s_rank, *s_pgid, *s_proxy_id, *s_host, *s;
+    struct HYD_pg *pg;
+    struct HYD_proxy *proxy;
+    char *tmp[HYD_NUM_TMP_STRINGS];
     HYD_status status = HYD_SUCCESS;
 
     HYDU_FUNC_ENTER();
 
-    if (HYD_ui_info.prepend_rank == 0) {
-        status = HYDU_sock_write(STDOUT_FILENO, buf, buflen, &sent, &closed);
-        HYDU_ERR_POP(status, "unable to write data to stdout\n");
+    if (HYD_ui_info.prepend_regex == NULL) {
+        status = HYDU_sock_write(fd, buf, buflen, &sent, &closed);
+        HYDU_ERR_POP(status, "unable to write data to stdout/stderr\n");
         HYDU_ASSERT(!closed, status);
     }
     else {
-        mark = 0;
-        for (i = 0; i < buflen; i++) {
-            if (buf[i] == '\n' || i == buflen - 1) {
-                HYDU_dump_noprefix(stdout, "[%d] ", rank);
-                status = HYDU_sock_write(STDOUT_FILENO, (const void *) &buf[mark],
-                                         i - mark + 1, &sent, &closed);
-                HYDU_ERR_POP(status, "unable to write data to stdout\n");
-                HYDU_ASSERT(!closed, status);
-                mark = i + 1;
-            }
-        }
-    }
+        tprepend = prepend = HYDU_strdup(HYD_ui_info.prepend_regex);
 
-  fn_exit:
-    HYDU_FUNC_EXIT();
-    return status;
+        offset = 0;
+        i = 0;
+        do {
+            s_rank = strstr(prepend, "%r");
+            s_pgid = strstr(prepend, "%g");
+            s_proxy_id = strstr(prepend, "%p");
+            s_host = strstr(prepend, "%h");
 
-  fn_fail:
-    goto fn_exit;
-}
+            s = s_rank;
+            if (s == NULL || (s_pgid && s_pgid < s))
+                s = s_pgid;
+            if (s == NULL || (s_proxy_id && s_proxy_id < s))
+                s = s_proxy_id;
+            if (s == NULL || (s_host && s_host < s))
+                s = s_host;
 
-HYD_status HYD_uiu_stderr_cb(int pgid, int proxy_id, int rank, void *_buf, int buflen)
-{
-    int sent, closed, mark, i;
-    char *buf = (char *) _buf;
-    HYD_status status = HYD_SUCCESS;
+            if (s)
+                *s = 0;
 
-    HYDU_FUNC_ENTER();
+            tmp[i++] = HYDU_strdup(prepend);
 
-    if (HYD_ui_info.prepend_rank == 0) {
-        status = HYDU_sock_write(STDERR_FILENO, buf, buflen, &sent, &closed);
-        HYDU_ERR_POP(status, "unable to write data to stderr\n");
-        HYDU_ASSERT(!closed, status);
-    }
-    else {
+            if (s) {
+                if (s[1] == 'r') {
+                    HYDU_MALLOC(tmp[i], char *, HYD_TMP_STRLEN, status);
+                    MPL_snprintf(tmp[i], HYD_TMP_STRLEN, "%d", rank);
+                }
+                else if (s[1] == 'g') {
+                    HYDU_MALLOC(tmp[i], char *, HYD_TMP_STRLEN, status);
+                    MPL_snprintf(tmp[i], HYD_TMP_STRLEN, "%d", pgid);
+                }
+                else if (s[1] == 'p') {
+                    HYDU_MALLOC(tmp[i], char *, HYD_TMP_STRLEN, status);
+                    MPL_snprintf(tmp[i], HYD_TMP_STRLEN, "%d", proxy_id);
+                }
+                else if (s[1] == 'h') {
+                    for (pg = &HYD_server_info.pg_list; pg; pg = pg->next)
+                        if (pg->pgid == pgid)
+                            break;
+                    HYDU_ASSERT(pg, status);
+
+                    for (proxy = pg->proxy_list; proxy; proxy = proxy->next)
+                        if (proxy->proxy_id == proxy_id)
+                            break;
+                    HYDU_ASSERT(proxy, status);
+
+                    HYDU_MALLOC(tmp[i], char *, HYD_TMP_STRLEN, status);
+                    MPL_snprintf(tmp[i], HYD_TMP_STRLEN, "%s", proxy->node.hostname);
+                }
+                else {
+                    HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR,
+                                        "unrecognized prepend regex\n");
+                }
+                i++;
+
+                prepend = s + 2;
+            }
+            else
+                prepend = NULL;
+        } while (prepend);
+
+        tmp[i++] = NULL;
+        status = HYDU_str_alloc_and_join(tmp, &prepend);
+        HYDU_ERR_POP(status, "unable to join strings\n");
+        HYDU_free_strlist(tmp);
+
         mark = 0;
         for (i = 0; i < buflen; i++) {
             if (buf[i] == '\n' || i == buflen - 1) {
-                HYDU_dump_noprefix(stderr, "[%d] ", rank);
-                status = HYDU_sock_write(STDERR_FILENO, (const void *) &buf[mark],
-                                         i - mark + 1, &sent, &closed);
-                HYDU_ERR_POP(status, "unable to write data to stderr\n");
+                if (fd == STDOUT_FILENO) {
+                    HYDU_dump_noprefix(stdout, "%s ", prepend);
+                }
+                else if (fd == STDERR_FILENO) {
+                    HYDU_dump_noprefix(stderr, "%s ", prepend);
+                }
+                status = HYDU_sock_write(fd, (const void *) &buf[mark], i - mark + 1,
+                                         &sent, &closed);
+                HYDU_ERR_POP(status, "unable to write data to stdout/stderr\n");
                 HYDU_ASSERT(!closed, status);
                 mark = i + 1;
             }
         }
+
+        HYDU_FREE(tprepend);
     }
 
   fn_exit:
@@ -212,3 +259,13 @@
   fn_fail:
     goto fn_exit;
 }
+
+HYD_status HYD_uiu_stdout_cb(int pgid, int proxy_id, int rank, void *buf, int buflen)
+{
+    return stdoe_cb(STDOUT_FILENO, pgid, proxy_id, rank, buf, buflen);
+}
+
+HYD_status HYD_uiu_stderr_cb(int pgid, int proxy_id, int rank, void *buf, int buflen)
+{
+    return stdoe_cb(STDERR_FILENO, pgid, proxy_id, rank, buf, buflen);
+}



More information about the mpich2-commits mailing list