@@ -821,7 +821,7 @@ qvi_hwloc_emit_cpubind(
821
821
if (rc != QV_SUCCESS) goto out;
822
822
823
823
qvi_log_info (
824
- " [pid={} tid={}] cpubind (physical)=[ {}" ,
824
+ " [pid={} tid={}] cpubind (physical) = {}" ,
825
825
getpid (), task_id, cpusets
826
826
);
827
827
out:
@@ -844,37 +844,32 @@ qvi_hwloc_bitmap_asprintf(
844
844
}
845
845
846
846
if (topo) {
847
+ hwloc_bitmap_t cpuset_logical = hwloc_bitmap_alloc ();
847
848
hwloc_obj_t obj_pu = nullptr ;
848
849
849
850
int num_pus = hwloc_get_nbobjs_inside_cpuset_by_type (topo, cpuset, HWLOC_OBJ_PU);
850
- int num_pus_cp = num_pus;
851
-
852
- int num_digits = 1 ;
853
- while (num_pus_cp /= 10 ) num_digits++;
854
-
855
- char head[] = " ] | (logical)=[" ;
856
- int str_size = strlen (head)+num_pus*(num_digits+1 )+1 ;
857
- char *str = (char *)calloc (str_size,sizeof (char ));
858
-
859
- strcpy (str,head);
860
-
861
- char *core_str = (char *)calloc (num_digits+2 ,sizeof (char ));
862
851
for (int idx = 0 ; idx < num_pus ; idx++){
863
852
obj_pu = hwloc_get_next_obj_inside_cpuset_by_type (topo, cpuset, HWLOC_OBJ_PU, obj_pu);
864
- sprintf (core_str," %i%s" ,obj_pu->logical_index , idx == (num_pus-1 ) ? " ]" :" ," );
865
- strcat (str,core_str);
866
- memset (core_str,0 ,strlen (core_str));
853
+ (void )hwloc_bitmap_set (cpuset_logical,obj_pu->logical_index );
867
854
}
868
855
869
- char *newstr = (char *)calloc (strlen (str)+strlen (iresult)+1 ,sizeof (char ));
870
- strcpy (newstr,iresult);
871
- strcat (newstr,str);
872
-
873
- free (core_str);
874
- free (str);
856
+ char *iresult_logical = nullptr ;
857
+ (void )hwloc_bitmap_list_asprintf (&iresult_logical, cpuset_logical);
858
+ if (qvi_unlikely (!iresult_logical)) {
859
+ qvi_log_error (" hwloc_bitmap_list_asprintf() failed" );
860
+ return QV_ERR_OOR;
861
+ }
862
+ (void )hwloc_bitmap_free (cpuset_logical);
863
+
864
+ char head[] = " | (logical) = " ;
865
+ char *final_result = (char *)calloc (strlen (iresult)+
866
+ strlen (head)+
867
+ strlen (iresult_logical)+1 ,sizeof (char ));
868
+ memcpy (final_result,iresult,strlen (iresult));
869
+ strcat (final_result,head);
870
+ strcat (final_result,iresult_logical);
875
871
free (iresult);
876
-
877
- iresult = newstr;
872
+ iresult = final_result;
878
873
}
879
874
880
875
*result = iresult;
@@ -895,37 +890,32 @@ qvi_hwloc_bitmap_list_asprintf(
895
890
}
896
891
897
892
if (topo) {
893
+ hwloc_bitmap_t cpuset_logical = hwloc_bitmap_alloc ();
898
894
hwloc_obj_t obj_pu = nullptr ;
899
895
900
896
int num_pus = hwloc_get_nbobjs_inside_cpuset_by_type (topo, cpuset, HWLOC_OBJ_PU);
901
- int num_pus_cp = num_pus;
902
-
903
- int num_digits = 1 ;
904
- while (num_pus_cp /= 10 ) num_digits++;
905
-
906
- char head[] = " ] | (logical)=[" ;
907
- int str_size = strlen (head)+num_pus*(num_digits+1 )+1 ;
908
- char *str = (char *)calloc (str_size,sizeof (char ));
909
-
910
- strcpy (str,head);
911
-
912
- char *core_str = (char *)calloc (num_digits+2 ,sizeof (char ));
913
897
for (int idx = 0 ; idx < num_pus ; idx++){
914
898
obj_pu = hwloc_get_next_obj_inside_cpuset_by_type (topo, cpuset, HWLOC_OBJ_PU, obj_pu);
915
- sprintf (core_str," %i%s" ,obj_pu->logical_index , idx == (num_pus-1 ) ? " ]" :" ," );
916
- strcat (str,core_str);
917
- memset (core_str,0 ,strlen (core_str));
899
+ (void )hwloc_bitmap_set (cpuset_logical,obj_pu->logical_index );
918
900
}
919
901
920
- char *newstr = (char *)calloc (strlen (str)+strlen (iresult)+1 ,sizeof (char ));
921
- strcpy (newstr,iresult);
922
- strcat (newstr,str);
923
-
924
- free (core_str);
925
- free (str);
902
+ char *iresult_logical = nullptr ;
903
+ (void )hwloc_bitmap_list_asprintf (&iresult_logical, cpuset_logical);
904
+ if (qvi_unlikely (!iresult_logical)) {
905
+ qvi_log_error (" hwloc_bitmap_list_asprintf() failed" );
906
+ return QV_ERR_OOR;
907
+ }
908
+ (void )hwloc_bitmap_free (cpuset_logical);
909
+
910
+ char head[] = " | (logical) = " ;
911
+ char *final_result = (char *)calloc (strlen (iresult)+
912
+ strlen (head)+
913
+ strlen (iresult_logical)+1 ,sizeof (char ));
914
+ memcpy (final_result,iresult,strlen (iresult));
915
+ strcat (final_result,head);
916
+ strcat (final_result,iresult_logical);
926
917
free (iresult);
927
-
928
- iresult = newstr;
918
+ iresult = final_result;
929
919
}
930
920
931
921
*result = iresult;
0 commit comments