protected override void CalcMatrix(object o) { //StreamWriter oo = new StreamWriter("dist.dat"); float[] center1 = new float[3]; float[] center2 = new float[3]; paramsThread p = (paramsThread)o; int maxV = -1; foreach (var item in indexList[p.k]) { int dd = FindIndex(item.Key); int distC = ThreadingGetDistance(structures[item.Key], structures[item.Value], center1, center2, p.k); if (distC < 0 || distC == int.MaxValue) { distC = -1; } distanceMatrix[dd + item.Value - item.Key] = distC; if (distC > maxV) { maxV = distC; } // oo.WriteLine(p.structures[item.Key] + " " + p.structures[item.Value] + " " + distC); } resetEvents[p.k].Set(); // oo.Close(); }
protected override void CalcMatrix(object o) { //StreamWriter oo = new StreamWriter("dist.dat"); paramsThread p = (paramsThread)o; int maxV = -1; foreach (var item in indexList[p.k]) { int dd = FindIndex(item.Key); int distC = GetDistance(structures[item.Key], structures[item.Value]); if (distC < 0 || distC == errorValue) { distC = -1; } distanceMatrix[dd + item.Value - item.Key] = distC; if (distC > maxV) { maxV = distC; } // oo.WriteLine(p.structures[item.Key] + " " + p.structures[item.Value] + " " + distC); Interlocked.Increment(ref currentV); } resetEvents[p.k].Set(); // oo.Close(); }
public override void CalcDistMatrix(List <string> structures) { hashIndex = new Dictionary <string, int>(structures.Count); for (int i = 0; i < structures.Count; i++) { if (!pdbs.molDic.ContainsKey(structures[i])) { throw new Exception("There is no pdb file or file is incorrect for the structure: " + structures[i]); } hashIndex.Add(structures[i], i); } Settings set = new Settings(); set.Load(); int threadNumbers = set.numberOfCores; this.structures = new List <string>(structures); int part = structures.Count * (structures.Count + 1) / (2 * threadNumbers) + 1; distanceMatrix = new int[structures.Count * (structures.Count + 1) / 2]; indexList = new List <KeyValuePair <int, int> > [threadNumbers]; optList = new Optimization[threadNumbers]; for (int n = 0; n < threadNumbers; n++) { indexList[n] = new List <KeyValuePair <int, int> >(part); optList[n] = new Optimization(); } int count = 0; foreach (var dim1 in structures) { foreach (var dim2 in structures) { if (hashIndex[dim1] <= hashIndex[dim2]) { indexList[count].Add(new KeyValuePair <int, int>(hashIndex[dim1], hashIndex[dim2])); if (part <= indexList[count].Count) { count++; } } } } PreparePDBPos(); resetEvents = new ManualResetEvent[threadNumbers]; for (int n = 0; n < threadNumbers; n++) { paramsThread p = new paramsThread(); p.k = n; ThreadPool.QueueUserWorkItem(new WaitCallback(CalcMatrix), (object)p); resetEvents[n] = new ManualResetEvent(false); } for (int j = 0; j < threadNumbers; j++) { resetEvents[j].WaitOne(); } }
public override void CalcDistMatrix(List <string> structures) { currentV = 0; hashIndex = new Dictionary<string, int>(structures.Count); for(int i=0;i<structures.Count;i++) { if (!pdbs.molDic.ContainsKey(structures[i])) throw new Exception("There is no pdb file or file is incorrect for the structure: " + structures[i]); hashIndex.Add(structures[i], i); } Settings set = new Settings(); set.Load(); int threadNumbers = set.numberOfCores; this.structures = new List<string>(structures); int part = structures.Count * (structures.Count+1) / (2 * threadNumbers)+1; distanceMatrix = new int[structures.Count * (structures.Count + 1) / 2]; indexList = new List<KeyValuePair<int, int>>[threadNumbers]; for (int n= 0; n < threadNumbers;n++) indexList[n] = new List<KeyValuePair<int, int>>(part); int count = 0; foreach (var dim1 in structures) { foreach (var dim2 in structures) { if (hashIndex[dim1] <= hashIndex[dim2]) { indexList[count].Add(new KeyValuePair<int, int>(hashIndex[dim1], hashIndex[dim2])); if (part <= indexList[count].Count) count++; } } } for (int n = 0; n < threadNumbers; n++) maxV += indexList[n].Count; // PreparePDBPos(); resetEvents = new ManualResetEvent[threadNumbers]; for(int n=0;n<threadNumbers;n++) { paramsThread p=new paramsThread(); p.k=n; resetEvents[n] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(new WaitCallback(CalcMatrix),(object) p); } for (int j = 0; j < threadNumbers; j++) resetEvents[j].WaitOne(); currentV = maxV; }