Advertisement
Guest User

example

a guest
Jun 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <shogun/base/init.h>
  2. #include <shogun/lib/Signal.h>
  3. #include <shogun/machine/Machine.h>
  4. #include <iostream>
  5. #include <thread>
  6.  
  7. using namespace shogun;
  8. using namespace std;
  9.  
  10. class MockAlg : public CMachine {
  11.    
  12.     public:
  13.     MockAlg() {}
  14.     ~MockAlg() {}
  15.  
  16.     void loop() {
  17.         #pragma omp parallel for
  18.         for (int i=0; i<1000; i++)
  19.         {
  20.             if (cancel_computation())
  21.                 continue;
  22.             cout << i << endl;
  23.             this_thread::sleep_for(chrono::milliseconds(1000));
  24.         }      
  25.     }
  26. };
  27.  
  28. int main() {
  29.    
  30.     init_shogun_with_defaults();
  31.    
  32.     // Enable the signal handler
  33.     get_global_signal()->enable_handler();
  34.  
  35.     MockAlg a;
  36.     a.connect_to_signal_handler();
  37.     MockAlg b;
  38.  
  39.     cout << "RUN FIRST TEST" << endl;
  40.     a.loop();
  41.  
  42.     cout << "RUN SECOND TEST" << endl;
  43.     b.connect_to_signal_handler();
  44.     b.loop();
  45.  
  46.     return 0;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement