Skip to content
Permalink
Browse files

Create CallBackTask.java

  • Loading branch information
sus11005 committed Sep 28, 2016
1 parent 848673a commit c24f6e4741c9826ad930fb514ec3e42ce5f1b18b
Showing with 123 additions and 0 deletions.
  1. +123 −0 POMP-DETECT/CallBackTask.java
@@ -0,0 +1,123 @@
//package multicore;

//import spliced.Utilities;

import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

public class CallBackTask implements Callable {
private CallBackTest callBackTest;
private int seq;
public Utilities utilities;
public int start, end;

public CallBackTask() {
}

public CallBackTask(int i, int start, int end, Utilities utilities) {
this.utilities = utilities;
seq = i;
this.start = start;
this.end = end;
}

public static long getCpuTime() {
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
return bean.isCurrentThreadCpuTimeSupported() ? bean.getCurrentThreadCpuTime() : 0L;
}

public Object call() throws IOException {

long startCpuTimeNano = getCpuTime();

long begTest = new java.util.Date().getTime();
System.out.println("STARTING TASK: " + seq);

List<Utilities.Information> final_list = new ArrayList<Utilities.Information>(25000);

try {

int count = 0, hamming_distance, index, min_length;

for (int i = start; i <= end; i++) {

if(i == Utilities.union_list.size()){
break;
}

index = Utilities.union_list.get(i);
String read = Utilities.reads.get(index);

Utilities.reads.set(index, "");

if (Utilities.hash_map_one.containsKey(index) && Utilities.hash_map_two.containsKey(index)) {

List<Utilities.Information> info_list = utilities.processUMR(index, read.length());

final_list.addAll(info_list);

info_list.clear();

} else {

hamming_distance = 0;
min_length = 10;

List<Utilities.UMRInfo> list = utilities.PreProcessUMR(index, read);

if (list.size() > 0) {

List<Utilities.Information> info_list = utilities.processUMR(list, hamming_distance,
min_length, index, read.length());

if (info_list.size() <= 0) {

min_length = 8;

info_list = utilities.processUMR(list, hamming_distance, min_length, index, read.length());
}

final_list.addAll(info_list);
}
}

count++;

if (count % 1000 == 0) {

System.out.println("COMPLETED " + count + " BY " + seq + " [" + final_list.size() + "]");

long taskCpuTimeNano = getCpuTime() - startCpuTimeNano;
double time_in_seconds = (double) taskCpuTimeNano / 1000000000.0;

Double secs = (new java.util.Date().getTime() - begTest) * 0.001;
System.out.println("TASK - " + seq + " TOOK " + time_in_seconds + " SECONDS");
}
}
} catch (Exception x) {
x.printStackTrace();
System.out.println(x.getMessage());
}

callBackTest.callBack(seq, final_list);

long taskCpuTimeNano = getCpuTime() - startCpuTimeNano;
double time_in_seconds = (double) taskCpuTimeNano / 1000000000.0;

Double secs = (new java.util.Date().getTime() - begTest) * 0.001;
System.out.println("TASK - " + seq + " TOOK " + time_in_seconds + " SECONDS");
return null;
}

public void setCaller(CallBackTest callBackTest) {
this.callBackTest = callBackTest;
}

public CallBackTest getCaller() {
return callBackTest;
}
}

0 comments on commit c24f6e4

Please sign in to comment.
You can’t perform that action at this time.