Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. package loopUnroll;
  2.  
  3. class isPrime {
  4.    
  5.     static boolean isPrime(int n, int i) //taken from geeksforgeeks
  6.     {
  7.         if (n <= 2)
  8.             return (n == 2) ? true : false;
  9.         if (n % i == 0)
  10.             return false;
  11.         if (i * i > n)
  12.             return true;
  13.        
  14.         // Check for next divisor
  15.         return isPrime(n, i + 1);
  16.     }
  17. }
  18.  
  19.  public class LoopClass
  20. {
  21.     private int n; //how many primes
  22.    
  23.     isPrime x = new isPrime();
  24.    
  25.     public LoopClass(int n)
  26.     {
  27.         this.n = n;
  28.     }
  29.    
  30.     public void Roll()
  31.     {
  32.         //for(int i = 0; i < this.n; i++) //go until workload
  33.         int i = 0;
  34.         while(true)
  35.         {
  36.             try
  37.             {
  38.                 if(isPrime.isPrime(i, 2))
  39.                 {
  40.                     //System.out.println(i);
  41.                     i++;
  42.                     continue;
  43.                 }
  44.                
  45.             }
  46.             catch(Exception e)
  47.             {
  48.                 System.out.println(e);
  49.                 System.out.println("Reached " + i);
  50.             }
  51.         }
  52.     }
  53.    
  54.     public void Unroll(int L)
  55.     {
  56.         //for(int i = 0; i < this.n; i++) //go until workload
  57.         int i = 0;
  58.         while(true)
  59.         {
  60.             int j = 0;
  61.             try
  62.             {
  63.                 do
  64.                 {
  65.                     if(isPrime.isPrime(i, 2)) //should do this L times per unroll?
  66.                     {
  67.                         i++;
  68.                         continue;
  69.                     }
  70.                 j++;
  71.                 }while(j < L);
  72.                
  73.             }
  74.             catch(Exception e)
  75.             {
  76.                 System.out.println(e);
  77.                 System.out.println("Reached " + i);
  78.             }
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement