Fix MPI interoperation example and add it to test script
[charm.git] / examples / charm++ / mpi-coexist / libs / hello / hello.C
bloba2feea4756c56897ece94aa0c575afe1c206563a
1 #include <stdio.h>
2 #include "hello.decl.h"
3 //header from Charm to enable Interoperation
4 #include "mpi-interoperate.h"
6 /*mainchare*/
7 class MainHello : public CBase_MainHello
9 public:
10   MainHello(int elems)
11   {
12     //Process command-line arguments
13     int nElements=elems;
14     //Start the computation
15     CkPrintf("Running Hello on %d processors for %d elements\n",
16              CkNumPes(),nElements);
17     CProxy_MainHello mainHelloProxy = thisProxy;
19     CProxy_Hello arr = CProxy_Hello::ckNew(mainHelloProxy, nElements, nElements);
21     arr[0].SayHi(0);
22   };
24   MainHello(CkMigrateMessage *m) {}
26   void done(void)
27   {
28     CkExit();
29   };
32 /*array [1D]*/
33 class Hello : public CBase_Hello 
35 private:
36   CProxy_MainHello mainProxy;
37   int nElements;
38 public:
39   Hello(CProxy_MainHello mp, int nElems)
40   {
41     mainProxy = mp;
42     nElements = nElems;
43   }
45   Hello(CkMigrateMessage *m) {}
46   
47   void SayHi(int hiNo)
48   {
49     CkPrintf("Hello[%d] from element %d\n",hiNo,thisIndex);
50     if (thisIndex < nElements-1)
51       //Pass the hello on:
52       thisProxy[thisIndex+1].SayHi(hiNo+1);
53     else 
54       //We've been around once-- we're done.
55       mainProxy.done();
56   }
59 //C++ function invoked from MPI, marks the begining of Charm++
60 void HelloStart(int elems)
62   if(CkMyPe() == 0) {
63     CkPrintf("HelloStart - Starting lib by calling constructor of MainHello\n");
64     CProxy_MainHello mainhello = CProxy_MainHello::ckNew(elems, 0);
65   }
66   StartCharmScheduler();
69 #include "hello.def.h"