I have a function called doWork(int a, int b, int c, int amount)
that computes some amount of a total calculation set. In my main I determine how many calculations each function call should do. What I need is to know is how to pass a,b,c
so that each call to the function will do it own slice of the calculation.
int nprocs = 2;
int total = 10
public static void main() {
//total number of calculations to compute
int totalLoad = ((total*total*total)/6)-(total/6);
//number of calculations per function call
int workLoad = totalLoad/nproc;
for(int i = 0; i < nproc; i++) {
doWork(a, b, c, workLoad);
}
}
public void doWork(int i,int j,int k, int amount) {
boolean start = true;
for(; i < total && amount != 0; i++) {
if(!start) {
j = i+1;
}
for(; j < total && amount != 0; j++) {
if(!start) {
k = j;
}
for(; k < total && amount != 0; k++) {
if(start) {
start = false;
}
//some calculation here
System.out.println(format(i,j,k));
amount--;
}
}
}
Each function call needs to handle a different sub-section of the total calculation to be made. For example:
nproc = 2
totalLoad = 6
Total work: Function call 1:
calc 1 calc 1
calc 2 calc 2
calc 3 calc 3
calc 4
calc 5 Function call 2:
calc 6 calc 4
calc 5
calc 6
Also, is there a cleaner way to write the doWork() function. It just seems messy to me.