Advertisement
peterurfi

[C++] Number of CPU threads

Oct 31st, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <thread>
  3.  
  4.  
  5. // main function
  6. // entry point to the application
  7. int main() {
  8.    
  9. #ifdef __APPLE__
  10.     std::cout << "This is a Mac running a darwin based system" << std::endl;
  11. #endif
  12.  
  13. #ifdef __WIN32__
  14.     std::cout << "This is a PC running a 32 or 64-bit version of Windows" << std::endl;
  15. #endif
  16.  
  17. #ifdef __WIN64__
  18.     std::cout << "This is a PC running a 64-bit version of Windows" << std::endl;
  19. #endif
  20.  
  21. #ifdef __linux__
  22.     std::cout << "This is a PC running Linux" << std::endl;
  23. #endif
  24.  
  25.    
  26.     // a standard function to get the number of available threads
  27.     unsigned int n = std::thread::hardware_concurrency();
  28.    
  29.     // printing out the number of threads to the standard output
  30.     std::cout << n << " concurrent threads are supported.\n";
  31.    
  32.     // normal run returns zero
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement