[mpich2-commits] r5594 - mpich2/trunk/src/pm/hydra/tools/bind/hwloc
mercierg at mcs.anl.gov
mercierg at mcs.anl.gov
Wed Oct 28 11:10:55 CDT 2009
Author: mercierg
Date: 2009-10-28 11:10:55 -0500 (Wed, 28 Oct 2009)
New Revision: 5594
Modified:
mpich2/trunk/src/pm/hydra/tools/bind/hwloc/bind_hwloc.c
Log:
New version of the Hwloc binding file: lot of fixes!
Modified: mpich2/trunk/src/pm/hydra/tools/bind/hwloc/bind_hwloc.c
===================================================================
--- mpich2/trunk/src/pm/hydra/tools/bind/hwloc/bind_hwloc.c 2009-10-28 08:49:48 UTC (rev 5593)
+++ mpich2/trunk/src/pm/hydra/tools/bind/hwloc/bind_hwloc.c 2009-10-28 16:10:55 UTC (rev 5594)
@@ -14,15 +14,20 @@
HYD_status HYDT_bind_hwloc_init(HYDT_bind_support_level_t * support_level)
{
- int proc,sock,core,thread,i,j;
- int num_cores = 0;
- int my_num_cores;
- int my_num_threads;
-
- hwloc_obj_t obj_sock,obj_core,obj_proc;
- hwloc_obj_t prev_obj = NULL;
- hwloc_cpuset_t cpuset_sock,cpuset_core;
+ hwloc_obj_t obj_sys;
+ hwloc_obj_t obj_node;
+ hwloc_obj_t obj_sock;
+ hwloc_obj_t obj_core;
+ hwloc_obj_t obj_proc;
+ hwloc_obj_t prev_obj;
+ hwloc_cpuset_t cpuset_sys;
+ hwloc_cpuset_t cpuset_node;
+ hwloc_cpuset_t cpuset_sock;
+ hwloc_cpuset_t cpuset_core;
+ int node,sock,core,proc,thread;
+ int bound,bound2;
+
HYD_status status = HYD_SUCCESS;
HYDU_FUNC_ENTER();
@@ -32,107 +37,115 @@
/* Get the max number of processing elements */
HYDT_bind_info.num_procs = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_PROC);
+
HYDU_MALLOC(HYDT_bind_info.topology, struct HYDT_topology *,
HYDT_bind_info.num_procs * sizeof(struct HYDT_topology), status);
- for (i = 0; i < HYDT_bind_info.num_procs; i++) {
- HYDT_bind_info.topology[i].processor_id = -1;
- HYDT_bind_info.topology[i].socket_rank = -1;
- HYDT_bind_info.topology[i].socket_id = -1;
- HYDT_bind_info.topology[i].core_rank = -1;
- HYDT_bind_info.topology[i].core_id = -1;
- HYDT_bind_info.topology[i].thread_rank = -1;
- HYDT_bind_info.topology[i].thread_id = -1;
+ for (proc = 0; proc < HYDT_bind_info.num_procs; proc++) {
+ HYDT_bind_info.topology[proc].processor_id = -1;
+ HYDT_bind_info.topology[proc].socket_rank = -1;
+ HYDT_bind_info.topology[proc].socket_id = -1;
+ HYDT_bind_info.topology[proc].core_rank = -1;
+ HYDT_bind_info.topology[proc].core_id = -1;
+ HYDT_bind_info.topology[proc].thread_rank = -1;
+ HYDT_bind_info.topology[proc].thread_id = -1;
}
- do{
- obj_proc = hwloc_get_next_obj_by_type(topology,HWLOC_OBJ_PROC,prev_obj);
- if (!obj_proc) {
- /* Unable to get processor ID */
- HYDU_warn_printf("hwloc get processor id failed\n");
- if (HYDT_bind_info.topology)
- HYDU_FREE(HYDT_bind_info.topology);
- goto fn_fail;
- }
- HYDT_bind_info.topology[i].processor_id = obj_proc->os_index;
- prev_obj = obj_proc;
- }while(prev_obj);
-
+ proc = 0;
+ prev_obj = NULL;
+ while(obj_proc = hwloc_get_next_obj_by_type(topology,HWLOC_OBJ_PROC,prev_obj))
+ {
+ HYDT_bind_info.topology[proc].processor_id = obj_proc->os_index;
+ prev_obj = obj_proc;
+ proc++;
+ }
+ assert(proc == HYDT_bind_info.num_procs);
+
/* We have qualified for basic binding support level */
*support_level = HYDT_BIND_BASIC;
+ /* get the System object */
+ obj_sys = hwloc_get_system_obj(topology);
+ cpuset_sys = obj_sys->cpuset;
+
/* Compute the total number of sockets */
- HYDT_bind_info.num_sockets = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_SOCKET);
- assert(HYDT_bind_info.num_sockets);
+ /* FIX ME : We assume that the number of sockets is the same for each node (e.g node 0)!*/
+ obj_node = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sys,HWLOC_OBJ_NODE,0);
+ HYDT_bind_info.num_sockets = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_node->cpuset,HWLOC_OBJ_SOCKET);
- /* Compute the total number of cores */
- my_num_cores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
- assert(my_num_cores);
-
- /* Compute again the total number of cores */
- for(i=0; i< HYDT_bind_info.num_sockets ; i++)
- {
- obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,i);
- num_cores += hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE);
- }
+ /* Compute the number of cores per socket */
+ /* FIX ME : We assume that the number of CORES is the same for each SOCKET (e.g sock 0)!*/
+ obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,0);
+ HYDT_bind_info.num_cores = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE);
- /* if this fails, it means that the number of cores */
- /* per socket is not always the same !*/
- assert(my_num_cores == num_cores);
+ HYDT_bind_info.num_threads = (HYDT_bind_info.num_procs/(hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_CORE)));
- HYDT_bind_info.num_cores = my_num_cores/HYDT_bind_info.num_sockets;
-
- /* Alternate version : We take the amount on socket 0 as the reference */
- /*
- obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,0);
- HYDT_bind_info.num_cores = hwloc_get_nbobjs_inside_cpuset_by_type(topology,&(obj_sock->cpuset),HWLOC_OBJ_CORE);
- */
+ for (proc = 0; proc < HYDT_bind_info.num_procs; proc++)
+ {
+ for(node = 0, bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_NODE); node < bound ; node++)
+ {
+ obj_node = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sys,HWLOC_OBJ_NODE,node);
+ cpuset_node = obj_node->cpuset;
- my_num_threads = HYDT_bind_info.num_procs/my_num_cores;
-
- /* Alternate version */
- HYDT_bind_info.num_threads = HYDT_bind_info.num_procs /
- (HYDT_bind_info.num_sockets * HYDT_bind_info.num_cores);
+ if(hwloc_cpuset_isset (cpuset_node, HYDT_bind_info.topology[proc].processor_id))
+ {
+ for(sock = 0, bound = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_node->cpuset,HWLOC_OBJ_SOCKET) ; sock < bound ; sock++)
+ {
+ obj_sock = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_node,HWLOC_OBJ_SOCKET,sock);
+ cpuset_sock = obj_sock->cpuset;
- /* these should be the same */
- assert(HYDT_bind_info.num_threads == my_num_threads);
+ if(hwloc_cpuset_isset (cpuset_sock, HYDT_bind_info.topology[proc].processor_id))
+ {
+ for(core = 0, bound2 = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE) ; core < bound2; core+\
+ +)
+ {
+ obj_core = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sock,HWLOC_OBJ_CORE,core);
+ cpuset_core = obj_core->cpuset;
- /* Find the socket and core IDs for all processor IDs */
- for(sock = 0 ; sock < HYDT_bind_info.num_sockets; sock++)
- {
- obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,sock);
- cpuset_sock = obj_sock->cpuset;
- num_cores = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE);
+ if (hwloc_cpuset_isset (cpuset_core, HYDT_bind_info.topology[proc].processor_id))
+ {
+ int j;
+ /* HYDT_bind_info.topology[proc].node_id = obj_node->os_index;*/
+ HYDT_bind_info.topology[proc].socket_id = obj_sock->os_index;
+ HYDT_bind_info.topology[proc].core_id = obj_core->os_index;
- for(core = 0 ; core < num_cores; core++)
- {
- obj_core = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sock,HWLOC_OBJ_CORE,core);
- cpuset_core = obj_core->cpuset;
- for (proc = 0; proc < HYDT_bind_info.num_procs; proc++)
- {
- if((hwloc_cpuset_isset (cpuset_sock, proc)) &&
- (hwloc_cpuset_isset (cpuset_core, proc)))
- {
- HYDT_bind_info.topology[proc].socket_id = sock;
- HYDT_bind_info.topology[proc].core_id = core;
-
- thread = -1;
- for (j = 0; j < proc; j++)
- if ((HYDT_bind_info.topology[j].socket_id == sock) &&
- (HYDT_bind_info.topology[j].core_id == core))
- thread = HYDT_bind_info.topology[j].thread_id;
- thread++;
-
- HYDT_bind_info.topology[proc].thread_id = thread;
- HYDT_bind_info.topology[proc].thread_rank = thread;
-
- break;
- }
- }
- }
- }
+ thread = -1;
+ for (j = 0; j < proc; j++)
+ {
+ /* if ((HYDT_bind_info.topology[j].node_id == obj_node->os_index) &&
+ (HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) &&
+ (HYDT_bind_info.topology[j].core_id == obj_core->os_index))
+ */
+ if ((HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) &&
+ (HYDT_bind_info.topology[j].core_id == obj_core->os_index))
+ thread = HYDT_bind_info.topology[j].thread_id;
+ }
+ thread++;
+ HYDT_bind_info.topology[proc].thread_id = thread;
+ HYDT_bind_info.topology[proc].thread_rank = thread;
+ break;
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ /* Get the rank of each node ID */
+ /*
+ for(node = 0, bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_NODE) ; node < bound ; node++)
+ {
+ obj_node = hwloc_get_obj_by_type(topology,HWLOC_OBJ_NODE,node);
+ for (proc = 0; proc < HYDT_bind_info.num_procs; proc++)
+ if (HYDT_bind_info.topology[proc].node_id == obj_node->os_index)
+ HYDT_bind_info.topology[proc].node_rank = node;
+ }
+ */
+
/* Get the rank of each socket ID */
- for(sock = 0 ; sock < HYDT_bind_info.num_sockets; sock++)
+ for(sock = 0, bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_SOCKET) ; sock < bound; sock++)
{
obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,sock);
for (proc = 0; proc < HYDT_bind_info.num_procs; proc++)
@@ -141,7 +154,7 @@
}
/* Find the rank of each core ID */
- for (core = 0; core < my_num_cores ; core++)
+ for (core = 0, bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_CORE); core < bound ; core++)
{
obj_core = hwloc_get_obj_by_type(topology,HWLOC_OBJ_CORE,core);
for (proc = 0; proc < HYDT_bind_info.num_procs; proc++)
More information about the mpich2-commits
mailing list