multithreading - Parallel computing in Java for big data -
there 2 sets of matrices i.e. a(1 500 matrices) , b(150 000 matrices).
for each matrix set a, iterate through elements b b checking criteria on , b (if it's true matrix b, stop iterating , return true. if no match found after iterating entire set b, return false).
my question how make program parallel using java?
i understand matrices sets quite big (the numbers of elements posted above instance, in real-life case bigger). how correctly computations? create 1 5000 threads , computation not idea. optimal amount of threads, take computational work?
as said, may need check pair , there no heuristic order of checking if checking not need i/o or sth cause wast of cpu, if have 4 example 4
core, create 4
thread(0-3) , thread responsible checking a(4k+i)
, every b
. , before each checking in each thread, must check whether find true pair or not, can accomplished static variable in classes extends thread
public class worker extends thread{ static int found=0; /** * @param args command line arguments */ list<matrix> a; list<matrix> b; int myid; int corenumber; worker(list<matrix> a, list<matrix> b, int myid,int corenumber){ this.a=a; this.b=b; this.myid=myid; this.corenumber=corenumber; } @override public void run() { for(int i=myid;i<a.size();i+=corenumber){ for(int j=0;j<b.size();j++){ if(found==1){ return; } if(check(a.get(i),b.get(j))){ found=1; return; } } } } }
you need wait until threads stop working.
Comments
Post a Comment