Open MPI logo

PLPA Users' Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all PLPA Users mailing list

Subject: [PLPA users] [PATCH 2/5] replace 'max_socket_id + 1' with a special variable
From: Bert Wesarg (bert.wesarg_at_[hidden])
Date: 2009-07-23 17:47:47


No functional change.

---
 src/libplpa/plpa_map.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/libplpa/plpa_map.c b/src/libplpa/plpa_map.c
index 43265f6..c66f859 100644
--- a/src/libplpa/plpa_map.c
+++ b/src/libplpa/plpa_map.c
@@ -138,6 +138,7 @@ static int num_processors = -1;
 static int max_processor_id = -1;
 static int num_sockets = -1;
 static int max_socket_id = -1;
+static int socket_index_extent = 0;
 static int *max_core_id = NULL;
 static int *num_cores = NULL;
 static int max_core_id_overall = -1;
@@ -176,6 +177,7 @@ static void clear_cache(void)
 
     num_processors = max_processor_id = -1;
     num_sockets = max_socket_id = -1;
+    socket_index_extent = 0;
     max_core_id_overall = -1;
 }
 
@@ -356,19 +358,22 @@ static void load_cache(void)
         return;
     }
 
+    /* index range for sockets, [0, socket_index_extent) */
+    socket_index_extent = max_socket_id + 1;
+
     /* Now that we know the max number of sockets, allocate some
        arrays */
-    max_core_id = malloc(sizeof(int) * (max_socket_id + 1));
+    max_core_id = malloc(sizeof(int) * socket_index_extent);
     if (NULL == max_core_id) {
         clear_cache();
         return;
     }
-    num_cores = malloc(sizeof(int) * (max_socket_id + 1));
+    num_cores = malloc(sizeof(int) * socket_index_extent);
     if (NULL == num_cores) {
         clear_cache();
         return;
     }
-    for (i = 0; i <= max_socket_id; ++i) {
+    for (i = 0; i < socket_index_extent; ++i) {
         num_cores[i] = -1;
         max_core_id[i] = -1;
     }
@@ -393,7 +398,7 @@ static void load_cache(void)
        may not be the same as max_socket_id because there may be
        "holes" -- e.g., sockets 0 and 3 are used, but sockets 1 and 2
        are empty. */
-    for (j = i = 0; i <= max_socket_id; ++i) {
+    for (j = i = 0; i < socket_index_extent; ++i) {
         if (max_core_id[i] >= 0) {
             ++j;
         }
@@ -407,12 +412,12 @@ static void load_cache(void)
        "holes".  I don't know if holes can happen (i.e., if specific
        cores can be taken offline), but what the heck... */
     cores_on_sockets = malloc(sizeof(PLPA_NAME(cpu_set_t)) * 
-                              (max_socket_id + 1));
+                              socket_index_extent);
     if (NULL == cores_on_sockets) {
         clear_cache();
         return;
     }
-    for (i = 0; i <= max_socket_id; ++i) {
+    for (i = 0; i < socket_index_extent; ++i) {
         PLPA_CPU_ZERO(&(cores_on_sockets[i]));
     }
     for (i = 0; i <= max_processor_id; ++i) {
@@ -423,7 +428,7 @@ static void load_cache(void)
                          &(cores_on_sockets[socket_index]));
         }
     }
-    for (i = 0; i <= max_socket_id; ++i) {
+    for (i = 0; i < socket_index_extent; ++i) {
         int count = 0;
         for (j = 0; j <= max_core_id[i]; ++j) {
             if (PLPA_CPU_ISSET(j, &(cores_on_sockets[i]))) {
@@ -441,14 +446,14 @@ static void load_cache(void)
        entries in the other map (i.e., it's by reference instead of by
        value). */
     map_tuple_to_processor_id = malloc(sizeof(tuple_t *) *
-                                       ((max_socket_id + 1) *
+                                       (socket_index_extent *
                                         (max_core_id_overall + 1)));
     if (NULL == map_tuple_to_processor_id) {
         clear_cache();
         return;
     }
     /* Compute map */
-    for (i = 0; i <= max_socket_id; ++i) {
+    for (i = 0; i < socket_index_extent; ++i) {
         int socket_id = socket_index_to_id(i);
         for (j = 0; j <= max_core_id_overall; ++j) {
             tuple_t **tuple_ptr = &map_tuple_to_processor_id[
@@ -884,7 +889,7 @@ int PLPA_NAME(get_socket_id)(int socket_num, int *socket_id)
     }
 
     /* Find the socket_num'th socket */
-    for (count = i = 0; i <= max_socket_id; ++i) {
+    for (count = i = 0; i < socket_index_extent; ++i) {
         /* See if any core in this socket is active.  If so, count
            this socket */
         for (j = 0; j <= max_core_id_overall; ++j) {
-- 
1.6.3.3.618.gce7bf