Advertisement
Guest User

replace your prime function with this matt

a guest
Feb 20th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. //Prime function
  2. void* Prime(void* index){
  3. int temp_index;
  4.  
  5. temp_index = *((int*)index);
  6. long sum_t = 0;
  7.  
  8. for(long i = start_numbers[temp_index]; i <= numbers[temp_index]; i++){
  9.  
  10. // Corner cases
  11.  
  12. if(i<=1)continue;
  13. if (i <= 3){
  14. sum_t++;
  15. continue;
  16. }
  17.  
  18.  
  19. for (int j=2; j*j <= i; j++)
  20. {
  21. if ((i % j == 0) || (i %( j+2))==0 )
  22. {
  23. break;
  24. }
  25. else if (j+1 > sqrt(i)) {
  26. sum_t++;
  27. }
  28. }
  29.  
  30. }
  31.  
  32. cout << "Thread " << temp_index << " terminates" << endl;
  33. pthread_exit( (void*) sum_t);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement