Bug #1081: Report an error on command-line flags that expect a wholly-missing integer...
[charm.git] / examples / charm++ / cell / hello / hello.C
blobfaecb5f7a1391ba19d093ffa2b754f358412aef0
1 #include <stdio.h>
2 #include "hello.decl.h"
4 /*readonly*/ CProxy_Main mainProxy;
5 /*readonly*/ int nElements;
8 class Main : public CBase_Main {
10   public:
11     Main(CkArgMsg* m) {
13       //Process command-line arguments
14       nElements = 5;
15       if (m->argc > 1) nElements = atoi(m->argv[1]);
16       delete m;
18       //Start the computation
19       CkPrintf("Running Hello on %d processors for %d elements\n", CkNumPes(), nElements);
20       mainProxy = thisProxy;
22       CProxy_Hello arr = CProxy_Hello::ckNew(nElements);
23       char *msg = "Hello from Main";
24       arr[0].saySomething(strlen(msg) + 1, msg, -1);
25     };
27     void done(void) {
28       CkPrintf("All done\n");
29       CkExit();
30     };
34 class Hello : public CBase_Hello {
36   // Declare the CkIndex_Hello class as a friend of this class so that the accelerated
37   //   entry methods can access the member variables of this class
38   friend class CkIndex_Hello;
40   public:
42     Hello() { }
43     Hello(CkMigrateMessage *m) {}
44     ~Hello() { }
45   
46     void saySomething_callback() {
47       if (thisIndex < nElements - 1) {
48         char msgBuf[128];
49         int msgLen = sprintf(msgBuf, "Hello from %d", thisIndex) + 1;
50         thisProxy[thisIndex+1].saySomething(msgLen, msgBuf, thisIndex);
51       } else {
52         mainProxy.done();
53       }
54     }
58 #include "hello.def.h"