Skip to content

Commit

Permalink
introduce "auto" options when picking CPU logic cores
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron533 committed Feb 3, 2024
1 parent 18d0b31 commit 107da13
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions DicomGrep/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<StackPanel Orientation="Horizontal">
<Label Content="Treads: "/>
<ComboBox ItemsSource="{Binding CPULogicCores}" SelectedValue="{Binding SearchThreads}" MinWidth="70"/>
<Label Content="0=auto"/>
</StackPanel>
</StackPanel>
</StackPanel>
Expand Down
2 changes: 1 addition & 1 deletion DicomGrep/Services/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static Configuration DefaultConfiguration()
IncludeSubfolders = true,
MatchPattern = MatchPatternEnum.Normal,
SearchInResults = false,
SearchThreads = 1
SearchThreads = 0
};

return new Configuration
Expand Down
7 changes: 4 additions & 3 deletions DicomGrep/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ public int SearchThreads
set { SetProperty(ref _searchThreads, value); }
}

public ObservableCollection<int> CPULogicCores { set; get; } = new ObservableCollection<int>();

#endregion Search Criteria END

public ObservableCollection<int> CPULogicCores { set; get; } = new ObservableCollection<int>();

private int _totalFileCount;
public int TotalFileCount
{
Expand Down Expand Up @@ -348,7 +348,8 @@ public MainViewModel()

private IEnumerable<int> GetCPULogicCoresList()
{
for (int i = 1; i <= Environment.ProcessorCount; i++)
// 0 means auto
for (int i = 0; i <= Environment.ProcessorCount; i++)
{
yield return i;
}
Expand Down
2 changes: 1 addition & 1 deletion DicomGrepCore/Services/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void Search(SearchCriteria criteria, CancellationTokenSource tokenSource)

ParallelOptions options = new ParallelOptions
{
MaxDegreeOfParallelism = criteria.SearchThreads,
MaxDegreeOfParallelism = criteria.SearchThreads <= 0 ? Environment.ProcessorCount : criteria.SearchThreads ,
CancellationToken = this.token
};
try
Expand Down

0 comments on commit 107da13

Please sign in to comment.