[mpich2-commits] r5629 - mpich2/trunk/src/pm/hydra/tools/bind

balaji at mcs.anl.gov balaji at mcs.anl.gov
Thu Oct 29 23:03:36 CDT 2009


Author: balaji
Date: 2009-10-29 23:03:36 -0500 (Thu, 29 Oct 2009)
New Revision: 5629

Modified:
   mpich2/trunk/src/pm/hydra/tools/bind/bind.c
Log:
Bug fix for the user-specified bindings code. Thanks to Guillaume to
pointing out this error.

Modified: mpich2/trunk/src/pm/hydra/tools/bind/bind.c
===================================================================
--- mpich2/trunk/src/pm/hydra/tools/bind/bind.c	2009-10-30 01:55:34 UTC (rev 5628)
+++ mpich2/trunk/src/pm/hydra/tools/bind/bind.c	2009-10-30 04:03:36 UTC (rev 5629)
@@ -39,12 +39,37 @@
         goto fn_exit;
     }
 
+    /* Initialize the binding library requested by the user */
+#if defined HAVE_PLPA
+    if (!strcmp(HYDT_bind_info.bindlib, "plpa")) {
+        status = HYDT_bind_plpa_init(&HYDT_bind_info.support_level);
+        HYDU_ERR_POP(status, "unable to initialize plpa\n");
+    }
+#endif /* HAVE_PLPA */
+
+#if defined HAVE_HWLOC
+    if (!strcmp(HYDT_bind_info.bindlib, "hwloc")) {
+        status = HYDT_bind_hwloc_init(&HYDT_bind_info.support_level);
+        HYDU_ERR_POP(status, "unable to initialize hwloc\n");
+    }
+#endif /* HAVE_HWLOC */
+
+    /* If we are not able to initialize the binding library, we set
+     * all mappings to -1 */
+    if (HYDT_bind_info.support_level == HYDT_BIND_NONE) {
+        HYDU_MALLOC(HYDT_bind_info.bindmap, int *, sizeof(int), status);
+        HYDT_bind_info.num_procs = 1;
+        HYDT_bind_info.bindmap[0] = -1;
+
+        goto fn_exit;
+    }
+
     if (!strncmp(binding, "user:", strlen("user:"))) {
         /* If the user specified the binding, we don't need to
          * initialize anything */
-        bindstr = HYDU_strdup(binding + strlen("user:"));
 
         /* Find the number of processing elements */
+        bindstr = HYDU_strdup(binding + strlen("user:"));
         HYDT_bind_info.num_procs = 0;
         bindentry = strtok(bindstr, ",");
         while (bindentry) {
@@ -56,6 +81,7 @@
         HYDU_MALLOC(HYDT_bind_info.bindmap, int *, HYDT_bind_info.num_procs * sizeof(int),
                     status);
         i = 0;
+        bindstr = HYDU_strdup(binding + strlen("user:"));
         bindentry = strtok(bindstr, ",");
         while (bindentry) {
             HYDT_bind_info.bindmap[i++] = atoi(bindentry);
@@ -65,76 +91,52 @@
         goto fn_exit;
     }
 
-    /* If a real binding is required, we initialize the binding
-     * library requested by the user */
-#if defined HAVE_PLPA
-    if (!strcmp(HYDT_bind_info.bindlib, "plpa")) {
-        status = HYDT_bind_plpa_init(&HYDT_bind_info.support_level);
-        HYDU_ERR_POP(status, "unable to initialize plpa\n");
-    }
-#endif /* HAVE_PLPA */
+    HYDU_MALLOC(HYDT_bind_info.bindmap, int *, HYDT_bind_info.num_procs * sizeof(int),
+                status);
 
-#if defined HAVE_HWLOC
-    if (!strcmp(HYDT_bind_info.bindlib, "hwloc")) {
-        status = HYDT_bind_hwloc_init(&HYDT_bind_info.support_level);
-        HYDU_ERR_POP(status, "unable to initialize hwloc\n");
-    }
-#endif /* HAVE_HWLOC */
+    for (i = 0; i < HYDT_bind_info.num_procs; i++) {
 
-    if (HYDT_bind_info.support_level != HYDT_BIND_NONE) {
-        HYDU_MALLOC(HYDT_bind_info.bindmap, int *, HYDT_bind_info.num_procs * sizeof(int),
-                    status);
+        /* RR is supported at the basic binding level */
+        if (!strcmp(binding, "rr")) {
+            HYDT_bind_info.bindmap[i] = i;
+            continue;
+        }
 
-        for (i = 0; i < HYDT_bind_info.num_procs; i++) {
+        /* If we reached here, the user requested for topology aware
+         * binding. */
+        if (HYDT_bind_info.support_level != HYDT_BIND_TOPO)
+            HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR,
+                                "topology binding not supported on this platform\n");
 
-            /* RR is supported at the basic binding level */
-            if (!strcmp(binding, "rr")) {
-                HYDT_bind_info.bindmap[i] = i;
-                continue;
-            }
+        if (!strcmp(binding, "buddy")) {
+            thread = i / (HYDT_bind_info.num_sockets * HYDT_bind_info.num_cores);
 
-            /* If we reached here, the user requested for topology
-             * aware binding. */
-            if (HYDT_bind_info.support_level != HYDT_BIND_TOPO)
-                HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR,
-                                    "topology binding not supported on this platform\n");
+            core = i % (HYDT_bind_info.num_sockets * HYDT_bind_info.num_cores);
+            core /= HYDT_bind_info.num_sockets;
 
-            if (!strcmp(binding, "buddy")) {
-                thread = i / (HYDT_bind_info.num_sockets * HYDT_bind_info.num_cores);
+            sock = i % HYDT_bind_info.num_sockets;
+        }
+        else if (!strcmp(binding, "pack")) {
+            sock = i / (HYDT_bind_info.num_cores * HYDT_bind_info.num_threads);
 
-                core = i % (HYDT_bind_info.num_sockets * HYDT_bind_info.num_cores);
-                core /= HYDT_bind_info.num_sockets;
+            core = i % (HYDT_bind_info.num_cores * HYDT_bind_info.num_threads);
+            core /= HYDT_bind_info.num_threads;
 
-                sock = i % HYDT_bind_info.num_sockets;
-            }
-            else if (!strcmp(binding, "pack")) {
-                sock = i / (HYDT_bind_info.num_cores * HYDT_bind_info.num_threads);
+            thread = i % HYDT_bind_info.num_threads;
+        }
+        else {
+            HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "unknown binding option\n");
+        }
 
-                core = i % (HYDT_bind_info.num_cores * HYDT_bind_info.num_threads);
-                core /= HYDT_bind_info.num_threads;
-
-                thread = i % HYDT_bind_info.num_threads;
+        for (j = 0; j < HYDT_bind_info.num_procs; j++) {
+            if (HYDT_bind_info.topology[j].socket_rank == sock &&
+                HYDT_bind_info.topology[j].core_rank == core &&
+                HYDT_bind_info.topology[j].thread_rank == thread) {
+                HYDT_bind_info.bindmap[i] = HYDT_bind_info.topology[j].processor_id;
+                break;
             }
-            else {
-                HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "unknown binding option\n");
-            }
-
-            for (j = 0; j < HYDT_bind_info.num_procs; j++) {
-                if (HYDT_bind_info.topology[j].socket_rank == sock &&
-                    HYDT_bind_info.topology[j].core_rank == core &&
-                    HYDT_bind_info.topology[j].thread_rank == thread) {
-                    HYDT_bind_info.bindmap[i] = HYDT_bind_info.topology[j].processor_id;
-                    break;
-                }
-            }
         }
     }
-    else {
-        /* If no binding is supported, we just set all mappings to -1 */
-        HYDU_MALLOC(HYDT_bind_info.bindmap, int *, sizeof(int), status);
-        HYDT_bind_info.num_procs = 1;
-        HYDT_bind_info.bindmap[0] = -1;
-    }
 
   fn_exit:
     HYDU_FUNC_EXIT();



More information about the mpich2-commits mailing list