Must answer properly attach output screenshot What would be the CONCURRENT implementation of it. (identify which part(s) can be executed concurrently such that the overall result is correct but a faster execution is realized.) Totient ranges to be testes using concurrent implementation of the code: Sum of totients between 1 and 10000 Sum of totients between 1 and 20000 Sum of totients between 1 and 50000 what i understand so far: In order to implement this code in a concurrent manner, the sumTotient function would need to be segmented into many smaller parts that are capable of running in parallel with one another. For instance, the sumTotient method may be segmented into four distinct parts, with each part corresponding to a different set of numerical values (e.g. 1-2500, 2501-5000, 5001-7500, and 7501-10000). It would therefore be possible to process these four pieces simultaneously, which would result in a quicker overall execution time. What would be the CODE for the concurrent implementation? Using this code import java.lang.System; public class TotientRange{ long hcf(long x, long y){ long t; while (y != 0) { t = x % y; x = y; y = t; } return x; } boolean relprime(long x, long y){ return hcf(x, y) == 1; } long euler(long n){ long length, i; length = 0; for (i = 1; i <= n; i++) if (relprime(n, i)) length++; return length; } long sumTotient(long lower, long upper){ long sum, i; sum = 0; for (i = lower; i <= upper; i++) sum = sum + euler(i); return sum; } public static void main(String[] args){ long lower = 0; long upper = 0; try{ lower = Long.parseLong(args[0]); upper = Long.parseLong(args[1]); }catch(Exception e){ System.out.println("Error (lower: " + lower + ", upper: " + upper + ")"); return; } TotientRange tr = new TotientRange(); long startTime = System.nanoTime(); System.out.println("Totient Sum: " + tr.sumTotient(lower, upper)); long endTime = System.nanoTime(); long duration = ((endTime - startTime) / 1000000) / 1000; System.out.println("Time Taken: " + duration + " seconds"); } }
Must answer properly attach output screenshot
What would be the CONCURRENT implementation of it. (identify which part(s) can be executed concurrently such that the overall result
is correct but a faster execution is realized.)
Totient ranges to be testes using concurrent implementation of the code:
Sum of totients between 1 and 10000
Sum of totients between 1 and 20000
Sum of totients between 1 and 50000
what i understand so far:
In order to implement this code in a concurrent manner, the sumTotient function would need to be segmented into many smaller parts that are capable of running in parallel with one another. For instance, the sumTotient method may be segmented into four distinct parts, with each part corresponding to a different set of numerical values (e.g. 1-2500, 2501-5000, 5001-7500, and 7501-10000). It would therefore be possible to process these four pieces simultaneously, which would result in a quicker overall execution time.
What would be the CODE for the concurrent implementation?
Using this code
import java.lang.System;
public class TotientRange{
long hcf(long x, long y){
long t;
while (y != 0) {
t = x % y;
x = y;
y = t;
}
return x;
}
boolean relprime(long x, long y){
return hcf(x, y) == 1;
}
long euler(long n){
long length, i;
length = 0;
for (i = 1; i <= n; i++)
if (relprime(n, i))
length++;
return length;
}
long sumTotient(long lower, long upper){
long sum, i;
sum = 0;
for (i = lower; i <= upper; i++)
sum = sum + euler(i);
return sum;
}
public static void main(String[] args){
long lower = 0;
long upper = 0;
try{
lower = Long.parseLong(args[0]);
upper = Long.parseLong(args[1]);
}catch(Exception e){
System.out.println("Error (lower: " + lower + ", upper: " + upper + ")");
return;
}
TotientRange tr = new TotientRange();
long startTime = System.nanoTime();
System.out.println("Totient Sum: " + tr.sumTotient(lower, upper));
long endTime = System.nanoTime();
long duration = ((endTime - startTime) / 1000000) / 1000;
System.out.println("Time Taken: " + duration + " seconds");
}
}
Step by step
Solved in 2 steps with 1 images