38
38
import edu .ucsd .msjava .mzml .MzMLAdapter ;
39
39
import edu .ucsd .msjava .params .ParamManager ;
40
40
import edu .ucsd .msjava .sequences .Constants ;
41
+ import java .util .concurrent .ThreadPoolExecutor ;
42
+ import java .util .logging .Level ;
43
+ import java .util .logging .Logger ;
41
44
42
45
43
46
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" ;
47
49
48
50
public static final String DECOY_DB_EXTENSION = ".revCat.fasta" ;
49
51
public static final String DECOY_PROTEIN_PREFIX = "XXX" ;
@@ -323,22 +325,24 @@ private static String runMSGFPlus(int ioIndex, SpecFileFormat specFormat, File o
323
325
System .out .println ("Spectrum " + fromIndexGlobal + "-" + (toIndexGlobal -1 ) + " (total: " + specSize + ")" );
324
326
325
327
// Thread pool
326
- ExecutorService executor = Executors .newFixedThreadPool (numThreads );
328
+ ThreadPoolExecutor executor = ( ThreadPoolExecutor ) Executors .newFixedThreadPool (numThreads );
327
329
330
+ int numTasks = Math .min (Math .max (numThreads * 10 , 128 ), Math .round (specSize /1000f ));
331
+
328
332
// Partition specKeyList
329
333
int size = toIndexGlobal - fromIndexGlobal ;
330
- int residue = size % numThreads ;
334
+ int residue = size % numTasks ;
331
335
332
- int [] startIndex = new int [numThreads ];
333
- int [] endIndex = new int [numThreads ];
336
+ int [] startIndex = new int [numTasks ];
337
+ int [] endIndex = new int [numTasks ];
334
338
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 ++)
337
341
{
338
342
startIndex [i ] = i > 0 ? endIndex [i -1 ] : fromIndexGlobal ;
339
343
endIndex [i ] = startIndex [i ] + subListSize + (i < residue ? 1 : 0 );
340
344
341
- subListSize = size /numThreads ;
345
+ subListSize = size /numTasks ;
342
346
while (endIndex [i ] < specKeyList .size ())
343
347
{
344
348
SpecKey lastSpecKey = specKeyList .get (endIndex [i ]-1 );
@@ -354,7 +358,7 @@ private static String runMSGFPlus(int ioIndex, SpecFileFormat specFormat, File o
354
358
}
355
359
}
356
360
357
- for (int i =0 ; i <numThreads ; i ++)
361
+ for (int i =0 ; i <numTasks ; i ++)
358
362
{
359
363
ScoredSpectraMap specScanner = new ScoredSpectraMap (
360
364
specAcc ,
@@ -371,21 +375,39 @@ private static String runMSGFPlus(int ioIndex, SpecFileFormat specFormat, File o
371
375
specScanner .turnOffEdgeScoring ();
372
376
373
377
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
+ );
379
384
executor .execute (msgfdbExecutor );
380
385
}
381
386
382
387
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
+ }
383
404
384
405
try {
385
406
executor .awaitTermination (Long .MAX_VALUE , TimeUnit .NANOSECONDS );
386
407
} catch (InterruptedException e )
387
408
{
388
409
e .printStackTrace ();
410
+ Logger .getLogger (MSGFPlus .class .getName ()).log (Level .SEVERE , null , e );
389
411
}
390
412
//while(!executor.isTerminated()) {} // wait until all threads terminate
391
413
0 commit comments