Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / old / testmpi.cc
1 #include <sys/stat.h>
2 #include <iostream>
3 #include <string>
4 using namespace std;
5
6 #include "common/config.h"
7 #include "messages/MPing.h"
8 #include "common/Mutex.h"
9
10 #include "msg/MPIMessenger.h"
11
12 class Pinger : public Dispatcher {
13 public:
14   Messenger *messenger;
15   explicit Pinger(Messenger *m) : messenger(m) {
16     m->set_dispatcher(this);
17   }
18   void dispatch(Message *m) {
19     //dout(1) << "got incoming " << m << endl;
20     delete m;
21
22   }
23 };
24
25 int main(int argc, char **argv) {
26   int num = 1000;
27
28   int myrank = mpimessenger_init(argc, argv);
29   int world = mpimessenger_world();
30   
31   Pinger *p = new Pinger( new MPIMessenger(myrank) );
32
33   mpimessenger_start();
34
35   //while (1) {
36   for (int i=0; i<10000; i++) {
37     
38     // ping random nodes
39     int d = rand() % world;
40     if (d != myrank) {
41       //cout << "sending " << i << " to " << d << endl;
42       p->messenger->send_message(new MPing(), d);
43      }
44     
45   }
46
47
48   //cout << "shutting down" << endl;
49   //p->messenger->shutdown();
50   
51   mpimessenger_wait();
52   mpimessenger_shutdown();  // shutdown MPI
53 }