| 72 | | /* Compute the number of sockets per NUMA Node */ |
| 73 | | /* FIX ME : We assume that the number of sockets is the same for each node (e.g node 0)!*/ |
| 74 | | obj_node = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sys,HWLOC_OBJ_NODE,0); |
| 75 | | if(obj_node) |
| 76 | | HYDT_bind_info.num_sockets = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_node->cpuset,HWLOC_OBJ_SOCKET); |
| 77 | | else |
| 78 | | HYDT_bind_info.num_sockets = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_SOCKET); |
| 79 | | |
| 80 | | /* Compute the number of cores per socket */ |
| 81 | | /* FIX ME : We assume that the number of CORES is the same for each SOCKET (e.g sock 0)!*/ |
| 82 | | obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,0); |
| 83 | | if(obj_node) |
| 84 | | HYDT_bind_info.num_cores = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE); |
| 85 | | else |
| 86 | | HYDT_bind_info.num_cores = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_CORE); |
| 87 | | |
| 88 | | HYDT_bind_info.num_threads = (HYDT_bind_info.num_procs/(hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_CORE))); |
| | 70 | /* In case there is no socket! */ |
| | 71 | if(!node_ptr->num_children) |
| | 72 | node_ptr->num_children = 1; |
| | 73 | |
| | 74 | HYDU_MALLOC(node_ptr->children, struct HYDT_topo_obj *, |
| | 75 | sizeof(struct HYDT_topo_obj) * node_ptr->num_children, status); |
| | 76 | node_ptr->shared_memory_depth = NULL; |
| | 77 | |
| | 78 | /* Setup the socket level */ |
| | 79 | for (sock = 0; sock < node_ptr->num_children ; sock++) |
| | 80 | { |
| | 81 | sock_ptr = &node_ptr->children[sock]; |
| | 82 | sock_ptr->type = HYDT_TOPO_SOCKET; |
| | 83 | sock_ptr->parent = node_ptr; |
| | 84 | |
| | 85 | obj_sock = hwloc_get_obj_inside_cpuset_by_type(topology,obj_node->cpuset,HWLOC_OBJ_SOCKET,sock); |
| | 86 | if(!obj_sock) |
| | 87 | obj_sock = obj_node; |
| | 88 | |
| | 89 | sock_ptr->os_index = obj_sock->os_index; |
| | 90 | sock_ptr->num_children = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE); |
| | 91 | |
| | 92 | /* In case there is no core! */ |
| | 93 | if(!sock_ptr->num_children) |
| | 94 | sock_ptr->num_children = 1; |
| 90 | | bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_NODE); |
| 91 | | for (proc = 0; proc < HYDT_bind_info.num_procs; proc++) |
| 92 | | { |
| 93 | | if (bound == 0) |
| 94 | | { |
| 95 | | for(sock = 0, bound2 = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_SOCKET) ; |
| 96 | | sock < bound2 ; |
| 97 | | sock++) |
| 98 | | { |
| 99 | | obj_sock = obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,sock); |
| 100 | | cpuset_sock = obj_sock->cpuset; |
| 101 | | |
| 102 | | if(hwloc_cpuset_isset (cpuset_sock, HYDT_bind_info.topology[proc].processor_id)) |
| 103 | | { |
| 104 | | for(core = 0, bound3 = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE) ; |
| 105 | | core < bound3; |
| 106 | | core++) |
| 107 | | { |
| 108 | | obj_core = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sock,HWLOC_OBJ_CORE,core); |
| 109 | | cpuset_core = obj_core->cpuset; |
| 110 | | |
| 111 | | if (hwloc_cpuset_isset (cpuset_core, HYDT_bind_info.topology[proc].processor_id)) |
| 112 | | { |
| 113 | | int j; |
| 114 | | /* HYDT_bind_info.topology[proc].node_id = obj_node->os_index;*/ |
| 115 | | HYDT_bind_info.topology[proc].socket_id = obj_sock->os_index; |
| 116 | | HYDT_bind_info.topology[proc].core_id = obj_core->os_index; |
| 117 | | |
| 118 | | thread = -1; |
| 119 | | for (j = 0; j < proc; j++) |
| 120 | | { |
| 121 | | /* if ((HYDT_bind_info.topology[j].node_id == obj_node->os_index) && |
| 122 | | (HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) && |
| 123 | | (HYDT_bind_info.topology[j].core_id == obj_core->os_index)) |
| 124 | | */ |
| 125 | | if ((HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) && |
| 126 | | (HYDT_bind_info.topology[j].core_id == obj_core->os_index)) |
| 127 | | thread = HYDT_bind_info.topology[j].thread_id; |
| 128 | | } |
| 129 | | thread++; |
| 130 | | HYDT_bind_info.topology[proc].thread_id = thread; |
| 131 | | HYDT_bind_info.topology[proc].thread_rank = thread; |
| 132 | | |
| 133 | | break; |
| 134 | | } |
| 135 | | } |
| 136 | | } |
| 137 | | } |
| 138 | | } |
| 139 | | else |
| 140 | | { |
| 141 | | for(node = 0; node < bound ; node++) |
| 142 | | { |
| 143 | | obj_node = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sys,HWLOC_OBJ_NODE,node); |
| 144 | | cpuset_node = obj_node->cpuset; |
| 145 | | |
| 146 | | if(hwloc_cpuset_isset (cpuset_node, HYDT_bind_info.topology[proc].processor_id)) |
| 147 | | { |
| 148 | | for(sock = 0, bound2 = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_node->cpuset,HWLOC_OBJ_SOCKET) ; sock < bound2 ; sock++) |
| 149 | | { |
| 150 | | obj_sock = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_node,HWLOC_OBJ_SOCKET,sock); |
| 151 | | cpuset_sock = obj_sock->cpuset; |
| 152 | | |
| 153 | | if(hwloc_cpuset_isset (cpuset_sock, HYDT_bind_info.topology[proc].processor_id)) |
| 154 | | { |
| 155 | | for(core = 0, bound3 = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE) ; core < bound3; core+\ |
| 156 | | +) |
| 157 | | { |
| 158 | | obj_core = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sock,HWLOC_OBJ_CORE,core); |
| 159 | | cpuset_core = obj_core->cpuset; |
| 160 | | |
| 161 | | if (hwloc_cpuset_isset (cpuset_core, HYDT_bind_info.topology[proc].processor_id)) |
| 162 | | { |
| 163 | | int j; |
| 164 | | /* HYDT_bind_info.topology[proc].node_id = obj_node->os_index;*/ |
| 165 | | HYDT_bind_info.topology[proc].socket_id = obj_sock->os_index; |
| 166 | | HYDT_bind_info.topology[proc].core_id = obj_core->os_index; |
| 167 | | |
| 168 | | thread = -1; |
| 169 | | for (j = 0; j < proc; j++) |
| 170 | | { |
| 171 | | /* if ((HYDT_bind_info.topology[j].node_id == obj_node->os_index) && |
| 172 | | (HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) && |
| 173 | | (HYDT_bind_info.topology[j].core_id == obj_core->os_index)) |
| 174 | | */ |
| 175 | | if ((HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) && |
| 176 | | (HYDT_bind_info.topology[j].core_id == obj_core->os_index)) |
| 177 | | thread = HYDT_bind_info.topology[j].thread_id; |
| 178 | | } |
| 179 | | thread++; |
| 180 | | HYDT_bind_info.topology[proc].thread_id = thread; |
| 181 | | HYDT_bind_info.topology[proc].thread_rank = thread; |
| 182 | | |
| 183 | | break; |
| 184 | | } |
| 185 | | } |
| 186 | | } |
| 187 | | } |
| 188 | | |
| 189 | | } |
| 190 | | } |
| 191 | | } |
| 192 | | } |
| 193 | | |
| 194 | | |
| 195 | | /* Get the rank of each node ID */ |
| 196 | | /* |
| 197 | | for(node = 0, bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_NODE) ; node < bound ; node++) |
| 198 | | { |
| 199 | | obj_node = hwloc_get_obj_by_type(topology,HWLOC_OBJ_NODE,node); |
| 200 | | for (proc = 0; proc < HYDT_bind_info.num_procs; proc++) |
| 201 | | if (HYDT_bind_info.topology[proc].node_id == obj_node->os_index) |
| 202 | | HYDT_bind_info.topology[proc].node_rank = node; |
| 203 | | } |
| 204 | | */ |
| 205 | | |
| 206 | | /* Get the rank of each socket ID */ |
| 207 | | for(sock = 0, bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_SOCKET) ; sock < bound; sock++) |
| 208 | | { |
| 209 | | obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,sock); |
| 210 | | for (proc = 0; proc < HYDT_bind_info.num_procs; proc++) |
| 211 | | if (HYDT_bind_info.topology[proc].socket_id == obj_sock->os_index) |
| 212 | | HYDT_bind_info.topology[proc].socket_rank = sock; |
| 213 | | } |
| 214 | | |
| 215 | | /* Find the rank of each core ID */ |
| 216 | | for (core = 0, bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_CORE); core < bound ; core++) |
| 217 | | { |
| 218 | | obj_core = hwloc_get_obj_by_type(topology,HWLOC_OBJ_CORE,core); |
| 219 | | for (proc = 0; proc < HYDT_bind_info.num_procs; proc++) |
| 220 | | if (HYDT_bind_info.topology[proc].core_id == obj_core->os_index) |
| 221 | | HYDT_bind_info.topology[proc].core_rank = core; |
| | 96 | HYDU_MALLOC(sock_ptr->children, struct HYDT_topo_obj *, |
| | 97 | sizeof(struct HYDT_topo_obj) * sock_ptr->num_children, status); |
| | 98 | sock_ptr->shared_memory_depth = NULL; |
| | 99 | |
| | 100 | /* setup the core level */ |
| | 101 | for (core = 0; core < sock_ptr->num_children; core++) |
| | 102 | { |
| | 103 | core_ptr = &sock_ptr->children[core]; |
| | 104 | core_ptr->type = HYDT_TOPO_CORE; |
| | 105 | core_ptr->parent = sock_ptr; |
| | 106 | |
| | 107 | obj_core = hwloc_get_obj_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE,core); |
| | 108 | if(!obj_core) |
| | 109 | obj_core = obj_sock; |
| | 110 | |
| | 111 | core_ptr->os_index = obj_core->os_index; |
| | 112 | core_ptr->num_children = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_core->cpuset,HWLOC_OBJ_PROC); |
| | 113 | |
| | 114 | HYDU_MALLOC(core_ptr->children, struct HYDT_topo_obj *, |
| | 115 | sizeof(struct HYDT_topo_obj) * core_ptr->num_children, status); |
| | 116 | core_ptr->shared_memory_depth = NULL; |
| | 117 | |
| | 118 | /* setup the thread level */ |
| | 119 | for (thread = 0; thread < core_ptr->num_children; thread++) |
| | 120 | { |
| | 121 | obj_proc = hwloc_get_obj_inside_cpuset_by_type(topology,obj_core->cpuset,HWLOC_OBJ_PROC,thread); |
| | 122 | thread_ptr = &core_ptr->children[thread]; |
| | 123 | thread_ptr->type = HYDT_TOPO_THREAD; |
| | 124 | thread_ptr->os_index = obj_proc->os_index; |
| | 125 | thread_ptr->parent = core_ptr; |
| | 126 | thread_ptr->num_children = 0; |
| | 127 | thread_ptr->children = NULL; |
| | 128 | thread_ptr->shared_memory_depth = NULL; |
| | 129 | |
| | 130 | /* |
| | 131 | fprintf(stdout," thread id %i | Core id %i | Socket id %i | Node id %i \n", |
| | 132 | obj_proc->os_index,obj_core->os_index,obj_sock->os_index,obj_node->os_index); |
| | 133 | */ |
| | 134 | } |
| | 135 | |
| | 136 | } |
| | 137 | } |