Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <thread>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. double coeficientes[] = { 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25,
  8. 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,0.25,0.25, 0.5, 0.5, 0.5, 0.25, 0.25, 0.25 };
  9.  
  10. void funcion1()
  11. {
  12. double mag = 10.0;
  13.  
  14. for (int i = 0; i < 320000; i++)
  15. {
  16. for (int i = 0; i < 80; i++) {
  17. coeficientes[i] = coeficientes[i] / mag;
  18. }
  19. }
  20. }
  21.  
  22. void funcion2()
  23. {
  24. double mag = 10.0;
  25.  
  26. for (int i = 0; i < 320000; i++)
  27. {
  28. #pragma omp simd
  29. for (int i = 0; i < 80; i++) {
  30. coeficientes[i] = coeficientes[i] / mag;
  31. }
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. auto start = std::chrono::system_clock::now();
  38.  
  39. funcion1();
  40. funcion2();
  41.  
  42. auto end = std::chrono::system_clock::now();
  43.  
  44. std::chrono::duration<double> elapsed = end - start;
  45. std::cout << "Elapsed timeA: " << elapsed.count() << "s" << endl;
  46.  
  47. start = std::chrono::system_clock::now();
  48.  
  49. thread t1(funcion1);
  50. thread t2(funcion2);
  51.  
  52. t1.join();
  53. t2.join();
  54.  
  55. end = std::chrono::system_clock::now();
  56.  
  57. elapsed = end - start;
  58. std::cout << "Elapsed timeB: " << elapsed.count() << "s \n\n";
  59.  
  60. cout << "Main es el hilo principal" << endl;
  61.  
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement