[mpich2-commits] r5445 - in mpich2/trunk/src/pm/hydra/utils/bind: . plpa
balaji at mcs.anl.gov
balaji at mcs.anl.gov
Sun Oct 11 15:32:14 CDT 2009
Author: balaji
Date: 2009-10-11 15:32:14 -0500 (Sun, 11 Oct 2009)
New Revision: 5445
Modified:
mpich2/trunk/src/pm/hydra/utils/bind/bind.c
mpich2/trunk/src/pm/hydra/utils/bind/bind.h
mpich2/trunk/src/pm/hydra/utils/bind/plpa/bind_plpa.c
mpich2/trunk/src/pm/hydra/utils/bind/plpa/bind_plpa.h
Log:
Modified the binding code to deal with the querying of all information
inside init, instead of doing it for each call.
Modified: mpich2/trunk/src/pm/hydra/utils/bind/bind.c
===================================================================
--- mpich2/trunk/src/pm/hydra/utils/bind/bind.c 2009-10-11 05:44:30 UTC (rev 5444)
+++ mpich2/trunk/src/pm/hydra/utils/bind/bind.c 2009-10-11 20:32:14 UTC (rev 5445)
@@ -15,35 +15,115 @@
HYD_Status HYDU_bind_init(char *binding, char *bindlib)
{
- char *user_bind_map;
+ char *bindstr, *bindentry;
+ int sock, core, thread, i, j;
HYD_Status status = HYD_SUCCESS;
HYDU_FUNC_ENTER();
HYDU_bind_info.support_level = HYDU_BIND_NONE;
- HYDU_bind_info.bind_map = NULL;
+ HYDU_bind_info.topology = NULL;
+ HYDU_bind_info.bindlib = HYDU_strdup(bindlib);
- if (binding)
- HYDU_bind_info.binding = HYDU_strdup(binding);
- else
- HYDU_bind_info.binding = HYDU_strdup("none");
+ if (!binding || !strcmp(binding, "none")) {
+ /* If no binding is given, we just set all mappings to -1 */
+ HYDU_MALLOC(HYDU_bind_info.bindmap, int *, sizeof(int), status);
+ HYDU_bind_info.num_procs = 1;
+ HYDU_bind_info.bindmap[0] = -1;
- if (!strncmp(HYDU_bind_info.binding, "user:", strlen("user:"))) {
- user_bind_map = HYDU_bind_info.binding + strlen("user:");
- HYDU_bind_info.binding[strlen("user")] = '\0';
+ goto fn_exit;
}
- else
- user_bind_map = NULL;
- HYDU_bind_info.bindlib = bindlib;
+ 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 */
+ HYDU_bind_info.num_procs = 0;
+ bindentry = strtok(bindstr, ",");
+ while (bindentry) {
+ HYDU_bind_info.num_procs++;
+ bindentry = strtok(NULL, ",");
+ }
+
+ /* Find the actual processing elements */
+ HYDU_MALLOC(HYDU_bind_info.bindmap, int *, HYDU_bind_info.num_procs * sizeof(int),
+ status);
+ i = 0;
+ bindentry = strtok(bindstr, ",");
+ while (bindentry) {
+ HYDU_bind_info.bindmap[i++] = atoi(bindentry);
+ bindentry = strtok(NULL, ",");
+ }
+
+ goto fn_exit;
+ }
+
+ /* If a real binding is required, we initialize the binding
+ * library requested by the user */
#if defined HAVE_PLPA
if (!strcmp(HYDU_bind_info.bindlib, "plpa")) {
- status = HYDU_bind_plpa_init(user_bind_map, &HYDU_bind_info.support_level);
+ status = HYDU_bind_plpa_init(&HYDU_bind_info.support_level);
HYDU_ERR_POP(status, "unable to initialize plpa\n");
}
#endif /* HAVE_PLPA */
+ if (HYDU_bind_info.support_level != HYDU_BIND_NONE) {
+ HYDU_MALLOC(HYDU_bind_info.bindmap, int *, HYDU_bind_info.num_procs * sizeof(int),
+ status);
+
+ for (i = 0; i < HYDU_bind_info.num_procs; i++) {
+
+ /* RR is supported at the basic binding level */
+ if (!strcmp(binding, "rr")) {
+ HYDU_bind_info.bindmap[i] = i;
+ continue;
+ }
+
+ /* If we reached here, the user requested for topology
+ * aware binding. */
+ if (HYDU_bind_info.support_level != HYDU_BIND_TOPO)
+ HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR,
+ "topology binding not supported on this platform\n");
+
+ if (!strcmp(binding, "buddy")) {
+ thread = i / (HYDU_bind_info.num_sockets * HYDU_bind_info.num_cores);
+
+ core = i % (HYDU_bind_info.num_sockets * HYDU_bind_info.num_cores);
+ core /= HYDU_bind_info.num_sockets;
+
+ sock = i % HYDU_bind_info.num_sockets;
+ }
+ else if (!strcmp(binding, "pack")) {
+ sock = i / (HYDU_bind_info.num_cores * HYDU_bind_info.num_threads);
+
+ core = i % (HYDU_bind_info.num_cores * HYDU_bind_info.num_threads);
+ core /= HYDU_bind_info.num_threads;
+
+ thread = i % HYDU_bind_info.num_threads;
+ }
+ else {
+ HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "unknown binding option\n");
+ }
+
+ for (j = 0; j < HYDU_bind_info.num_procs; j++) {
+ if (HYDU_bind_info.topology[j].socket_rank == sock &&
+ HYDU_bind_info.topology[j].core_rank == core &&
+ HYDU_bind_info.topology[j].thread_rank == thread) {
+ HYDU_bind_info.bindmap[i] = HYDU_bind_info.topology[j].processor_id;
+ break;
+ }
+ }
+ }
+ }
+ else {
+ /* If no binding is supported, we just set all mappings to -1 */
+ HYDU_MALLOC(HYDU_bind_info.bindmap, int *, sizeof(int), status);
+ HYDU_bind_info.num_procs = 1;
+ HYDU_bind_info.bindmap[0] = -1;
+ }
+
fn_exit:
HYDU_FUNC_EXIT();
return status;
@@ -76,69 +156,5 @@
int HYDU_bind_get_core_id(int id)
{
- int sock, core, thread, i, realid;
- HYD_Status status = HYD_SUCCESS;
-
- HYDU_FUNC_ENTER();
-
- if (HYDU_bind_info.support_level != HYDU_BIND_NONE) {
- realid = (id % HYDU_bind_info.num_procs);
-
- /* NONE, RR and USER are supported at the basic binding
- * level */
- if (!strcmp(HYDU_bind_info.binding, "none")) {
- return -1;
- }
- else if (!strcmp(HYDU_bind_info.binding, "rr")) {
- return HYDU_bind_info.bind_map[realid].processor_id;
- }
- else if (!strcmp(HYDU_bind_info.binding, "user")) {
- if (!HYDU_bind_info.user_bind_valid)
- return -1;
- else
- return HYDU_bind_info.user_bind_map[realid];
- }
-
- /* If we reached here, the user requested for topology aware
- * binding. */
- if (HYDU_bind_info.support_level == HYDU_BIND_TOPO) {
- if (!strcmp(HYDU_bind_info.binding, "buddy")) {
- thread = realid / (HYDU_bind_info.num_sockets * HYDU_bind_info.num_cores);
-
- core = realid % (HYDU_bind_info.num_sockets * HYDU_bind_info.num_cores);
- core /= HYDU_bind_info.num_sockets;
-
- sock = realid % HYDU_bind_info.num_sockets;
- }
- else if (!strcmp(HYDU_bind_info.binding, "pack")) {
- sock = realid / (HYDU_bind_info.num_cores * HYDU_bind_info.num_threads);
-
- core = realid % (HYDU_bind_info.num_cores * HYDU_bind_info.num_threads);
- core /= HYDU_bind_info.num_threads;
-
- thread = realid % HYDU_bind_info.num_threads;
- }
- else {
- HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "unknown binding option\n");
- }
-
- for (i = 0; i < HYDU_bind_info.num_procs; i++) {
- if (HYDU_bind_info.bind_map[i].socket_rank == sock &&
- HYDU_bind_info.bind_map[i].core_rank == core &&
- HYDU_bind_info.bind_map[i].thread_rank == thread) {
- return HYDU_bind_info.bind_map[i].processor_id;
- }
- }
- }
- else {
- HYDU_Error_printf("Topology-aware binding is not supported on this platform\n");
- }
- }
-
-fn_exit:
- HYDU_FUNC_EXIT();
- return -1;
-
-fn_fail:
- goto fn_exit;
+ return HYDU_bind_info.bindmap[id % HYDU_bind_info.num_procs];
}
Modified: mpich2/trunk/src/pm/hydra/utils/bind/bind.h
===================================================================
--- mpich2/trunk/src/pm/hydra/utils/bind/bind.h 2009-10-11 05:44:30 UTC (rev 5444)
+++ mpich2/trunk/src/pm/hydra/utils/bind/bind.h 2009-10-11 20:32:14 UTC (rev 5445)
@@ -15,32 +15,29 @@
HYDU_BIND_TOPO
} HYDU_bind_support_level_t;
-typedef struct {
- int processor_id;
-
- int socket_rank;
- int socket_id;
-
- int core_rank;
- int core_id;
-
- int thread_rank;
- int thread_id;
-} HYDU_bind_map_t;
-
struct HYDU_bind_info {
HYDU_bind_support_level_t support_level;
+
int num_procs;
int num_sockets;
int num_cores;
int num_threads;
- char *binding;
+ int *bindmap;
char *bindlib;
- HYDU_bind_map_t *bind_map;
- int user_bind_valid;
- int *user_bind_map;
+ struct HYDU_topology {
+ int processor_id;
+
+ int socket_rank;
+ int socket_id;
+
+ int core_rank;
+ int core_id;
+
+ int thread_rank;
+ int thread_id;
+ } *topology;
};
extern struct HYDU_bind_info HYDU_bind_info;
Modified: mpich2/trunk/src/pm/hydra/utils/bind/plpa/bind_plpa.c
===================================================================
--- mpich2/trunk/src/pm/hydra/utils/bind/plpa/bind_plpa.c 2009-10-11 05:44:30 UTC (rev 5444)
+++ mpich2/trunk/src/pm/hydra/utils/bind/plpa/bind_plpa.c 2009-10-11 20:32:14 UTC (rev 5445)
@@ -13,7 +13,7 @@
#include "plpa.h"
#include "plpa_internal.h"
-HYD_Status HYDU_bind_plpa_init(char *user_bind_map, HYDU_bind_support_level_t *support_level)
+HYD_Status HYDU_bind_plpa_init(HYDU_bind_support_level_t *support_level)
{
PLPA_NAME(api_type_t) p;
int ret, i, j, max, id;
@@ -38,16 +38,16 @@
goto fn_fail;
}
- HYDU_MALLOC(HYDU_bind_info.bind_map, HYDU_bind_map_t *,
- HYDU_bind_info.num_procs * sizeof(HYDU_bind_map_t), status);
+ HYDU_MALLOC(HYDU_bind_info.topology, struct HYDU_topology *,
+ HYDU_bind_info.num_procs * sizeof(struct HYDU_topology), status);
for (i = 0; i < HYDU_bind_info.num_procs; i++) {
- HYDU_bind_info.bind_map[i].processor_id = -1;
- HYDU_bind_info.bind_map[i].socket_rank = -1;
- HYDU_bind_info.bind_map[i].socket_id = -1;
- HYDU_bind_info.bind_map[i].core_rank = -1;
- HYDU_bind_info.bind_map[i].core_id = -1;
- HYDU_bind_info.bind_map[i].thread_rank = -1;
- HYDU_bind_info.bind_map[i].thread_id = -1;
+ HYDU_bind_info.topology[i].processor_id = -1;
+ HYDU_bind_info.topology[i].socket_rank = -1;
+ HYDU_bind_info.topology[i].socket_id = -1;
+ HYDU_bind_info.topology[i].core_rank = -1;
+ HYDU_bind_info.topology[i].core_id = -1;
+ HYDU_bind_info.topology[i].thread_rank = -1;
+ HYDU_bind_info.topology[i].thread_id = -1;
}
for (i = 0; i < HYDU_bind_info.num_procs; i++) {
@@ -55,38 +55,16 @@
if (ret) {
/* Unable to get processor ID */
HYDU_Warn_printf("plpa get processor id failed\n");
- if (HYDU_bind_info.bind_map)
- HYDU_FREE(HYDU_bind_info.bind_map);
+ if (HYDU_bind_info.topology)
+ HYDU_FREE(HYDU_bind_info.topology);
goto fn_fail;
}
- HYDU_bind_info.bind_map[i].processor_id = processor;
+ HYDU_bind_info.topology[i].processor_id = processor;
}
/* We have qualified for basic binding support level */
*support_level = HYDU_BIND_BASIC;
- /* If the user is specifying the binding, we just use it */
- if (user_bind_map) {
- HYDU_MALLOC(HYDU_bind_info.user_bind_map, int *,
- HYDU_bind_info.num_procs * sizeof(int), status);
- for (i = 0; i < HYDU_bind_info.num_procs; i++)
- HYDU_bind_info.user_bind_map[i] = -1;
-
- HYDU_bind_info.user_bind_valid = 1;
- i = 0;
- str = strtok(user_bind_map, ",");
- do {
- if (!str || i >= HYDU_bind_info.num_procs)
- break;
- HYDU_bind_info.user_bind_map[i++] = atoi(str);
- str = strtok(NULL, ",");
- } while (1);
-
- /* For user binding, we don't need to get the topology
- * information */
- goto fn_exit;
- }
-
/* PLPA only gives information about sockets and cores */
ret = PLPA_NAME(get_socket_info) (&HYDU_bind_info.num_sockets, &max);
if (ret) {
@@ -107,7 +85,7 @@
/* Find the socket and core IDs for all processor IDs */
for (i = 0; i < HYDU_bind_info.num_procs; i++) {
- ret = PLPA_NAME(map_to_socket_core) (HYDU_bind_info.bind_map[i].processor_id,
+ ret = PLPA_NAME(map_to_socket_core) (HYDU_bind_info.topology[i].processor_id,
&sock, &core);
if (ret) {
/* Unable to get number of cores */
@@ -115,18 +93,18 @@
goto fn_fail;
}
- HYDU_bind_info.bind_map[i].socket_id = sock;
- HYDU_bind_info.bind_map[i].core_id = core;
+ HYDU_bind_info.topology[i].socket_id = sock;
+ HYDU_bind_info.topology[i].core_id = core;
thread = -1;
for (j = 0; j < i; j++)
- if (HYDU_bind_info.bind_map[j].socket_id == sock &&
- HYDU_bind_info.bind_map[j].core_id == core)
- thread = HYDU_bind_info.bind_map[j].thread_id;
+ if (HYDU_bind_info.topology[j].socket_id == sock &&
+ HYDU_bind_info.topology[j].core_id == core)
+ thread = HYDU_bind_info.topology[j].thread_id;
thread++;
- HYDU_bind_info.bind_map[i].thread_id = thread;
- HYDU_bind_info.bind_map[i].thread_rank = thread;
+ HYDU_bind_info.topology[i].thread_id = thread;
+ HYDU_bind_info.topology[i].thread_rank = thread;
}
/* Find the rank of each socket ID */
@@ -138,21 +116,21 @@
goto fn_fail;
}
for (j = 0; j < HYDU_bind_info.num_procs; j++)
- if (HYDU_bind_info.bind_map[j].socket_id == id)
- HYDU_bind_info.bind_map[j].socket_rank = i;
+ if (HYDU_bind_info.topology[j].socket_id == id)
+ HYDU_bind_info.topology[j].socket_rank = i;
}
/* Find the rank of each core ID */
for (i = 0; i < HYDU_bind_info.num_cores; i++) {
- ret = PLPA_NAME(get_core_id) (HYDU_bind_info.bind_map[0].socket_id, i, &id);
+ ret = PLPA_NAME(get_core_id) (HYDU_bind_info.topology[0].socket_id, i, &id);
if (ret) {
/* Unable to get socket id */
HYDU_Warn_printf("plpa unable to get socket id\n");
goto fn_fail;
}
for (j = 0; j < HYDU_bind_info.num_procs; j++)
- if (HYDU_bind_info.bind_map[j].core_id == id)
- HYDU_bind_info.bind_map[j].core_rank = i;
+ if (HYDU_bind_info.topology[j].core_id == id)
+ HYDU_bind_info.topology[j].core_rank = i;
}
/* We have qualified for topology-aware binding support level */
Modified: mpich2/trunk/src/pm/hydra/utils/bind/plpa/bind_plpa.h
===================================================================
--- mpich2/trunk/src/pm/hydra/utils/bind/plpa/bind_plpa.h 2009-10-11 05:44:30 UTC (rev 5444)
+++ mpich2/trunk/src/pm/hydra/utils/bind/plpa/bind_plpa.h 2009-10-11 20:32:14 UTC (rev 5445)
@@ -7,7 +7,7 @@
#ifndef BIND_PLPA_H_INCLUDED
#define BIND_PLPA_H_INCLUDED
-HYD_Status HYDU_bind_plpa_init(char *user_bind_map, HYDU_bind_support_level_t *support_level);
+HYD_Status HYDU_bind_plpa_init(HYDU_bind_support_level_t *support_level);
HYD_Status HYDU_bind_plpa_process(int core);
#endif /* BIND_PLPA_H_INCLUDED */
More information about the mpich2-commits
mailing list