Skip to content

Commit 375d462

Browse files
committed
Memory usage improvements; release 2016.01.20
Use a number of tasks (usually > 128), rather than "numThreads" tasks Output "Task completed." whenever a task completes.
1 parent 686abae commit 375d462

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

src/main/java/edu/ucsd/msjava/msdbsearch/ConcurrentMSGFPlus.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ public static class RunMSGFPlus implements Runnable {
88
private final DBScanner scanner;
99
SearchParams params;
1010
List<MSGFPlusMatch> resultList;
11+
private final int taskNum;
1112

1213
public RunMSGFPlus(
1314
ScoredSpectraMap specScanner,
1415
CompactSuffixArray sa,
1516
SearchParams params,
16-
List<MSGFPlusMatch> resultList
17+
List<MSGFPlusMatch> resultList,
18+
int taskNum
1719
)
1820
{
1921
this.specScanner = specScanner;
@@ -31,11 +33,14 @@ public RunMSGFPlus(
3133
params.ignoreMetCleavage()
3234
);
3335
this.resultList = resultList;
36+
this.taskNum = taskNum;
3437
}
3538

39+
@Override
3640
public void run()
3741
{
3842
String threadName = Thread.currentThread().getName();
43+
System.out.println(threadName+": Starting task " + taskNum);
3944

4045
// Pre-process spectra
4146
long time = System.currentTimeMillis();
@@ -72,6 +77,7 @@ public void run()
7277

7378
scanner.addResultsToList(resultList);
7479
// gen.addSpectrumIdentificationResults(scanner.getSpecIndexDBMatchMap());
80+
System.out.print(threadName+": Task " + taskNum + " completed.");
7581
}
7682
}
7783
}

src/main/java/edu/ucsd/msjava/ui/MSGFPlus.java

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
import edu.ucsd.msjava.mzml.MzMLAdapter;
3939
import edu.ucsd.msjava.params.ParamManager;
4040
import edu.ucsd.msjava.sequences.Constants;
41+
import java.util.concurrent.ThreadPoolExecutor;
42+
import java.util.logging.Level;
43+
import java.util.logging.Logger;
4144

4245

4346
public class MSGFPlus {
44-
public static final String VERSION = "Beta (v10282)";
45-
// public static final String VERSION = "Test_Multithreading (v10064)";
46-
public static final String RELEASE_DATE = "12/19/2014";
47+
public static final String VERSION = "Release (v2016.01.20)";
48+
public static final String RELEASE_DATE = "1/20/2016";
4749

4850
public static final String DECOY_DB_EXTENSION = ".revCat.fasta";
4951
public static final String DECOY_PROTEIN_PREFIX = "XXX";
@@ -323,22 +325,24 @@ private static String runMSGFPlus(int ioIndex, SpecFileFormat specFormat, File o
323325
System.out.println("Spectrum " + fromIndexGlobal + "-" + (toIndexGlobal-1) + " (total: " + specSize + ")");
324326

325327
// Thread pool
326-
ExecutorService executor = Executors.newFixedThreadPool(numThreads);
328+
ThreadPoolExecutor executor = (ThreadPoolExecutor)Executors.newFixedThreadPool(numThreads);
327329

330+
int numTasks = Math.min(Math.max(numThreads * 10, 128), Math.round(specSize/1000f));
331+
328332
// Partition specKeyList
329333
int size = toIndexGlobal - fromIndexGlobal;
330-
int residue = size % numThreads;
334+
int residue = size % numTasks;
331335

332-
int[] startIndex = new int[numThreads];
333-
int[] endIndex = new int[numThreads];
336+
int[] startIndex = new int[numTasks];
337+
int[] endIndex = new int[numTasks];
334338

335-
int subListSize = size/numThreads;
336-
for(int i=0; i<numThreads; i++)
339+
int subListSize = size/numTasks;
340+
for(int i=0; i<numTasks; i++)
337341
{
338342
startIndex[i] = i > 0 ? endIndex[i-1] : fromIndexGlobal;
339343
endIndex[i] = startIndex[i] + subListSize + (i < residue ? 1 : 0);
340344

341-
subListSize = size/numThreads;
345+
subListSize = size/numTasks;
342346
while(endIndex[i] < specKeyList.size())
343347
{
344348
SpecKey lastSpecKey = specKeyList.get(endIndex[i]-1);
@@ -354,7 +358,7 @@ private static String runMSGFPlus(int ioIndex, SpecFileFormat specFormat, File o
354358
}
355359
}
356360

357-
for(int i=0; i<numThreads; i++)
361+
for(int i=0; i<numTasks; i++)
358362
{
359363
ScoredSpectraMap specScanner = new ScoredSpectraMap(
360364
specAcc,
@@ -371,21 +375,39 @@ private static String runMSGFPlus(int ioIndex, SpecFileFormat specFormat, File o
371375
specScanner.turnOffEdgeScoring();
372376

373377
ConcurrentMSGFPlus.RunMSGFPlus msgfdbExecutor = new ConcurrentMSGFPlus.RunMSGFPlus(
374-
specScanner,
375-
sa,
376-
params,
377-
resultList
378-
);
378+
specScanner,
379+
sa,
380+
params,
381+
resultList,
382+
i + 1
383+
);
379384
executor.execute(msgfdbExecutor);
380385
}
381386

382387
executor.shutdown();
388+
389+
// TODO: Detect exceptions in the threads, and exit early.
390+
// One thread got interrupted, so all of the results will be incomplete. Exit.
391+
//return "Task terminated; results incomplete. Please run again with a greater amount of memory, using \"-Xmx4G\", for example.";
392+
393+
while (executor.getActiveCount() > 1) {
394+
try {
395+
double completed = executor.getCompletedTaskCount();
396+
double total = executor.getTaskCount();
397+
double progress = (completed / total) * 100.0;
398+
System.out.format("Search progress: %.0f / %.0f tasks, %.1f%%%n", completed, total, progress);
399+
Thread.sleep(60000); // Output every minute
400+
} catch (InterruptedException ex) {
401+
Logger.getLogger(MSGFPlus.class.getName()).log(Level.SEVERE, null, ex);
402+
}
403+
}
383404

384405
try {
385406
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
386407
} catch (InterruptedException e)
387408
{
388409
e.printStackTrace();
410+
Logger.getLogger(MSGFPlus.class.getName()).log(Level.SEVERE, null, e);
389411
}
390412
//while(!executor.isTerminated()) {} // wait until all threads terminate
391413

0 commit comments

Comments
 (0)