public void doSomeWork()\r
{\r
int MAX = 100000;\r
+ int ittr = 100;\r
+\r
long sum = 0;\r
long time = System.currentTimeMillis();\r
\r
//I did the for loop this way so that each parallel thread would take\r
//about the same time \r
- for(int i = 0; i < MAX/2 + 1; i++)\r
+ for(int i = 0; i < MAX/2 + 1; i += ittr)\r
{\r
int innerSum = 0;\r
\r
sese a \r
{\r
+ for(int j = i; (j < i + ittr) && j < MAX/2 + 1; j++)\r
+ {\r
\r
- int oppositeNum = MAX - i;\r
+ int oppositeNum = MAX - j;\r
\r
- if(isPrime(i))\r
- innerSum += i;\r
+ if(isPrime(j))\r
+ innerSum += j;\r
\r
- if(i != oppositeNum && isPrime(oppositeNum))\r
+ if(i != oppositeNum && isPrime(oppositeNum))\r
innerSum += oppositeNum;\r
+ }\r
}\r
\r
sese b \r
\r
System.out.println("The sum of primes from 1 to " + MAX + " is " + sum + ".");\r
System.out.println("Note: 1 is counted as a prime.");\r
- System.out.println("Time Consumed (Not Parallelized): " + (System.currentTimeMillis() - time) + " ms");\r
+ System.out.println("Time Consumed: " + (System.currentTimeMillis() - time) + " ms");\r
\r
}\r
\r