Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedier gptmd again #2448

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
19 changes: 15 additions & 4 deletions MetaMorpheus/EngineLayer/Gptmd/GptmdEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ public static bool ModFits(Modification attemptToLocalize, IBioPolymer protein,

protected override MetaMorpheusEngineResults RunSpecific()
{
var modDict = new ConcurrentDictionary<string, ConcurrentBag<Tuple<int, Modification>>>();
var mergedDictionaries = new ConcurrentDictionary<string, ConcurrentBag<Tuple<int, Modification>>>();
int modsAdded = 0;

int maxThreadsPerFile = CommonParameters.MaxThreadsToUsePerFile;
var psms = AllIdentifications.Where(b => b.FdrInfo.QValueNotch <= 0.05 && !b.IsDecoy).ToList();
if (psms.Any() == false)
Expand All @@ -76,6 +75,7 @@ protected override MetaMorpheusEngineResults RunSpecific()
}
Parallel.ForEach(Partitioner.Create(0, psms.Count), new ParallelOptions() { MaxDegreeOfParallelism = maxThreadsPerFile }, (range) =>
{
var modDict = new ConcurrentDictionary<string, ConcurrentBag<Tuple<int, Modification>>>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be concurrent, as it is created inside the parallel loop, i.e., one per thread

for (int i = range.Item1; i < range.Item2; i++)
{
foreach (var pepWithSetMods in psms[i].BestMatchingBioPolymersWithSetMods.Select(v => v.Peptide as PeptideWithSetModifications))
Expand Down Expand Up @@ -173,10 +173,21 @@ protected override MetaMorpheusEngineResults RunSpecific()
}
}
}
foreach (var kvp in modDict)
{
mergedDictionaries.AddOrUpdate(kvp.Key, kvp.Value, (key, oldValue) =>
{
foreach (var item in kvp.Value)
{
oldValue.Add(item);
}
return oldValue;
});
}
});

// Convert ConcurrentDictionary to Dictionary with HashSet
var finalModDictionary = modDict.ToDictionary(
var finalModDictionary = mergedDictionaries.ToDictionary(
kvp => kvp.Key,
kvp => new HashSet<Tuple<int, Modification>>(kvp.Value)
);
Expand Down Expand Up @@ -241,4 +252,4 @@ private static IEnumerable<Modification> GetPossibleMods(double totalMassToGetTo
}
}
}
}
}