@@ -82,33 +82,33 @@ unsigned int highs::parallel::available_core_count() {
8282 process_groups.data ()))
8383 return fallback_core_count ();
8484
85- // For single-group processes, get the affinity mask for precise filtering
86- DWORD_PTR process_mask = 0 ;
85+ // For single-group processes, get the affinity mask for precise filtering;
86+ // for multi-group, all bits set means no filtering.
87+ DWORD_PTR process_mask = ~static_cast <DWORD_PTR >(0 );
8788 if (process_group_count == 1 ) {
8889 DWORD_PTR system_mask;
89- if (!GetProcessAffinityMask (GetCurrentProcess (), &process_mask,
90- &system_mask))
91- process_mask = 0 ;
90+ GetProcessAffinityMask (GetCurrentProcess (), &process_mask, &system_mask);
9291 }
9392
9493 // Query topology across all groups via GetLogicalProcessorInformationEx
9594 DWORD length = 0 ;
9695 GetLogicalProcessorInformationEx (RelationProcessorCore, nullptr , &length);
9796 if (GetLastError () != ERROR_INSUFFICIENT_BUFFER ) return fallback_core_count ();
9897
98+ // Variable-size entries packed in a byte buffer
9999 std::vector<char > buffer (length);
100- if (!GetLogicalProcessorInformationEx (
101- RelationProcessorCore,
102- reinterpret_cast <PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX >(
103- buffer.data ()),
104- &length))
100+ auto entry_at = [&](DWORD offset) {
101+ return reinterpret_cast <PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX >(
102+ buffer.data () + offset);
103+ };
104+ if (!GetLogicalProcessorInformationEx (RelationProcessorCore, entry_at (0 ),
105+ &length))
105106 return fallback_core_count ();
106107
107108 unsigned int physical_cores = 0 ;
108109 DWORD offset = 0 ;
109110 while (offset < length) {
110- auto * entry = reinterpret_cast <PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX >(
111- buffer.data () + offset);
111+ auto * entry = entry_at (offset);
112112 if (entry->Relationship == RelationProcessorCore) {
113113 for (WORD i = 0 ; i < entry->Processor .GroupCount ; i++) {
114114 WORD group = entry->Processor .GroupMask [i].Group ;
@@ -117,14 +117,7 @@ unsigned int highs::parallel::available_core_count() {
117117 if (std::find (process_groups.begin (), process_groups.end (), group) ==
118118 process_groups.end ())
119119 continue ;
120- // For single-group processes, filter by affinity mask
121- if (process_mask) {
122- if (mask & process_mask) physical_cores++;
123- } else {
124- // Multi-group: no per-group affinity API, count all cores
125- assert (mask);
126- physical_cores++;
127- }
120+ if (mask & process_mask) physical_cores++;
128121 }
129122 }
130123 offset += entry->Size ;
0 commit comments