[mpich2-commits] r7511 - in mpich2/trunk/src/pm/hydra/tools/bind: . hwloc

balaji at mcs.anl.gov balaji at mcs.anl.gov
Fri Nov 26 07:10:36 CST 2010


Author: balaji
Date: 2010-11-26 07:10:36 -0600 (Fri, 26 Nov 2010)
New Revision: 7511

Modified:
   mpich2/trunk/src/pm/hydra/tools/bind/bind.c
   mpich2/trunk/src/pm/hydra/tools/bind/bind.h
   mpich2/trunk/src/pm/hydra/tools/bind/hwloc/bind_hwloc.c
Log:
Several fixes to the process binding code with respect to detection of
cache and CPU topology.


Modified: mpich2/trunk/src/pm/hydra/tools/bind/bind.c
===================================================================
--- mpich2/trunk/src/pm/hydra/tools/bind/bind.c	2010-11-26 08:01:13 UTC (rev 7510)
+++ mpich2/trunk/src/pm/hydra/tools/bind/bind.c	2010-11-26 13:10:36 UTC (rev 7511)
@@ -175,6 +175,10 @@
             if (use_topo_obj[i])
                 use_topo_obj[i - 1] = 1;
         }
+	/* We should have at least one process on the node; otherwise,
+	   the mapping makes no sense */
+	for (i = HYDT_BIND_OBJ_MACHINE; i < HYDT_BIND_OBJ_NODE; i++)
+	    use_topo_obj[i] = 1;
 
         topo_end = HYDT_BIND_OBJ_END;
         for (i = HYDT_BIND_OBJ_MACHINE; i < HYDT_BIND_OBJ_END; i++) {
@@ -198,7 +202,8 @@
         bindentry = strtok(bindstr, ":");
         bindentry = strtok(NULL, ":");
 
-        use_cache_level = 0;
+	/* Don't share any cache to start with */
+        use_cache_level = HYDT_INVALID_CACHE_DEPTH;
         if (bindentry == NULL) {
             /* No extension option specified; use all resources */
             use_cache_level = 1;
@@ -206,20 +211,22 @@
         else {
             elem = strtok(bindentry, ",");
             do {
-                if (!strcmp(elem, "l3") || !strcmp(elem, "l3")) {
-                    if (!use_cache_level || use_cache_level > 3)
+                if (!strcmp(elem, "l3") || !strcmp(elem, "L3")) {
+                    if (use_cache_level > 3)
                         use_cache_level = 3;
                 }
-                else if (!strcmp(elem, "l2") || !strcmp(elem, "l2")) {
-                    if (!use_cache_level || use_cache_level > 2)
+                else if (!strcmp(elem, "l2") || !strcmp(elem, "L2")) {
+                    if (use_cache_level > 2)
                         use_cache_level = 2;
                 }
-                else if (!strcmp(elem, "l1") || !strcmp(elem, "l1")) {
-                    if (!use_cache_level || use_cache_level > 1)
+                else if (!strcmp(elem, "l1") || !strcmp(elem, "L1")) {
+                    if (use_cache_level > 1)
                         use_cache_level = 1;
                 }
-                else
-                    HYDU_ERR_POP(status, "unrecognized binding option\n");
+                else {
+                    HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR,
+                                        "unrecognized binding option\n");
+                }
 
                 elem = strtok(NULL, ",");
             } while (elem);
@@ -230,6 +237,10 @@
         break_out = 0;
         for (i = HYDT_BIND_OBJ_MACHINE; i < HYDT_BIND_OBJ_END; i++) {
             for (j = 0; j < obj->mem.num_caches; j++) {
+		/* If the cache level is lower than what I'm allowed
+		   to share, and there are more than one OS indices
+		   below this level (there is actually sharing) mark
+		   this as the lowest level I can get to */
                 if (obj->mem.cache_depth[j] == use_cache_level) {
                     topo_end = (HYDT_bind_obj_type_t) (i + 1);
                     break_out = 1;
@@ -253,8 +264,8 @@
             for (; j < topo_end - 1; j++)
                 obj = obj->children;
 
-            HYDT_bind_cpuset_dup(obj->cpuset, &HYDT_bind_info.bindmap[i]);
-            i++;
+	    HYDT_bind_cpuset_dup(obj->cpuset, &HYDT_bind_info.bindmap[i]);
+	    i++;
 
             child_id = HYDT_BIND_OBJ_CHILD_ID(obj);
             if (child_id < obj->parent->num_children - 1) {

Modified: mpich2/trunk/src/pm/hydra/tools/bind/bind.h
===================================================================
--- mpich2/trunk/src/pm/hydra/tools/bind/bind.h	2010-11-26 08:01:13 UTC (rev 7510)
+++ mpich2/trunk/src/pm/hydra/tools/bind/bind.h	2010-11-26 13:10:36 UTC (rev 7511)
@@ -16,6 +16,9 @@
 #define HYDT_BIND_OBJ_CHILD_ID(obj) \
     ((((char *) obj) - ((char *) obj->parent->children)) / sizeof(struct HYDT_bind_obj))
 
+/* This should be higher than the number of cache levels we support */
+#define HYDT_INVALID_CACHE_DEPTH (10)
+
 /*! \endcond */
 
 /*! \addtogroup bind Process Binding Interface

Modified: mpich2/trunk/src/pm/hydra/tools/bind/hwloc/bind_hwloc.c
===================================================================
--- mpich2/trunk/src/pm/hydra/tools/bind/hwloc/bind_hwloc.c	2010-11-26 08:01:13 UTC (rev 7510)
+++ mpich2/trunk/src/pm/hydra/tools/bind/hwloc/bind_hwloc.c	2010-11-26 13:10:36 UTC (rev 7511)
@@ -55,10 +55,10 @@
 }
 
 static void gather_attached_caches(struct HYDT_bind_obj *obj, hwloc_obj_t hobj,
-                                   hwloc_cpuset_t cpuset)
+                                   hwloc_cpuset_t cpuset, int cindex)
 {
     int i;
-    static int cidx = 0;
+    int cidx = cindex;
 
     if (hobj->type == HWLOC_OBJ_CACHE && !hwloc_cpuset_compare(hobj->cpuset, cpuset)) {
         obj->mem.cache_size[cidx] = hobj->attr->cache.size;
@@ -67,7 +67,7 @@
     }
 
     for (i = 0; i < hobj->arity; i++)
-        gather_attached_caches(obj, hobj->children[i], cpuset);
+        gather_attached_caches(obj, hobj->children[i], cpuset, cidx);
 }
 
 static HYD_status load_mem_cache_info(struct HYDT_bind_obj *obj, hwloc_obj_t hobj)
@@ -82,12 +82,15 @@
     /* Check how many cache objects match out cpuset */
     obj->mem.num_caches = count_attached_caches(hobj, hobj->cpuset);
 
-    HYDU_MALLOC(obj->mem.cache_size, size_t *, obj->mem.num_caches * sizeof(size_t), status);
-    memset(obj->mem.cache_size, 0, obj->mem.num_caches * sizeof(size_t));
-    HYDU_MALLOC(obj->mem.cache_depth, int *, obj->mem.num_caches * sizeof(int), status);
-    memset(obj->mem.cache_depth, 0, obj->mem.num_caches * sizeof(int));
+    if (obj->mem.num_caches) {
+	HYDU_MALLOC(obj->mem.cache_size, size_t *, obj->mem.num_caches * sizeof(size_t),
+		    status);
+	memset(obj->mem.cache_size, 0, obj->mem.num_caches * sizeof(size_t));
+	HYDU_MALLOC(obj->mem.cache_depth, int *, obj->mem.num_caches * sizeof(int), status);
+	memset(obj->mem.cache_depth, 0, obj->mem.num_caches * sizeof(int));
 
-    gather_attached_caches(obj, hobj, hobj->cpuset);
+	gather_attached_caches(obj, hobj, hobj->cpuset, 0);
+    }
 
   fn_exit:
     return status;



More information about the mpich2-commits mailing list